fix(warehouse): 修复仓库调拨库存数量错误问题
- 修改 decStock 和 incStock 方法,使用 bcsub 和 bcadd 函数进行精确计算 - 从数据库中获取对象后再更新,以确保操作的原子性和准确性 - 优化 SqlChannelLog 调用,使用正确的参数记录日志
This commit is contained in:
parent
24cd3ef828
commit
cbbd75cf60
@ -346,31 +346,28 @@ class WarehouseProductLogic extends BaseLogic
|
||||
//减少
|
||||
private static function decStock($res)
|
||||
{
|
||||
$res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
->where('product_id', $res['product_id'])
|
||||
->dec('nums', $res['nums'])
|
||||
->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], -1, Request()->url());
|
||||
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
->where('product_id', $res['product_id'])->find();
|
||||
$res1->save(['nums'=>bcsub($res1['nums'], $res['nums'],2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], -1, Request()->url());
|
||||
|
||||
$res2 = StoreBranchProduct::where('id', $res['id'])
|
||||
->dec('stock', $res['nums'])
|
||||
->update();
|
||||
$res2 = StoreBranchProduct::where('id', $res['id'])->find();
|
||||
$res2->save(['stock'=>bcsub($res2['stock'], $res['nums'],2)]);
|
||||
SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], -1, Request()->url());
|
||||
}
|
||||
|
||||
//增加
|
||||
private static function incStock($res, $params)
|
||||
{
|
||||
$res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
->where('product_id', $res['product_id'])
|
||||
->inc('nums', $params['nums'])
|
||||
->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], 1, Request()->url());
|
||||
->find();
|
||||
$res1->save(['nums'=>bcadd($res1['nums'], $params['nums'],2)]);
|
||||
|
||||
SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], 1, Request()->url());
|
||||
|
||||
|
||||
$res2 = StoreBranchProduct::where('id', $res['id'])
|
||||
->inc('stock', $params['nums'])
|
||||
->save();
|
||||
$res2 = StoreBranchProduct::where('id', $res['id'])->find();
|
||||
$res2->save(['stock'=>bcadd($res2['stock'], $params['nums'],2)]);
|
||||
SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], 1, Request()->url());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user