From 75a233833791a1ed1dc7908e47606b528131ea00 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 1 Aug 2024 13:59:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E4=BA=A7=E5=93=81=E7=A1=AE=E8=AE=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_product/StoreProductController.php | 5 +- .../WarehouseProductController.php | 17 ++- .../WarehouseProductStoregeController.php | 95 ++++++++++++++++ .../WarehouseProductLists.php | 30 ++++- .../WarehouseProductStoregeLists.php | 85 ++++++++++++++ .../WarehouseProductLogic.php | 64 +++++++++-- .../WarehouseProductStoregeLogic.php | 104 ++++++++++++++++++ .../WarehouseProductValidate.php | 4 +- .../WarehouseProductStoregeValidate.php | 94 ++++++++++++++++ .../WarehouseProductStorege.php | 22 ++++ app/queue/redis/StoreStorageSend.php | 34 ++++-- 11 files changed, 530 insertions(+), 24 deletions(-) create mode 100644 app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php create mode 100644 app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php create mode 100644 app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php create mode 100644 app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php create mode 100644 app/common/model/warehouse_product_storege/WarehouseProductStorege.php diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 4e9046b0..6ea157ae 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -99,15 +99,16 @@ 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); + $warehouse_id = $this->request->post('warehouse_id'); if (count($store_arr) == 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]); + 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]); + 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/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index e1bac316..6f5817b3 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -7,7 +7,7 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\warehouse_product\WarehouseProductLists; use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\validate\warehouse_product\WarehouseProductValidate; - +use app\common\model\warehouse_product\WarehouseProduct; /** * 商品仓储信息控制器 @@ -39,6 +39,7 @@ class WarehouseProductController extends BaseAdminController public function add() { $params = (new WarehouseProductValidate())->post()->goCheck('add'); + $params['admin_id']=$this->adminId; $result = WarehouseProductLogic::add($params); if (true === $result) { return $this->success('添加成功', [], 1, 1); @@ -56,6 +57,7 @@ class WarehouseProductController extends BaseAdminController public function edit() { $params = (new WarehouseProductValidate())->post()->goCheck('edit'); + $params['admin_id']=$this->adminId; $result = WarehouseProductLogic::edit($params); if (true === $result) { return $this->success('编辑成功', [], 1, 1); @@ -91,5 +93,16 @@ class WarehouseProductController extends BaseAdminController return $this->data($result); } - + /** + * 确认操作 + */ + public function enter(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::enter($id); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + return $this->success($result); + } } \ No newline at end of file diff --git a/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php new file mode 100644 index 00000000..cfa6f487 --- /dev/null +++ b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseProductStoregeLists()); + } + + + // /** + // * @notes 添加仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function add() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('add'); + // $result = WarehouseProductStoregeLogic::add($params); + // if (true === $result) { + // return $this->success('添加成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 编辑仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function edit() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('edit'); + // $result = WarehouseProductStoregeLogic::edit($params); + // if (true === $result) { + // return $this->success('编辑成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 删除仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function delete() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('delete'); + // WarehouseProductStoregeLogic::delete($params); + // return $this->success('删除成功', [], 1, 1); + // } + + + // /** + // * @notes 获取仓库商品存储详情 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function detail() + // { + // $params = (new WarehouseProductStoregeValidate())->goCheck('detail'); + // $result = WarehouseProductStoregeLogic::detail($params); + // return $this->data($result); + // } + + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index c33e58cd..dbefbe64 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -6,7 +6,8 @@ namespace app\admin\lists\warehouse_product; use app\admin\lists\BaseAdminDataLists; 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; /** * 商品仓储信息列表 @@ -43,10 +44,33 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt public function lists(): array { return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'status']) + ->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'manufacture','expiration_date','status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item){ + if($item->financial_pm==0){ + $item->financial_pm_name='出库'; + }else{ + $item->financial_pm_name='入库'; + } + if($item->status==0){ + $item->status_name='未确认'; + }else{ + $item->status_name='已确认'; + } + if($item->admin_id){ + $item->admin_name=Admin::where('id',$item->admin_id)->value('name'); + }else{ + $item->admin_name=''; + } + if($item->product_id){ + $item->store_name=StoreProduct::where('id',$item->product_id)->value('store_name'); + }else{ + $item->store_name=''; + } + $item->expiration_date=$item->expiration_date?date('Y-m-d',$item->expiration_date):''; + $item->manufacture=$item->manufacture?date('Y-m-d',$item->manufacture):''; + }) ->toArray(); } diff --git a/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php new file mode 100644 index 00000000..6bd72ec0 --- /dev/null +++ b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php @@ -0,0 +1,85 @@ + ['warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'], + ]; + } + + + /** + * @notes 获取仓库商品存储列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/01 10:22 + */ + public function lists(): array + { + return WarehouseProductStorege::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item->warehouse_id)->value('name'); + $find= StoreProduct::where('id',$item->product_id)->find(); + if($find){ + $item->store_name = $find->store_name; + $item->image = $find->image; + $item->bar_code = $find->bar_code; + $item->price = $find->price; + $item->cost = $find->cost; + $item->purchase = $find->purchase; + $item->store_info = $find->store_info; + $item->rose = $find->rose; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name'); + } + $item['stock']=$item['nums']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取仓库商品存储数量 + * @return int + * @author admin + * @date 2024/08/01 10:22 + */ + public function count(): int + { + return WarehouseProductStorege::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index b829fc58..0511360d 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -5,6 +5,8 @@ namespace app\admin\logic\warehouse_product; use app\common\model\warehouse_product\WarehouseProduct; use app\common\logic\BaseLogic; +use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; use think\facade\Db; @@ -28,17 +30,22 @@ class WarehouseProductLogic extends BaseLogic { Db::startTrans(); try { - WarehouseProduct::create([ + $res=WarehouseProduct::create([ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], 'financial_pm' => $params['financial_pm'], 'batch' => $params['batch'], 'nums' => $params['nums'], - 'price' => $params['price'], - 'total_price' => $params['total_price'], - 'status' => $params['status'] + 'price' => $params['price']??'', + 'total_price' => $params['total_price']??'', + 'admin_id' => $params['admin_id'], + 'code' => $params['code']??'', + 'manufacture' => $params['manufacture']?strtotime($params['manufacture']):'', + 'expiration_date' =>$params['expiration_date']?strtotime($params['expiration_date']):'', + 'status' => $params['status']??0, + 'mark' => $params['mark']??'', ]); - + self::enter($res['id']); Db::commit(); return true; } catch (\Exception $e) { @@ -67,8 +74,11 @@ class WarehouseProductLogic extends BaseLogic 'batch' => $params['batch'], 'nums' => $params['nums'], 'price' => $params['price'], + 'admin_id' => $params['admin_id'], 'total_price' => $params['total_price'], - 'status' => $params['status'] + 'code' => $params['code'], + 'manufacture' => strtotime($params['manufacture']), + 'expiration_date' => strtotime($params['expiration_date']), ]); Db::commit(); @@ -79,6 +89,40 @@ class WarehouseProductLogic extends BaseLogic return false; } } + + /** + * @notes 确认商品仓储信息 + * @param array $params + * @author admin + * @date 2024/07/31 16:55 + */ + public static function enter($id) + { + Db::startTrans(); + try { + $find=WarehouseProduct::where('id',$id)->find(); + $find->status=1; + $find->save(); + StoreProduct::where('id',$find['product_id'])->inc('stock',$find['nums'])->update(); + $storege=WarehouseProductStorege::where('warehouse_id',$find['warehouse_id'])->where('product_id',$find['product_id'])->find(); + if($storege){ + $storege->nums=$storege->nums+$find['nums']; + $storege->save(); + }else{ + WarehouseProductStorege::create([ + 'warehouse_id' => $find['warehouse_id'], + 'product_id' => $find['product_id'], + 'nums' => $find['nums'], + ]); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** @@ -103,6 +147,12 @@ class WarehouseProductLogic extends BaseLogic */ public static function detail($params): array { - return WarehouseProduct::findOrEmpty($params['id'])->toArray(); + $data= WarehouseProduct::findOrEmpty($params['id'])->toArray(); + if($data){ + $data['manufacture']=date('Y-m-d',$data['manufacture']); + $data['expiration_date']=date('Y-m-d',$data['expiration_date']); + + } + return $data; } } \ No newline at end of file diff --git a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php new file mode 100644 index 00000000..eac41ece --- /dev/null +++ b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php @@ -0,0 +1,104 @@ + $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑仓库商品存储 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/01 10:22 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + WarehouseProductStorege::where('id', $params['id'])->update([ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除仓库商品存储 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/01 10:22 + */ + public static function delete(array $params): bool + { + return WarehouseProductStorege::destroy($params['id']); + } + + + /** + * @notes 获取仓库商品存储详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/01 10:22 + */ + public static function detail($params): array + { + return WarehouseProductStorege::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/warehouse_product/WarehouseProductValidate.php b/app/admin/validate/warehouse_product/WarehouseProductValidate.php index afbe4862..a3a7cb79 100644 --- a/app/admin/validate/warehouse_product/WarehouseProductValidate.php +++ b/app/admin/validate/warehouse_product/WarehouseProductValidate.php @@ -56,7 +56,7 @@ class WarehouseProductValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price']); } @@ -68,7 +68,7 @@ class WarehouseProductValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price']); } diff --git a/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php new file mode 100644 index 00000000..45905ac9 --- /dev/null +++ b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php @@ -0,0 +1,94 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '价格', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php new file mode 100644 index 00000000..074aa2d0 --- /dev/null +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -0,0 +1,22 @@ +findOrEmpty()->toArray(); if($stock_type == 1){ $this->ordinary($product_arr,$store_id,$admin_id,$find); @@ -40,7 +43,7 @@ class StoreStorageSend implements Consumer } /**普通 */ - public function ordinary($product_arr,$store_id,$admin_id,$find){ + public function ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id){ $store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { $attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty(); @@ -82,7 +85,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductAttrValue::create($arr); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -109,7 +112,7 @@ class StoreStorageSend implements Consumer } /**兑换 */ - public function exchange($product_arr,$store_id,$admin_id,$find){ + public function exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id){ $store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { Db::startTrans(); @@ -133,7 +136,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductExchange::create($product); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } // StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -158,7 +161,7 @@ class StoreStorageSend implements Consumer } } } - public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1) + public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0) { $storage = [ 'product_id' => $product_arr['id'], @@ -167,12 +170,27 @@ class StoreStorageSend implements Consumer 'admin_id' => $admin_id, 'type' => $stock_type, ]; - if ($find['stock'] < $product_arr['stock']) { - $storage['status'] = -1; - $storage['mark'] = '库存不足,主库存为:' . $find['stock']; + $data=[ + 'warehouse_id'=>$warehouse_id, + 'product_id' => $product_arr['id'], + 'financial_pm' => 0, + 'batch' => $product_arr['batch']??1, + 'nums' => $product_arr['stock'], + 'status' =>1, + 'admin_id' =>$admin_id, + ]; + $warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find(); + if ($warehouse) { + if($warehouse['nums']< $product_arr['stock']){ + $storage['status'] = -1; + $storage['mark'] = '库存不足,分库存为:' .$warehouse['nums']; + $data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock']; + } SystemStoreStorage::create($storage); + WarehouseProductLogic::add($data); } else { SystemStoreStorage::create($storage); + WarehouseProductLogic::add($data); StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update(); } }