From 6b38a6b73201b54096582280129f897fbdb79b12 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 14 Jan 2025 17:04:48 +0800 Subject: [PATCH] feat:dish depot --- app/Constants/Admin/DepotCode.php | 17 ++++ app/Constants/Common/DishCode.php | 13 +++ app/Controller/Admin/DepotController.php | 69 ++++++++++++++ app/Controller/Admin/DishController.php | 33 +++++++ app/Model/Depot.php | 59 ++++++++++++ app/Model/Dish.php | 46 +++++++++ app/Request/Admin/DepotRequest.php | 41 ++++++++ app/Request/Admin/DishRequest.php | 39 ++++++++ app/Service/Admin/Depot/DepotService.php | 114 +++++++++++++++++++++++ app/Service/Admin/Good/DishService.php | 64 +++++++++++++ sync/http/admin/auth.http | 28 ++++++ 11 files changed, 523 insertions(+) create mode 100644 app/Constants/Admin/DepotCode.php create mode 100644 app/Constants/Common/DishCode.php create mode 100644 app/Controller/Admin/DepotController.php create mode 100644 app/Controller/Admin/DishController.php create mode 100644 app/Model/Depot.php create mode 100644 app/Model/Dish.php create mode 100644 app/Request/Admin/DepotRequest.php create mode 100644 app/Request/Admin/DishRequest.php create mode 100644 app/Service/Admin/Depot/DepotService.php create mode 100644 app/Service/Admin/Good/DishService.php diff --git a/app/Constants/Admin/DepotCode.php b/app/Constants/Admin/DepotCode.php new file mode 100644 index 0000000..e986136 --- /dev/null +++ b/app/Constants/Admin/DepotCode.php @@ -0,0 +1,17 @@ +depotList(); + } + + /** + * 添加仓库 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_add", methods: "POST")] + #[Scene(scene: "depot_add")] + public function add(DepotRequest $request): array + { + return (new DepotService)->add(); + } + + /** + * 修改仓库 + * @return array + */ + #[RequestMapping(path: "depot_edit", methods: "POST")] + #[Scene(scene: "depot_edit")] + public function edit(DepotRequest $request): array + { + return (new DepotService)->edit(); + } + + /** + * 删除仓库 + * @return array + */ + #[RequestMapping(path: "depot_delete", methods: "GET")] + #[Scene(scene: "depot_delete")] + public function delete(DepotRequest $request): array + { + return (new DepotService)->delete(); + } +} diff --git a/app/Controller/Admin/DishController.php b/app/Controller/Admin/DishController.php new file mode 100644 index 0000000..7dca1ca --- /dev/null +++ b/app/Controller/Admin/DishController.php @@ -0,0 +1,33 @@ +dishList(); + } + + +} diff --git a/app/Model/Depot.php b/app/Model/Depot.php new file mode 100644 index 0000000..54af478 --- /dev/null +++ b/app/Model/Depot.php @@ -0,0 +1,59 @@ + 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->where('is_del',DepotCode::IS_NO_DEL)->first(); + } + + /** + * @param string $name + * @param int $kitchen_id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoByName(string $name,int $kitchen_id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('name', $name)->where('kitchen_id',$kitchen_id)->where('is_del',DepotCode::IS_NO_DEL)->first(); + } +} diff --git a/app/Model/Dish.php b/app/Model/Dish.php new file mode 100644 index 0000000..4cb19d5 --- /dev/null +++ b/app/Model/Dish.php @@ -0,0 +1,46 @@ + 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; +} diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php new file mode 100644 index 0000000..2561503 --- /dev/null +++ b/app/Request/Admin/DepotRequest.php @@ -0,0 +1,41 @@ + 'required|integer', + 'query_id' => 'sometimes|integer', + 'query_kitchen_id' => 'sometimes|integer', + 'name' => 'required|string', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', + 'id' => 'required|integer', + ]; + } + + protected array $scenes = [ + 'depot_list' => ['limit','query_id','query_kitchen_id'], + 'depot_add' => ['name','city_id','kitchen_id'], + 'depot_edit' => ['id','name','city_id','kitchen_id'], + 'depot_delete' => ['id'], + ]; +} diff --git a/app/Request/Admin/DishRequest.php b/app/Request/Admin/DishRequest.php new file mode 100644 index 0000000..6d6e918 --- /dev/null +++ b/app/Request/Admin/DishRequest.php @@ -0,0 +1,39 @@ + 'required|integer', + 'query_id' => 'sometimes|integer', + 'query_dish_name' => 'sometimes|string', + 'query_city_id' => 'sometimes|integer|exists:system_city,id', + 'query_date_id' => 'sometimes|integer|exists:cycle,id', + 'query_status' => 'sometimes|integer', + 'query_chef_id' => 'sometimes|integer', + + ]; + } + + protected array $scenes = [ + 'list' => ['limit','query_id','query_dish_name','query_city_id','query_date_id','query_status','query_chef_id'], + ]; +} diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php new file mode 100644 index 0000000..533e924 --- /dev/null +++ b/app/Service/Admin/Depot/DepotService.php @@ -0,0 +1,114 @@ +request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->when($id,function ($query) use ($id) { + $query->where('id',$id); + }) + ->when($kitchenId,function ($query) use ($kitchenId) { + $query->where('kitchen_id',$kitchenId); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + + } + + /** + * @return array + */ + public function add():array + { + $name = $this->request->input('name'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + $info = $this->DepotModel->getInfoByName($name,$kitchen_id); + if (!empty($info)) throw new ErrException('仓库已存在'); + + $depot = new Depot(); + $depot->name = $name; + $depot->city_id = $this->request->input('city_id'); + $depot->kitchen_id = $kitchen_id; + + if (!$depot->save()) throw new ErrException('仓库添加失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function edit(): array + { + $id = (int)$this->request->input('id'); + $depotName = $this->request->input('name'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + + $info = $this->DepotModel->getInfoById($id); + if (empty($info)) throw new ErrException('数据不存在'); + + $name = $this->DepotModel->getInfoByName($depotName,$kitchen_id); + if (!empty($name)){ + if ($name->id != $info->id && $info->kitchen_id == $kitchen_id) + throw new ErrException('仓库已存在'); + } + + $info->name = $depotName; + $info->city_id = (int)$this->request->input('city_id'); + $info->kitchen_id = $kitchen_id; + + if (!$info->save()) throw new ErrException('仓库修改失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function delete(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->DepotModel->getInfoById($id); + if (empty($info)) throw new ErrException('仓库不存在'); + + $info->is_del = DepotCode::IS_DEL; + + if (!$info->save()) throw new ErrException('删除失败'); + + return $this->return->success(); + } + + +} \ No newline at end of file diff --git a/app/Service/Admin/Good/DishService.php b/app/Service/Admin/Good/DishService.php new file mode 100644 index 0000000..cf6b9f4 --- /dev/null +++ b/app/Service/Admin/Good/DishService.php @@ -0,0 +1,64 @@ +request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $cityId = (int)$this->request->input('query_city_id',0); + $dishName = $this->request->input('query_dish_name'); + $dateId = (int)$this->request->input('query_date_id'); + $status = (int)$this->request->input('query_status'); + $chefId = (int)$this->request->input('query_chef_id',0); + + $list = $this->DishModel + ->where('is_del',DishCode::IS_NO_DEL) + ->when($id > 0, function ($query) use ($id) { + $query->where('id', $id); + }) + ->when($cityId > 0, function ($query) use ($cityId) { + $query->where('city_id', $cityId); + }) + ->when($dishName, function ($query) use ($dishName) { + $query->where('dish', 'like', "$dishName%"); + }) + ->when($dateId, function ($query) use ($dateId) { + $query->where('cycle_id', $dateId); + }) + ->when($status, function ($query) use ($status) { + $query->where('status', $status); + }) + ->when($chefId, function ($query) use ($chefId) { + $query->where('chef_id', $chefId); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 4f3cf55..65c30c1 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -276,3 +276,31 @@ GET {{host}}/admin/member/list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +### 排菜列表 +GET {{host}}/admin/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 仓库列表 +GET {{host}}/admin/depot/depot_list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 仓库添加 +POST {{host}}/admin/depot/depot_add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +name=蔬菜仓库&city_id=1&kitchen_id=1 + +### 仓库修改信息 +POST {{host}}/admin/depot/depot_edit +content-type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=2&name=冻品仓库&city_id=1&kitchen_id=1 + +### 仓库删除 +GET {{host}}/admin/depot/depot_delete?id=2 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} \ No newline at end of file