feat: 修改库存计算方式以优化商品销售更新逻辑

This commit is contained in:
mkm 2024-08-24 10:39:57 +08:00
parent 2e37a6ac46
commit 694c83379a

View File

@ -578,13 +578,13 @@ class PayNotifyLogic extends BaseLogic
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find();
if($branchProduct){
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2);
$branchProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]);
}
$storeProduct=StoreProduct::where('id', $v['product_id'])->find();
if($storeProduct){
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2);
$storeProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2),
StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2),
'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]);
}
}