修改商品分类分组价格浮动比例
This commit is contained in:
parent
a63d90834e
commit
d51d56a314
@ -45,6 +45,8 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$userGroups = UserShip::field('id,title')->select()->toArray();
|
$userGroups = UserShip::field('id,title')->select()->toArray();
|
||||||
|
$userGroups[] = ['id' => 100001, 'title' => '供货价'];
|
||||||
|
$userGroups[] = ['id' => 100002, 'title' => '零售价'];
|
||||||
return StoreCategory::where($this->searchWhere)
|
return StoreCategory::where($this->searchWhere)
|
||||||
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
|
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
@ -52,8 +52,8 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
|
|||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function($item){
|
->select()->each(function($item){
|
||||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->find();
|
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->withTrashed()->find();
|
||||||
$item['unit_name']=$find['unitName']['name'];
|
$item['unit_name']=$find['unitName']['name'] ?? '';
|
||||||
$item['store_name']=$find['store_name'];
|
$item['store_name']=$find['store_name'];
|
||||||
$item['store_info']=$find['store_info'];
|
$item['store_info']=$find['store_info'];
|
||||||
$item['image']=$find['image'];
|
$item['image']=$find['image'];
|
||||||
|
@ -140,40 +140,39 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
'marques' => $params['marques'],
|
'marques' => $params['marques'],
|
||||||
'after_sales' => $params['after_sales'],
|
'after_sales' => $params['after_sales'],
|
||||||
]);
|
]);
|
||||||
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id')->find();
|
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id')->find();
|
||||||
$unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name');
|
$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();
|
self::setProductGroupPrice($params, $product);
|
||||||
$data = [];
|
// $data = [];
|
||||||
$data['bhoid'] = $offer['order_id'];
|
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||||
$data['offer_id'] = $params['id'];
|
// $data['bhoid'] = $offer['order_id'];
|
||||||
$data['product_id'] = $offer['product_id'];
|
// $data['offer_id'] = $params['id'];
|
||||||
$data['purchase_price'] = $params['purchase'];
|
// $data['product_id'] = $offer['product_id'];
|
||||||
$data['status'] = 0;
|
// $data['purchase_price'] = $params['purchase'];
|
||||||
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
|
// $data['status'] = 0;
|
||||||
self::setProductGroupPrice($params, $product, $productCatePriceRate);
|
// if ($dict_data) {
|
||||||
if ($dict_data) {
|
// foreach ($dict_data as $k => $v) {
|
||||||
foreach ($dict_data as $k => $v) {
|
// if ($v['name'] == 'purchase') {
|
||||||
if ($v['name'] == 'purchase') {
|
// $data['purchase_lv'] = $v['value'];
|
||||||
$data['purchase_lv'] = $v['value'];
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||||
$data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
// } elseif ($v['name'] == 'cost') {
|
||||||
} elseif ($v['name'] == 'cost') {
|
// $data['cost_lv'] = $v['value'];
|
||||||
$data['cost_lv'] = $v['value'];
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||||
$data['cost'] = bcadd($lv, $params['purchase'], 2);
|
// } elseif ($v['name'] == 'price') {
|
||||||
} elseif ($v['name'] == 'price') {
|
// $data['price_lv'] = $v['value'];
|
||||||
$data['price_lv'] = $v['value'];
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||||
$data['price'] = bcadd($lv, $params['purchase'], 2);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// if ($find) {
|
||||||
if ($find) {
|
// $find->save($data);
|
||||||
$find->save($data);
|
// } else {
|
||||||
} else {
|
// StoreProductPrice::create($data);
|
||||||
StoreProductPrice::create($data);
|
// }
|
||||||
}
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
$offer['store_name']=$product['store_name'];
|
$offer['store_name']=$product['store_name'];
|
||||||
$offer['unit_name']=$unit_name;
|
$offer['unit_name']=$unit_name;
|
||||||
@ -306,16 +305,50 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
return PurchaseProductOffer::destroy($params['id']);
|
return PurchaseProductOffer::destroy($params['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setProductGroupPrice($params, $product, $productCatePriceRate)
|
public static function setProductGroupPrice($params, $product)
|
||||||
{
|
{
|
||||||
|
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
|
||||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
||||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||||
$insertData = [];
|
$priceConfig = [];
|
||||||
|
$data = [
|
||||||
|
'bhoid' => $params['bhoid'],
|
||||||
|
'offer_id' => $params['id'],
|
||||||
|
'product_id' => $product['id'],
|
||||||
|
'purchase_price' => $params['purchase'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time(),
|
||||||
|
'status' => 0,
|
||||||
|
];
|
||||||
foreach ($productCatePriceRate as $k => $v) {
|
foreach ($productCatePriceRate as $k => $v) {
|
||||||
|
if ($v['id'] == 4) {
|
||||||
|
$data['cost_lv'] = bcdiv($v['rate'], 100, 2);
|
||||||
|
$data['cost'] = bcmul($params['purchase'], bcadd($data['cost_lv'], 1, 2), 2);
|
||||||
|
continue;
|
||||||
|
} elseif ($v['id'] == 100001) {
|
||||||
|
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
|
||||||
|
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
|
||||||
|
continue;
|
||||||
|
} elseif ($v['id'] == 100002) {
|
||||||
|
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
|
||||||
|
$data['price'] = bcmul($params['purchase'], bcadd($data['price_lv'], 1, 2), 1);
|
||||||
|
if ($product['two_cate_id'] == 15268) {
|
||||||
|
$lastNum = substr($data['price'], -1);
|
||||||
|
if ($lastNum <= 2) {
|
||||||
|
$data['price'] = floor($data['price']);
|
||||||
|
} elseif ($lastNum < 5) {
|
||||||
|
$data['price'] = bcadd(floor($data['price']), 0.5, 1);
|
||||||
|
} else {
|
||||||
|
$data['price'] = bcadd(floor($data['price']), 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$baseRate = 100 + $v['rate'];
|
$baseRate = 100 + $v['rate'];
|
||||||
$item = [
|
$item = [
|
||||||
'product_id' => $product['id'],
|
'product_id' => $product['id'],
|
||||||
'group_id' => $v['id'],
|
'group_id' => $v['id'],
|
||||||
|
'group_name' => $v['title'],
|
||||||
'price' => bcmul($params['purchase'], $baseRate / 100, 2),
|
'price' => bcmul($params['purchase'], $baseRate / 100, 2),
|
||||||
'price_type' => 3,
|
'price_type' => 3,
|
||||||
'base_rate' => $baseRate,
|
'base_rate' => $baseRate,
|
||||||
@ -325,8 +358,14 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
$item['price'] = bcmul($params['purchase'], $item['base_rate'] / 100, 2);
|
$item['price'] = bcmul($params['purchase'], $item['base_rate'] / 100, 2);
|
||||||
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
|
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
|
||||||
}
|
}
|
||||||
$insertData[] = $item;
|
$priceConfig[] = $item;
|
||||||
|
}
|
||||||
|
$data['price_config'] = $priceConfig;
|
||||||
|
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||||
|
if ($find) {
|
||||||
|
$find->save($data);
|
||||||
|
} else {
|
||||||
|
StoreProductPrice::create($data);
|
||||||
}
|
}
|
||||||
(new StoreProductGroupPrice())->saveAll($insertData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,7 @@ class StoreProductPrice extends BaseModel
|
|||||||
protected $name = 'store_product_price';
|
protected $name = 'store_product_price';
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
protected $json = ['price_config'];
|
||||||
|
protected $jsonAssoc = true;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user