diff --git a/app/Controller/Api/DishController.php b/app/Controller/Api/DishController.php new file mode 100644 index 0000000..4606df6 --- /dev/null +++ b/app/Controller/Api/DishController.php @@ -0,0 +1,56 @@ +add(); + } + + /** + * 菜品修改 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function dishEdit(dishRequest $request): array + { + return (new DishService())->edit(); + } + + /** + * 菜品列表 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "list", methods: "GET")] + #[Scene(scene: "list")] + public function dishList(dishRequest $request): array + { + return (new DishService())->list(); + } +} diff --git a/app/Model/Dish.php b/app/Model/Dish.php index 3a7b4b2..92d2a2d 100644 --- a/app/Model/Dish.php +++ b/app/Model/Dish.php @@ -17,7 +17,6 @@ use Hyperf\DbConnection\Model\Model; * @property string $side_dish * @property string $flavor * @property int $cycle_id - * @property int $status * @property int $city_id * @property int $kitchen_id * @property int $chef_id @@ -40,7 +39,7 @@ class Dish extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; const string CREATED_AT = 'create_time'; diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php new file mode 100644 index 0000000..3ec2dff --- /dev/null +++ b/app/Request/Api/DishRequest.php @@ -0,0 +1,40 @@ + 'required|integer', + 'dish_name' => 'sometimes|string', + 'cycle_id' => 'sometimes|integer|exists:cycle,id', + 'city_id' => 'sometimes|integer|exists:system_city,id', + 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', + + ]; + } + + protected array $scenes = [ + 'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','cycle_id','city_id','kitchen_id'], + 'edit' => ['id','dish_name','profile','pre_quantity','price','side_dish','flavor'], + 'list' =>['limit'] + + ]; +} diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php new file mode 100644 index 0000000..a2d094a --- /dev/null +++ b/app/Service/Api/Material/DishService.php @@ -0,0 +1,107 @@ +request->input('dish_name'); + $profile = $this->request->input('profile'); + $pre_quantity = (int)$this->request->input('pre_quantity'); + $price = (double)$this->request->input('price'); + $side_dish = $this->request->input('side_dish'); + $flavor = $this->request->input('flavor'); + $cycle_id = (int)$this->request->input('cycle_id'); + $city_id = (int)$this->request->input('city_id'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + $chef_id = $this->userId; + + $dish = new Dish(); + $dish ->dish = $dish_name; + $dish ->profile = $profile; + $dish ->pre_quantity = $pre_quantity; + $dish ->price = $price; + $dish ->side_dish = $side_dish; + $dish ->flavor = $flavor; + $dish ->cycle_id = $cycle_id; + $dish ->city_id = $city_id; + $dish ->kitchen_id = $kitchen_id; + $dish ->chef_id = $chef_id; + + if (!$dish->save()) throw new ErrException('菜品添加失败'); + + return $this->return->success('success'); + } + + public function edit(): array + { + $dish_id = (int)$this->request->input('id'); + $dish_name = $this->request->input('dish_name'); + $profile = $this->request->input('profile'); + $pre_quantity = (int)$this->request->input('pre_quantity'); + $price = (double)$this->request->input('price'); + $side_dish = $this->request->input('side_dish'); + $flavor = $this->request->input('flavor'); + + $info = $this->DishModel->getInfoById($dish_id); + if (empty($info)) throw new ErrException('数据不存在'); + + if (!empty($dish_name)) { + $info->dish = $dish_name; + } + if (!empty($profile)) { + $info->profile = $profile; + } + if (!empty($pre_quantity)) { + $info->pre_quantity = $pre_quantity; + } + if (!empty($price)) { + $info->price = $price; + } + if (!empty($side_dish)) { + $info->side_dish = $side_dish; + } + if (!empty($flavor)) { + $info->flavor = $flavor; + } + if (!$info->save()) throw new ErrException('菜品修改失败'); + + return $this->return->success(); + } + + public function list(): array + { + $limit = (int)$this->request->input('limit'); + $chef_id = $this->userId; + $list = $this->DishModel + ->where('chef_id', $chef_id) + ->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 90422da..10b301e 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -276,11 +276,6 @@ 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 @@ -394,5 +389,28 @@ POST {{host}}/admin/depot/depot_purchase_update Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -id=1&number=8 +id=1&number=9 +### 排菜列表 +GET {{host}}/admin/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 厨师添加菜品 +POST {{host}}/api/dish/add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +dish_name=排骨饭&profile=加水&pre_quantity=500&price=15&side_dish=33333&flavor=清淡&cycle_id=1&city_id=1&kitchen_id=1 + +### 厨师修改菜品 +POST {{host}}/api/dish/edit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&pre_quantity=300&price=12 + +### 厨师查看排菜 +GET {{host}}/api/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} \ No newline at end of file