From e3beb860d3200923a3c08447e693040e8caa73ea Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Wed, 16 Jul 2025 16:57:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=80=81=E9=A1=B9=E7=9B=AE=E8=8F=9C=E5=93=81=E3=80=81?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=8F=9C=E5=93=81=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ProjectController.php | 95 +++++++++++++++ .../controller/ProjectDishesController.php | 95 +++++++++++++++ .../ProjectDishesProductController.php | 95 +++++++++++++++ app/admin/lists/ProjectDishesLists.php | 66 +++++++++++ app/admin/lists/ProjectDishesProductLists.php | 67 +++++++++++ app/admin/lists/ProjectLists.php | 73 ++++++++++++ app/admin/logic/ProjectDishesLogic.php | 98 ++++++++++++++++ app/admin/logic/ProjectDishesProductLogic.php | 104 +++++++++++++++++ app/admin/logic/ProjectLogic.php | 110 ++++++++++++++++++ .../validate/ProjectDishesProductValidate.php | 82 +++++++++++++ app/admin/validate/ProjectDishesValidate.php | 82 +++++++++++++ app/admin/validate/ProjectValidate.php | 82 +++++++++++++ app/common/model/Project.php | 22 ++++ app/common/model/ProjectDishes.php | 31 +++++ app/common/model/ProjectDishesProduct.php | 41 +++++++ 15 files changed, 1143 insertions(+) create mode 100644 app/admin/controller/ProjectController.php create mode 100644 app/admin/controller/ProjectDishesController.php create mode 100644 app/admin/controller/ProjectDishesProductController.php create mode 100644 app/admin/lists/ProjectDishesLists.php create mode 100644 app/admin/lists/ProjectDishesProductLists.php create mode 100644 app/admin/lists/ProjectLists.php create mode 100644 app/admin/logic/ProjectDishesLogic.php create mode 100644 app/admin/logic/ProjectDishesProductLogic.php create mode 100644 app/admin/logic/ProjectLogic.php create mode 100644 app/admin/validate/ProjectDishesProductValidate.php create mode 100644 app/admin/validate/ProjectDishesValidate.php create mode 100644 app/admin/validate/ProjectValidate.php create mode 100644 app/common/model/Project.php create mode 100644 app/common/model/ProjectDishes.php create mode 100644 app/common/model/ProjectDishesProduct.php diff --git a/app/admin/controller/ProjectController.php b/app/admin/controller/ProjectController.php new file mode 100644 index 0000000..10b590e --- /dev/null +++ b/app/admin/controller/ProjectController.php @@ -0,0 +1,95 @@ +dataLists(new ProjectLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function add() + { + $params = (new ProjectValidate())->post()->goCheck('add'); + $result = ProjectLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function edit() + { + $params = (new ProjectValidate())->post()->goCheck('edit'); + $result = ProjectLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function delete() + { + $params = (new ProjectValidate())->post()->goCheck('delete'); + ProjectLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function detail() + { + $params = (new ProjectValidate())->goCheck('detail'); + $result = ProjectLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/ProjectDishesController.php b/app/admin/controller/ProjectDishesController.php new file mode 100644 index 0000000..afadafa --- /dev/null +++ b/app/admin/controller/ProjectDishesController.php @@ -0,0 +1,95 @@ +dataLists(new ProjectDishesLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function add() + { + $params = (new ProjectDishesValidate())->post()->goCheck('add'); + $result = ProjectDishesLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectDishesLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function edit() + { + $params = (new ProjectDishesValidate())->post()->goCheck('edit'); + $result = ProjectDishesLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectDishesLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function delete() + { + $params = (new ProjectDishesValidate())->post()->goCheck('delete'); + ProjectDishesLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function detail() + { + $params = (new ProjectDishesValidate())->goCheck('detail'); + $result = ProjectDishesLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/ProjectDishesProductController.php b/app/admin/controller/ProjectDishesProductController.php new file mode 100644 index 0000000..40e1bd0 --- /dev/null +++ b/app/admin/controller/ProjectDishesProductController.php @@ -0,0 +1,95 @@ +dataLists(new ProjectDishesProductLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function add() + { + $params = (new ProjectDishesProductValidate())->post()->goCheck('add'); + $result = ProjectDishesProductLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectDishesProductLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function edit() + { + $params = (new ProjectDishesProductValidate())->post()->goCheck('edit'); + $result = ProjectDishesProductLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectDishesProductLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function delete() + { + $params = (new ProjectDishesProductValidate())->post()->goCheck('delete'); + ProjectDishesProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function detail() + { + $params = (new ProjectDishesProductValidate())->goCheck('detail'); + $result = ProjectDishesProductLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/ProjectDishesLists.php b/app/admin/lists/ProjectDishesLists.php new file mode 100644 index 0000000..686b152 --- /dev/null +++ b/app/admin/lists/ProjectDishesLists.php @@ -0,0 +1,66 @@ + ['project_id', 'dishes_id'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function lists(): array + { + return ProjectDishes::where($this->searchWhere) + ->with(['dishes', 'project']) + ->field(['id', 'project_id', 'dishes_id', 'consume_time', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function count(): int + { + return ProjectDishes::where($this->searchWhere)->count(); + } + +} diff --git a/app/admin/lists/ProjectDishesProductLists.php b/app/admin/lists/ProjectDishesProductLists.php new file mode 100644 index 0000000..6938a1b --- /dev/null +++ b/app/admin/lists/ProjectDishesProductLists.php @@ -0,0 +1,67 @@ + ['project_id', 'dishes_id', 'product_id'], + + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function lists(): array + { + return ProjectDishesProduct::where($this->searchWhere) + ->with(['dishes', 'project', 'product', 'unit']) + ->field(['id', 'project_id', 'dishes_id', 'product_id', 'unit_id', 'nums', 'consume_time', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function count(): int + { + return ProjectDishesProduct::where($this->searchWhere)->count(); + } + +} diff --git a/app/admin/lists/ProjectLists.php b/app/admin/lists/ProjectLists.php new file mode 100644 index 0000000..ff1a5b6 --- /dev/null +++ b/app/admin/lists/ProjectLists.php @@ -0,0 +1,73 @@ + ['project_status'], + '>=' => ['start_time'], + '<=' => ['end_time'], + '%like%' => ['name', 'linkman', 'contact_number'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function lists(): array + { + $query = Project::where($this->searchWhere); + $sql = $query->field(['id', 'name', 'address', 'project_status', 'start_time', 'end_time', 'linkman', 'contacts_dept', 'contact_number', 'area_manager_id', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->fetchSql() + ->select(); + return $query->field(['id', 'name', 'address', 'project_status', 'start_time', 'end_time', 'linkman', 'contacts_dept', 'contact_number', 'area_manager_id', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function count(): int + { + return Project::where($this->searchWhere)->count(); + } + +} diff --git a/app/admin/logic/ProjectDishesLogic.php b/app/admin/logic/ProjectDishesLogic.php new file mode 100644 index 0000000..13ba959 --- /dev/null +++ b/app/admin/logic/ProjectDishesLogic.php @@ -0,0 +1,98 @@ + $params['project_id'], + 'dishes_id' => $params['dishes_id'], + 'consume_time' => $params['consume_time'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectDishes::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'dishes_id' => $params['dishes_id'], + 'consume_time' => $params['consume_time'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function delete(array $params): bool + { + return ProjectDishes::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function detail($params): array + { + return ProjectDishes::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/admin/logic/ProjectDishesProductLogic.php b/app/admin/logic/ProjectDishesProductLogic.php new file mode 100644 index 0000000..7a70db5 --- /dev/null +++ b/app/admin/logic/ProjectDishesProductLogic.php @@ -0,0 +1,104 @@ + $params['project_id'], + 'dishes_id' => $params['dishes_id'], + 'product_id' => $params['product_id'], + 'unit_id' => $params['unit_id'], + 'nums' => $params['nums'], + 'consume_time' => strtotime($params['consume_time']), + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectDishesProduct::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'dishes_id' => $params['dishes_id'], + 'product_id' => $params['product_id'], + 'unit_id' => $params['unit_id'], + 'nums' => $params['nums'], + 'consume_time' => strtotime($params['consume_time']), + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function delete(array $params): bool + { + return ProjectDishesProduct::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function detail($params): array + { + return ProjectDishesProduct::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/ProjectLogic.php b/app/admin/logic/ProjectLogic.php new file mode 100644 index 0000000..4bc1b5c --- /dev/null +++ b/app/admin/logic/ProjectLogic.php @@ -0,0 +1,110 @@ + $params['name'], + 'address' => $params['address'], + 'project_status' => $params['project_status'], + 'start_time' => $params['start_time'], + 'end_time' => $params['end_time'], + 'linkman' => $params['linkman'], + 'contacts_dept' => $params['contacts_dept'], + 'contact_number' => $params['contact_number'], + 'area_manager_id' => $params['area_manager_id'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Project::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'address' => $params['address'], + 'project_status' => $params['project_status'], + 'start_time' => $params['start_time'], + 'end_time' => $params['end_time'], + 'linkman' => $params['linkman'], + 'contacts_dept' => $params['contacts_dept'], + 'contact_number' => $params['contact_number'], + 'area_manager_id' => $params['area_manager_id'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function delete(array $params): bool + { + return Project::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public static function detail($params): array + { + return Project::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/admin/validate/ProjectDishesProductValidate.php b/app/admin/validate/ProjectDishesProductValidate.php new file mode 100644 index 0000000..e64eebd --- /dev/null +++ b/app/admin/validate/ProjectDishesProductValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ProjectDishesProductValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ProjectDishesProductValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ProjectDishesProductValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectDishesProductValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/ProjectDishesValidate.php b/app/admin/validate/ProjectDishesValidate.php new file mode 100644 index 0000000..4d675a6 --- /dev/null +++ b/app/admin/validate/ProjectDishesValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ProjectDishesValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ProjectDishesValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ProjectDishesValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectDishesValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/ProjectValidate.php b/app/admin/validate/ProjectValidate.php new file mode 100644 index 0000000..254f108 --- /dev/null +++ b/app/admin/validate/ProjectValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ProjectValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ProjectValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ProjectValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectValidate + * @author likeadmin + * @date 2025/07/16 15:09 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/Project.php b/app/common/model/Project.php new file mode 100644 index 0000000..57480f6 --- /dev/null +++ b/app/common/model/Project.php @@ -0,0 +1,22 @@ +hasOne(Project::class, 'id', 'project_id')->field('id,name'); + } + + public function dishes() + { + return $this->hasOne(Dishes::class, 'id', 'dishes_id')->field('id,name'); + } + +} diff --git a/app/common/model/ProjectDishesProduct.php b/app/common/model/ProjectDishesProduct.php new file mode 100644 index 0000000..6424d8b --- /dev/null +++ b/app/common/model/ProjectDishesProduct.php @@ -0,0 +1,41 @@ +hasOne(Project::class, 'id', 'project_id')->field('id,name'); + } + + public function dishes() + { + return $this->hasOne(Dishes::class, 'id', 'dishes_id')->field('id,name'); + } + + public function product() + { + return $this->hasOne(Product::class, 'id', 'product_id')->field('id,name'); + } + + public function unit() + { + return $this->hasOne(ProductUnit::class, 'id', 'unit_id')->field('id,name'); + } + +}