From 19b9c98582d9a710cb89b1a889ad1b85d65f56cf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 7 Jan 2025 16:56:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=BC=BA=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增商品缺库存控制器、列表、逻辑和验证器 --- .../StoreProductLowStockController.php | 95 ++++++++++++++++++ .../StoreProductLowStockLists.php | 72 ++++++++++++++ .../StoreProductLowStockLogic.php | 97 +++++++++++++++++++ .../StoreProductLowStockValidate.php | 82 ++++++++++++++++ .../StoreProductLowStock.php | 22 +++++ 5 files changed, 368 insertions(+) create mode 100644 app/admin/controller/store_product_low_stock/StoreProductLowStockController.php create mode 100644 app/admin/lists/store_product_low_stock/StoreProductLowStockLists.php create mode 100644 app/admin/logic/store_product_low_stock/StoreProductLowStockLogic.php create mode 100644 app/admin/validate/store_product_low_stock/StoreProductLowStockValidate.php create mode 100644 app/common/model/store_product_low_stock/StoreProductLowStock.php diff --git a/app/admin/controller/store_product_low_stock/StoreProductLowStockController.php b/app/admin/controller/store_product_low_stock/StoreProductLowStockController.php new file mode 100644 index 00000000..e08d691f --- /dev/null +++ b/app/admin/controller/store_product_low_stock/StoreProductLowStockController.php @@ -0,0 +1,95 @@ +dataLists(new StoreProductLowStockLists()); + } + + + /** + * @notes 添加商品缺库存 + * @return \think\response\Json + * @author admin + * @date 2025/01/07 16:39 + */ + public function add() + { + $params = (new StoreProductLowStockValidate())->post()->goCheck('add'); + $result = StoreProductLowStockLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductLowStockLogic::getError()); + } + + + /** + * @notes 编辑商品缺库存 + * @return \think\response\Json + * @author admin + * @date 2025/01/07 16:39 + */ + public function edit() + { + $params = (new StoreProductLowStockValidate())->post()->goCheck('edit'); + $result = StoreProductLowStockLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreProductLowStockLogic::getError()); + } + + + /** + * @notes 删除商品缺库存 + * @return \think\response\Json + * @author admin + * @date 2025/01/07 16:39 + */ + public function delete() + { + $params = (new StoreProductLowStockValidate())->post()->goCheck('delete'); + StoreProductLowStockLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品缺库存详情 + * @return \think\response\Json + * @author admin + * @date 2025/01/07 16:39 + */ + public function detail() + { + $params = (new StoreProductLowStockValidate())->goCheck('detail'); + $result = StoreProductLowStockLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/store_product_low_stock/StoreProductLowStockLists.php b/app/admin/lists/store_product_low_stock/StoreProductLowStockLists.php new file mode 100644 index 00000000..e99447ed --- /dev/null +++ b/app/admin/lists/store_product_low_stock/StoreProductLowStockLists.php @@ -0,0 +1,72 @@ + ['product_id', 'store_id', 'status'], + ]; + } + + + /** + * @notes 获取商品缺库存列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/01/07 16:39 + */ + public function lists(): array + { + return StoreProductLowStock::where($this->searchWhere) + ->field(['id', 'product_id', 'store_id', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $find = StoreBranchProduct::where('product_id', $item->product_id)->where('store_id', $item->store_id)->withTrashed()->find(); + $item->product_name = $find->store_name.'|'.$item->product_id; + $item->system_store_name = SystemStore::where('id', $item->store_id)->value('name').'|'.$item->store_id; + $item->image = $find->image; + $item->stock = $find->stock; + }) + ->toArray(); + } + + + /** + * @notes 获取商品缺库存数量 + * @return int + * @author admin + * @date 2025/01/07 16:39 + */ + public function count(): int + { + return StoreProductLowStock::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/logic/store_product_low_stock/StoreProductLowStockLogic.php b/app/admin/logic/store_product_low_stock/StoreProductLowStockLogic.php new file mode 100644 index 00000000..ac807152 --- /dev/null +++ b/app/admin/logic/store_product_low_stock/StoreProductLowStockLogic.php @@ -0,0 +1,97 @@ + $params['product_id'], + 'store_id' => $params['store_id'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑商品缺库存 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/07 16:39 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreProductLowStock::where('id', $params['id'])->update([ + 'product_id' => $params['product_id'], + 'store_id' => $params['store_id'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除商品缺库存 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/07 16:39 + */ + public static function delete(array $params): bool + { + return StoreProductLowStock::destroy($params['id']); + } + + + /** + * @notes 获取商品缺库存详情 + * @param $params + * @return array + * @author admin + * @date 2025/01/07 16:39 + */ + public static function detail($params): array + { + return StoreProductLowStock::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/store_product_low_stock/StoreProductLowStockValidate.php b/app/admin/validate/store_product_low_stock/StoreProductLowStockValidate.php new file mode 100644 index 00000000..b78f1197 --- /dev/null +++ b/app/admin/validate/store_product_low_stock/StoreProductLowStockValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductLowStockValidate + * @author admin + * @date 2025/01/07 16:39 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreProductLowStockValidate + * @author admin + * @date 2025/01/07 16:39 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreProductLowStockValidate + * @author admin + * @date 2025/01/07 16:39 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductLowStockValidate + * @author admin + * @date 2025/01/07 16:39 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/store_product_low_stock/StoreProductLowStock.php b/app/common/model/store_product_low_stock/StoreProductLowStock.php new file mode 100644 index 00000000..a24b00ee --- /dev/null +++ b/app/common/model/store_product_low_stock/StoreProductLowStock.php @@ -0,0 +1,22 @@ +