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