diff --git a/app/Controller/Api/DishController.php b/app/Controller/Api/DishController.php index 4606df6..ca1ce84 100644 --- a/app/Controller/Api/DishController.php +++ b/app/Controller/Api/DishController.php @@ -53,4 +53,16 @@ class DishController { return (new DishService())->list(); } + + /** + * 菜品删除 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "delete", methods: "POST")] + #[Scene(scene: "delete")] + public function dishDelete(dishRequest $request): array + { + return (new DishService())->delete(); + } } diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php index 3ec2dff..800c289 100644 --- a/app/Request/Api/DishRequest.php +++ b/app/Request/Api/DishRequest.php @@ -34,7 +34,8 @@ class DishRequest extends FormRequest 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'] + 'list' =>['limit'], + 'delete' =>['id'], ]; } diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php index a2d094a..2d929aa 100644 --- a/app/Service/Api/Material/DishService.php +++ b/app/Service/Api/Material/DishService.php @@ -7,6 +7,7 @@ namespace App\Service\Api\Material; use App\Constants\Common\DishCode; use App\Exception\ErrException; use App\Model\Dish; +use App\Model\MaterialApplication; use App\Service\Api\BaseService; use Hyperf\Di\Annotation\Inject; @@ -19,6 +20,9 @@ class DishService extends BaseService #[Inject] protected Dish $DishModel; + #[Inject] + protected MaterialApplication $MaterialApplication; + public function handle() { @@ -93,6 +97,23 @@ class DishService extends BaseService return $this->return->success(); } + public function delete(): array + { + $id = (int)$this->request->input('id'); + $info = $this->DishModel->getInfoById($id); + $application = $this->MaterialApplication + ->where('dish_id', $id) + ->where('is_del', DishCode::IS_NO_DEL) + ->first(); + if (!empty($application)) throw new ErrException('该菜品存在申请材料'); + + $info->is_del = DishCode::IS_DELETE; + + if (!$info->save()) throw new ErrException('菜品删除失败'); + return $this->return->success(); + + } + public function list(): array { $limit = (int)$this->request->input('limit'); diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index dc46d29..7bbc089 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -92,6 +92,9 @@ class MaterialService extends BaseService{ if (!empty($processing)){ $info->processing = $processing; } + if($info->status == MaterialCode::AUDIT_REFUSE){ + $info->status = MaterialCode::UN_AUDIT; + } $info->operator_id = $this->userId; if (!$info->save()) throw new ErrException('申请修改失败'); @@ -104,7 +107,7 @@ class MaterialService extends BaseService{ $id = (int)$this->request->input('id'); $info = $this->MaterialApplication->getInfoById($id); $info->is_del = 2; - if ($info->status == MaterialCode::ALL_OUT) throw new ErrException("已全部出库"); + if ($info->status == MaterialCode::ALL_OUT || $info->status == MaterialCode::PART_OUT) throw new ErrException("已进行出库"); if (!$info->save()) throw new ErrException('申请删除失败'); return $this->return->success(); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 7a4c8d8..880d8e9 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -410,6 +410,11 @@ Authorization: Bearer {{admin_token}} id=1&pre_quantity=300&price=12 +### 厨师删除菜品 +POST {{host}}/api/dish/delete?id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + ### 厨师查看排菜 GET {{host}}/api/dish/list?limit=10 content-type: application/json @@ -437,4 +442,5 @@ Authorization: Bearer {{admin_token}} ### 个人申请材料列表 GET {{host}}/api/material/application_list?limit=10 content-type: application/json -Authorization: Bearer {{admin_token}} \ No newline at end of file +Authorization: Bearer {{admin_token}} +