From f5cd98515705adf2d99e102560a2dfeeed84dc86 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 13 Aug 2024 12:01:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WarehouseProductLogic.php | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 508f1f370..7ee4898b6 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;