添加商品分类分组价格浮动比例

This commit is contained in:
DESKTOP-GMUNQ1B\Administrator 2024-12-16 16:32:04 +08:00
parent 0ebe7712fd
commit 65229c142d
4 changed files with 50 additions and 4 deletions

View File

@ -6,6 +6,7 @@ namespace app\admin\lists\store_category;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\store_category\StoreCategory;
use app\common\lists\ListsSearchInterface;
use app\common\model\user_ship\UserShip;
/**
@ -43,11 +44,24 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
*/
public function lists(): array
{
$userGroups = UserShip::field('id,title')->select()->toArray();
return StoreCategory::where($this->searchWhere)
->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
->select()->each(function ($item) use ($userGroups) {
if (empty($item['price_rate'])) {
$item['price_rate'] = $userGroups;
} else {
$priceRate = reset_index($item['price_rate'], 'id');
foreach ($userGroups as $userGroup) {
if (!isset($priceRate[$userGroup['id']])) {
$userGroup['rate'] = 0;
$priceRate[] = $userGroup;
}
}
$item['price_rate'] = array_values($priceRate);
}
$item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类
return $item->toArray();
})

View File

@ -10,7 +10,9 @@ use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\delivery_service\DeliveryService;
use app\common\model\dict\DictData;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_price\StoreProductPrice;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User;
@ -139,7 +141,7 @@ class PurchaseProductOfferLogic extends BaseLogic
'after_sales' => $params['after_sales'],
]);
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('store_name,top_cate_id')->find();
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id')->find();
$unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name');
$dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
$data = [];
@ -148,6 +150,8 @@ class PurchaseProductOfferLogic extends BaseLogic
$data['product_id'] = $offer['product_id'];
$data['purchase_price'] = $params['purchase'];
$data['status'] = 0;
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
self::setProductGroupPrice($params, $product, $productCatePriceRate);
if ($dict_data) {
foreach ($dict_data as $k => $v) {
if ($v['name'] == 'purchase') {
@ -301,4 +305,28 @@ class PurchaseProductOfferLogic extends BaseLogic
{
return PurchaseProductOffer::destroy($params['id']);
}
public static function setProductGroupPrice($params, $product, $productCatePriceRate)
{
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
$insertData = [];
foreach ($productCatePriceRate as $k => $v) {
$baseRate = 100 + $v['rate'];
$item = [
'product_id' => $product['id'],
'group_id' => $v['id'],
'price' => bcmul($params['purchase'], $baseRate / 100, 2),
'price_type' => 3,
'base_rate' => $baseRate,
];
if (isset($storeProductGroupPrice[$v['id']])) {
$item['base_rate'] = $storeProductGroupPrice[$v['id']]['base_rate'];
$item['price'] = bcmul($params['purchase'], $item['base_rate'] / 100, 2);
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
}
$insertData[] = $item;
}
(new StoreProductGroupPrice())->saveAll($insertData);
}
}

View File

@ -62,7 +62,8 @@ class StoreCategoryLogic extends BaseLogic
'name' => $params['name'],
'data' => $params['data'],
'pic' => $params['pic'],
'sort' => $params['sort']
'sort' => $params['sort'],
'price_rate' => $params['price_rate']
]);
Db::commit();

View File

@ -18,5 +18,8 @@ class StoreCategory extends BaseModel
protected $name = 'store_category';
protected $deleteTime = 'delete_time';
protected $json = ['price_rate'];
protected $jsonAssoc = true;
}