From c6bc0b41e80b02fa99c72c5e609283668c6cb3f0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 4 Aug 2024 17:41:24 +0800 Subject: [PATCH] feat(StoreProductController, WarehouseProductLists, StoreStorageSend): Update stock management logic, optimize inventory checking, adjust storage management methods --- .../store_product/StoreProductController.php | 13 +++++++++++++ .../warehouse_product/WarehouseProductLists.php | 6 +++++- app/queue/redis/StoreStorageSend.php | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 6ea157ae..83db7147 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -7,6 +7,7 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\store_product\StoreProductLists; use app\admin\logic\store_product\StoreProductLogic; use app\admin\validate\store_product\StoreProductValidate; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; use Webman\RedisQueue\Redis; /** @@ -102,11 +103,23 @@ class StoreProductController extends BaseAdminController $warehouse_id = $this->request->post('warehouse_id'); if (count($store_arr) == 1) { $store_id = $store_arr[0]; + foreach ($product_arr as $key => $arr) { + $nums= WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$arr['product_id'])->value('nums'); + if($nums<$arr['stock']){ + return $this->fail('商品ID'.$arr['product_id'].'库存不足'); + } + } foreach ($product_arr as $key => $arr) { Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } } else { foreach ($product_arr as $key => $arr) { + foreach ($product_arr as $key => $arr) { + $nums= WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$arr['product_id'])->value('nums'); + if($nums<$arr['stock']){ + return $this->fail('商品ID'.$arr['product_id'].'库存不足'); + } + } foreach ($store_arr as $k => $store_id) { Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 19d9a9f5..3dd0c0f8 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -8,6 +8,7 @@ use app\common\model\warehouse_product\WarehouseProduct; use app\common\lists\ListsSearchInterface; use app\common\model\auth\Admin; use app\common\model\store_product\StoreProduct; +use app\common\model\system_store\SystemStore; use app\common\model\warehouse\Warehouse; /** @@ -45,12 +46,15 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt public function lists(): array { return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price','purchase','cost', 'total_price', 'manufacture','expiration_date','status','mark','create_time']) + ->field(['id', 'admin_id','store_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price','purchase','cost', 'total_price', 'manufacture','expiration_date','status','mark','create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item){ if($item->financial_pm==0){ $item->financial_pm_name='出库'; + if($item->store_id>0){ + $item->financial_pm_name='出库=>'.SystemStore::where('id',$item->store_id)->value('name'); + } }else{ $item->financial_pm_name='入库'; } diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index 0ae7662a..cea7038a 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -174,6 +174,7 @@ class StoreStorageSend implements Consumer $data=[ 'warehouse_id'=>$warehouse_id, 'product_id' => $product_arr['id'], + 'store_id' => $store_id, 'financial_pm' => 0, 'batch' => $product_arr['batch']??1, 'nums' => $product_arr['stock'],