优化仓库商品逻辑,支持商品未存在时的处理
- 当仓库商品不存在时,自动创建商品库存记录,而不是抛出异常 - 新增商品库存时,'nums'字段设置为负数,以表示缺货数量 - 保留了仓库ID和产品ID的关联,便于后续处理
This commit is contained in:
parent
d5a9066616
commit
6afd0be1c8
@ -130,7 +130,13 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$total_price = bcmul($after_nums, $params['purchase'], 2);
|
||||
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);
|
||||
} else {
|
||||
throw new BusinessException('仓库商品不存在' . '|' . $params['product_id']);
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => -$params['nums'],
|
||||
'total_price' => 0
|
||||
];
|
||||
$storege = WarehouseProductStorege::create($data);
|
||||
}
|
||||
} else {
|
||||
$storege['nums'] = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user