From a441b94e949771a9313275578da562d3e15fd0fa Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 31 Jul 2024 18:07:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E5=92=8C=E5=95=86=E5=93=81=E4=BB=93=E5=82=A8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../warehouse/WarehouseController.php | 95 +++++++++++++++ .../WarehouseProductController.php | 95 +++++++++++++++ app/admin/lists/warehouse/WarehouseLists.php | 65 +++++++++++ .../WarehouseProductLists.php | 65 +++++++++++ app/admin/logic/warehouse/WarehouseLogic.php | 106 +++++++++++++++++ .../WarehouseProductLogic.php | 108 ++++++++++++++++++ .../validate/warehouse/WarehouseValidate.php | 84 ++++++++++++++ .../WarehouseProductValidate.php | 98 ++++++++++++++++ app/common/model/warehouse/Warehouse.php | 22 ++++ .../warehouse_product/WarehouseProduct.php | 22 ++++ 10 files changed, 760 insertions(+) create mode 100644 app/admin/controller/warehouse/WarehouseController.php create mode 100644 app/admin/controller/warehouse_product/WarehouseProductController.php create mode 100644 app/admin/lists/warehouse/WarehouseLists.php create mode 100644 app/admin/lists/warehouse_product/WarehouseProductLists.php create mode 100644 app/admin/logic/warehouse/WarehouseLogic.php create mode 100644 app/admin/logic/warehouse_product/WarehouseProductLogic.php create mode 100644 app/admin/validate/warehouse/WarehouseValidate.php create mode 100644 app/admin/validate/warehouse_product/WarehouseProductValidate.php create mode 100644 app/common/model/warehouse/Warehouse.php create mode 100644 app/common/model/warehouse_product/WarehouseProduct.php diff --git a/app/admin/controller/warehouse/WarehouseController.php b/app/admin/controller/warehouse/WarehouseController.php new file mode 100644 index 00000000..8f4506ef --- /dev/null +++ b/app/admin/controller/warehouse/WarehouseController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseLists()); + } + + + /** + * @notes 添加仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function add() + { + $params = (new WarehouseValidate())->post()->goCheck('add'); + $result = WarehouseLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 编辑仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function edit() + { + $params = (new WarehouseValidate())->post()->goCheck('edit'); + $result = WarehouseLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 删除仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function delete() + { + $params = (new WarehouseValidate())->post()->goCheck('delete'); + WarehouseLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取仓库信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function detail() + { + $params = (new WarehouseValidate())->goCheck('detail'); + $result = WarehouseLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php new file mode 100644 index 00000000..e1bac316 --- /dev/null +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseProductLists()); + } + + + /** + * @notes 添加商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function add() + { + $params = (new WarehouseProductValidate())->post()->goCheck('add'); + $result = WarehouseProductLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 编辑商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function edit() + { + $params = (new WarehouseProductValidate())->post()->goCheck('edit'); + $result = WarehouseProductLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 删除商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function delete() + { + $params = (new WarehouseProductValidate())->post()->goCheck('delete'); + WarehouseProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品仓储信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function detail() + { + $params = (new WarehouseProductValidate())->goCheck('detail'); + $result = WarehouseProductLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse/WarehouseLists.php b/app/admin/lists/warehouse/WarehouseLists.php new file mode 100644 index 00000000..4552a97c --- /dev/null +++ b/app/admin/lists/warehouse/WarehouseLists.php @@ -0,0 +1,65 @@ + ['name', 'contacts', 'tel'], + ]; + } + + + /** + * @notes 获取仓库信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:10 + */ + public function lists(): array + { + return Warehouse::where($this->searchWhere) + ->field(['id', 'name', 'code', 'contacts', 'tel', 'address', 'notes', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取仓库信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:10 + */ + public function count(): int + { + return Warehouse::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php new file mode 100644 index 00000000..c33e58cd --- /dev/null +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -0,0 +1,65 @@ + ['warehouse_id', 'product_id', 'financial_pm'], + ]; + } + + + /** + * @notes 获取商品仓储信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:55 + */ + public function lists(): array + { + return WarehouseProduct::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品仓储信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:55 + */ + public function count(): int + { + return WarehouseProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/warehouse/WarehouseLogic.php b/app/admin/logic/warehouse/WarehouseLogic.php new file mode 100644 index 00000000..13568bdb --- /dev/null +++ b/app/admin/logic/warehouse/WarehouseLogic.php @@ -0,0 +1,106 @@ + $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + 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/07/31 16:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Warehouse::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + 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/07/31 16:10 + */ + public static function delete(array $params): bool + { + return Warehouse::destroy($params['id']); + } + + + /** + * @notes 获取仓库信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:10 + */ + public static function detail($params): array + { + return Warehouse::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php new file mode 100644 index 00000000..b829fc58 --- /dev/null +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -0,0 +1,108 @@ + $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'] + ]); + + 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/07/31 16:55 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + WarehouseProduct::where('id', $params['id'])->update([ + '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'] + ]); + + 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/07/31 16:55 + */ + public static function delete(array $params): bool + { + return WarehouseProduct::destroy($params['id']); + } + + + /** + * @notes 获取商品仓储信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:55 + */ + public static function detail($params): array + { + return WarehouseProduct::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/warehouse/WarehouseValidate.php b/app/admin/validate/warehouse/WarehouseValidate.php new file mode 100644 index 00000000..e044a6ff --- /dev/null +++ b/app/admin/validate/warehouse/WarehouseValidate.php @@ -0,0 +1,84 @@ + 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '仓库名称', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneAdd() + { + return $this->only(['name']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneEdit() + { + return $this->only(['id','name']); + } + + + /** + * @notes 删除场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/warehouse_product/WarehouseProductValidate.php b/app/admin/validate/warehouse_product/WarehouseProductValidate.php new file mode 100644 index 00000000..afbe4862 --- /dev/null +++ b/app/admin/validate/warehouse_product/WarehouseProductValidate.php @@ -0,0 +1,98 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'financial_pm' => 'require', + 'batch' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'financial_pm' => '0 = 出库 1 = 获得', + 'batch' => '批次', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '总价', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/warehouse/Warehouse.php b/app/common/model/warehouse/Warehouse.php new file mode 100644 index 00000000..4689aefa --- /dev/null +++ b/app/common/model/warehouse/Warehouse.php @@ -0,0 +1,22 @@ +