diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 508f1f37..7ee4898b 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -34,22 +34,22 @@ class WarehouseProductLogic extends BaseLogic { // Db::startTrans(); // try { - $before_nums=0; - $after_nums=0; + $before_nums = 0; + $after_nums = 0; $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); - if($storege){ + if ($storege) { if ($params['financial_pm'] == 0) { - $after_nums=$storege['nums']-$params['nums']; - if($after_nums<0){ + $after_nums = $storege['nums'] - $params['nums']; + if ($after_nums < 0) { throw new BusinessException('库存不足'); } WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update(); } else { - $after_nums=$storege['nums']+$params['nums']; + $after_nums = $storege['nums'] + $params['nums']; WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update(); } - $before_nums=$storege['nums']; - }else{ + $before_nums = $storege['nums']; + } else { WarehouseProductStorege::create([ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], @@ -62,7 +62,7 @@ class WarehouseProductLogic extends BaseLogic 'store_id' => $params['store_id'] ?? 0, 'product_id' => $params['product_id'], 'financial_pm' => $params['financial_pm'], - 'batch' => $batch_count+1, + 'batch' => $batch_count + 1, 'nums' => $params['nums'], 'before_nums' => $before_nums, 'after_nums' => $after_nums, @@ -148,21 +148,15 @@ class WarehouseProductLogic extends BaseLogic if ($res) { $res->delete(); if ($res['financial_pm'] == 1) { - WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums', $res['nums'])->update(); + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update(); } elseif ($res['financial_pm'] == 0) { - $find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find(); - if ($find) { - if ($find['status'] == 1) { - $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); - if ($stock < $res['nums']) { - self::setError('商品库存不足,无法退回'); - return false; - } - StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); - } - $find->delete(); + $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); + if ($stock < $res['nums']) { + self::setError('商品库存不足,无法退回'); + return false; } - WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums', $res['nums'])->update(); + StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update(); } return true;