修复了库存管理逻辑中的错误,优化了库存不足时的异常处理。

This commit is contained in:
mkm 2024-08-13 19:56:27 +08:00
parent 6e17d78d52
commit 7eaf64af41

View File

@ -28,22 +28,22 @@ class InventoryTransferLogic extends BaseLogic
*/
public static function add(array $params): bool
{
$one_before_nums=0;
$one_after_nums=0;
$two_before_nums=0;
$two_after_nums=0;
$one_before_nums = 0;
$one_after_nums = 0;
$two_before_nums = 0;
$two_after_nums = 0;
if ($params['type'] == 1) {
$stock = StoreBranchProduct::where('product_id', $params['one_id'])->value('stock');
$stock_two = StoreBranchProduct::where('product_id', $params['two_id'])->value('stock');
if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前库存');
return false;
}else{
$one_before_nums=$stock;
$one_after_nums=bcsub($stock,$params['nums']);
} else {
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums=$stock_two;
$two_after_nums=bcadd($stock_two,$params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}
} elseif ($params['type'] == 2) {
$stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums');
@ -51,39 +51,37 @@ class InventoryTransferLogic extends BaseLogic
if ($stock < $params['nums']) {
self::setError('调拨数量不能大于当前库存');
return false;
}else{
$one_before_nums=$stock;
$one_after_nums=bcsub($stock,$params['nums']);
} else {
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums=$stock_two;
$two_after_nums=bcadd($stock_two,$params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}
}
Db::startTrans();
try {
InventoryTransfer::create([
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'one_before_nums' => $one_before_nums,
'one_after_nums' => $one_after_nums,
'two_before_nums' => $two_before_nums,
'two_after_nums' => $two_after_nums,
'type' => $params['type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id']
]);
Db::startTrans();
try {
InventoryTransfer::create([
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'one_before_nums' => $one_before_nums,
'one_after_nums' => $one_after_nums,
'two_before_nums' => $two_before_nums,
'two_after_nums' => $two_after_nums,
'type' => $params['type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑商品调拨
* @param array $params