fix(admin): 优化库存更新逻辑

- 修改 StoreBranchProduct 库存更新方式,先更新 stock 属性再保存
- 这种方式可以减少数据库查询次数,提高性能
This commit is contained in:
mkm 2025-01-08 15:13:02 +08:00
parent 8e07237489
commit 0ca77643f1

View File

@ -69,7 +69,8 @@ class SystemStoreStorageLogic extends BaseLogic
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
if($branch_product){
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
$branch_product->stock=$branch_product['stock']+$find['nums'];
$branch_product->save();
SqlChannelLog('StoreBranchProduct', $branch_product['id'], $find['nums'], 1,Request()->url(),$admin_id);
}else{
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();