feat: 修改仓库逻辑以优化库存计算

This commit is contained in:
mkm 2024-09-01 17:29:58 +08:00
parent 9758171b39
commit 97c4cf60d5

View File

@ -248,7 +248,6 @@ class WarehouseLogic extends BaseLogic
$price=0; $price=0;
} }
WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]); WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]);
} }
$arr2=StoreBranchProduct::where('stock','>',0)->select(); $arr2=StoreBranchProduct::where('stock','>',0)->select();
@ -260,7 +259,7 @@ class WarehouseLogic extends BaseLogic
} }
StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]); StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]);
} }
$arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->select(); $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->group('product_id')->select();
foreach ($arr3 as $k=>$v){ foreach ($arr3 as $k=>$v){
StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]);
} }