From 297864ea9e81dd80f6dfee5d1721f0afccc9335d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 9 Aug 2024 15:11:32 +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=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=A3=80=E6=9F=A5=E4=B8=8E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_product/StoreProductController.php | 16 +++++++++--- .../SystemStoreStorageController.php | 26 ++++++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 507a8b360..332171527 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -99,17 +99,25 @@ class StoreProductController extends BaseAdminController { $product_arr = $this->request->post('product_arr'); $store_arr = $this->request->post('store_arr'); - $stock_type = $this->request->post('stock_type',1); + $stock_type = $this->request->post('stock_type', 1); $warehouse_id = $this->request->post('warehouse_id'); - if (count($store_arr) == 1) { + $count=count($store_arr); + foreach ($product_arr as $key => $arr) { + $stock=bcmul($arr['stock'],$count); + $nums=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$arr['id'])->value('nums'); + if($nums<$stock){ + return $this->fail('商品库存不足'); + } + } + if ($count == 1) { $store_id = $store_arr[0]; 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]); + 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 ($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]); + 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/controller/system_store_storage/SystemStoreStorageController.php b/app/admin/controller/system_store_storage/SystemStoreStorageController.php index fe21f824f..d04d37848 100644 --- a/app/admin/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/admin/controller/system_store_storage/SystemStoreStorageController.php @@ -7,7 +7,8 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\system_store_storage\SystemStoreStorageLists; use app\admin\logic\system_store_storage\SystemStoreStorageLogic; use app\admin\validate\system_store_storage\SystemStoreStorageValidate; - +use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\system_store_storage\SystemStoreStorage; /** * 门店入库记录控制器 @@ -55,13 +56,24 @@ class SystemStoreStorageController extends BaseAdminController */ public function edit() { - $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); - $params['admin_id']=$this->adminId; - $result = SystemStoreStorageLogic::edit($params); - if (true === $result) { - return $this->success('编辑成功', [], 1, 1); + // $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); + // $params['admin_id']=$this->adminId; + // $result = SystemStoreStorageLogic::edit($params); + // if (true === $result) { + // return $this->success('编辑成功', [], 1, 1); + // } + // return $this->fail(SystemStoreStorageLogic::getError()); + $id = $this->request->post('id',0); + if($id==0){ + return $this->fail('参数错误'); } - return $this->fail(SystemStoreStorageLogic::getError()); + $res=SystemStoreStorage::where(['id' => $id])->update(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]); + if($res){ + $find=SystemStoreStorage::where(['id' => $id])->find(); + StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); + return $this->success('操作成功',[]); + } + return $this->fail('操作失败'); }