fix(warehouse): 修复仓库产品数量增减操作的精度问题

- 在增减产品数量时使用 bcadd 和 bcsub 函数,确保精度正确
- 修改了 decProductIncStorege 和 incProductDecStorege 方法的实现
- 添加了异常捕获时的调试信息
This commit is contained in:
mkm 2025-01-06 15:13:19 +08:00
parent a93207ff4c
commit 33eff351fc

View File

@ -242,6 +242,7 @@ class WarehouseProductLogic extends BaseLogic
return $res; return $res;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());
} }
} }
@ -356,21 +357,25 @@ class WarehouseProductLogic extends BaseLogic
private static function decProductIncStorege($res,$nums,$admin_id=0) private static function decProductIncStorege($res,$nums,$admin_id=0)
{ {
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id'])->inc('nums',$nums)->update(); ->where('product_id', $res['product_id'])->find();
$res1->nums = bcadd($res1->nums,$nums,2);
$res1->save();
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, 1, Request()->url(),$admin_id); SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, 1, Request()->url(),$admin_id);
$res->dec('nums',$nums)->update(); WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcsub($res['nums'],$nums,2)]);
SqlChannelLog('WarehouseProduct', $res['id'], $res['nums'], -1, Request()->url(),$admin_id); SqlChannelLog('WarehouseProduct', $res['id'], $nums, -1, Request()->url(),$admin_id);
} }
//增加 //增加
private static function incProductDecStorege($res, $nums,$admin_id=0) private static function incProductDecStorege($res, $nums,$admin_id=0)
{ {
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id'])->dec('nums',$nums)->update(); ->where('product_id', $res['product_id'])->find();
$res1->nums = bcsub($res1->nums,$nums,2);
$res1->save();
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, -1, Request()->url(),$admin_id); SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, -1, Request()->url(),$admin_id);
$res->inc('nums',$nums)->update(); WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcadd($res['nums'],$nums,2)]);
SqlChannelLog('WarehouseProduct', $res['id'], $res['nums'], 1, Request()->url(),$admin_id); SqlChannelLog('WarehouseProduct', $res['id'], $nums, 1, Request()->url(),$admin_id);
} }
} }