修改商品改价
This commit is contained in:
parent
5641eaecab
commit
eb9de07654
@ -57,15 +57,9 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
try {
|
||||
$find = StoreProductPrice::where('id', $params['id'])->find();
|
||||
if ($find) {
|
||||
$updateData = [];
|
||||
$changePurchase = false;
|
||||
if ($find['purchase_lv'] != $params['purchase_lv']) {
|
||||
$updateData[] = [
|
||||
'product_id' => $find['product_id'],
|
||||
'price_type' => StoreProductPriceList::PriceTypeSupply,
|
||||
'rate' => $params['purchase_lv'] * 100,
|
||||
];
|
||||
$params['purchase'] = bcmul($find['purchase_price'], $params['purchase_lv'], 2);
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeSupply, $params['purchase_lv'], $params, 'purchase', $find['purchase_price']);
|
||||
$changePurchase = true;
|
||||
}
|
||||
if ($changePurchase) {
|
||||
@ -74,31 +68,13 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
$params['price'] = bcmul($params['purchase'], $params['price_lv'], 2);
|
||||
}
|
||||
if ($find['cost_lv'] != $params['cost_lv']) {
|
||||
$updateData[] = [
|
||||
'product_id' => $find['product_id'],
|
||||
'price_type' => StoreProductPriceList::PriceTypeBusiness,
|
||||
'rate' => $params['cost_lv'] * 100,
|
||||
];
|
||||
$params['cost'] = bcmul($params['purchase'], $params['cost_lv'], 2);
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeBusiness, $params['cost_lv'], $params, 'cost', $params['purchase']);
|
||||
}
|
||||
if ($find['vip_lv'] != $params['vip_lv']) {
|
||||
$updateData[] = [
|
||||
'product_id' => $find['product_id'],
|
||||
'price_type' => StoreProductPriceList::PriceTypeVip,
|
||||
'rate' => $params['vip_lv'] * 100,
|
||||
];
|
||||
$params['vip_price'] = bcmul($params['purchase'], $params['vip_lv'], 2);
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeVip, $params['vip_lv'], $params, 'vip_price', $params['purchase']);
|
||||
}
|
||||
if ($find['price_lv'] != $params['price_lv']) {
|
||||
$updateData[] = [
|
||||
'product_id' => $find['product_id'],
|
||||
'price_type' => StoreProductPriceList::PriceTypeRetail,
|
||||
'rate' => $params['price_lv'] * 100,
|
||||
];
|
||||
$params['price'] = bcmul($params['purchase'], $params['price_lv'], 2);
|
||||
}
|
||||
if (count($updateData) > 0) {
|
||||
(new StoreProductPriceList())->saveAll($updateData);
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeRetail, $params['price_lv'], $params, 'price', $params['purchase']);
|
||||
}
|
||||
$find->save([
|
||||
'status' => 1,
|
||||
@ -133,6 +109,23 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateProductPriceList($productId, $priceType, $rate, $params, $field, $basePrice)
|
||||
{
|
||||
$id = StoreProductPriceList::where('product_id', $productId)->where('price_type', $priceType)->value('id');
|
||||
if (empty($id)) {
|
||||
StoreProductPriceList::create([
|
||||
'product_id' => $productId,
|
||||
'price_type' => $priceType,
|
||||
'rate' => $rate * 100,
|
||||
]);
|
||||
} else {
|
||||
StoreProductPriceList::where('id', $id)->update(['rate' => $rate * 100]);
|
||||
}
|
||||
$params[$field] = bcmul($basePrice, $rate, 2);
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认改价
|
||||
* @param array $params
|
||||
|
Loading…
x
Reference in New Issue
Block a user