From 804d65b7259850ecaacda7b8ff8302846c9bd319 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 8 Jan 2025 17:52:29 +0800 Subject: [PATCH] feat:chef --- app/Controller/Admin/ChefController.php | 29 +++++------- app/Model/Chef.php | 9 ++-- app/Request/Admin/ChefRequest.php | 12 ++--- app/Service/Admin/System/ChefService.php | 52 +++++++--------------- app/Service/Admin/User/EmployeeService.php | 14 ++++-- sync/http/admin/auth.http | 19 +++++++- 6 files changed, 67 insertions(+), 68 deletions(-) diff --git a/app/Controller/Admin/ChefController.php b/app/Controller/Admin/ChefController.php index cd8645e..a3d93ac 100644 --- a/app/Controller/Admin/ChefController.php +++ b/app/Controller/Admin/ChefController.php @@ -42,13 +42,6 @@ class ChefController return (new ChefService())->chefDetailList(); } - #[RequestMapping(path: "chef_info", methods: "GET")] - #[Scene(scene: "chef_info")] - public function chefInfo(chefRequest $request) - { - return (new chefService)->chefInfo(); - } - /** * 设置厨师数据 * @param ChefRequest $request @@ -61,15 +54,15 @@ class ChefController return (new ChefService)->settingChef(); } - /** - * 删除厨师数据 - * @param ChefRequest $request - * @return array - */ - #[RequestMapping(path: "delete", methods: "GET")] - #[Scene(scene: "delete")] - public function delete(chefRequest $request) - { - return (new chefService)->delete(); - } +// /** +// * 删除厨师数据 +// * @param ChefRequest $request +// * @return array +// */ +// #[RequestMapping(path: "delete", methods: "GET")] +// #[Scene(scene: "delete")] +// public function delete(chefRequest $request) +// { +// return (new chefService)->delete(); +// } } diff --git a/app/Model/Chef.php b/app/Model/Chef.php index 4241329..761f072 100644 --- a/app/Model/Chef.php +++ b/app/Model/Chef.php @@ -4,13 +4,12 @@ declare(strict_types=1); namespace App\Model; +use App\Constants\Admin\UserCode; use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; /** - * @property int $id - * @property string $name - * @property int $avatar_id + * @property int $id * @property int $user_id * @property string $profile * @property string $specialties @@ -33,7 +32,7 @@ class Chef extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'avatar_id' => 'integer', 'user_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'is_del' => 'integer']; const string CREATED_AT = 'create_time'; @@ -54,7 +53,7 @@ class Chef extends Model */ public function getInfoByUserId(int $userId): \Hyperf\Database\Model\Model|Builder|null { - return $this->where('user_id', $userId)->first(); + return $this->where('is_del',UserCode::IS_NO_DEL)->where('user_id', $userId)->first(); } } diff --git a/app/Request/Admin/ChefRequest.php b/app/Request/Admin/ChefRequest.php index 1ebae8c..0c29ab6 100644 --- a/app/Request/Admin/ChefRequest.php +++ b/app/Request/Admin/ChefRequest.php @@ -25,7 +25,10 @@ class ChefRequest extends FormRequest 'limit' => 'required|integer', 'query_chef_name' =>'sometimes|string', 'query_chef_id' =>'sometimes|integer|exists:admin_user,id', - + 'chef_id' =>'sometimes|integer|exists:admin_user,id', + 'user_id' =>'required|integer|exists:chef,user_id', + 'profile' =>'sometimes', + 'specialties' =>'sometimes', ]; } @@ -36,17 +39,14 @@ class ChefRequest extends FormRequest 'query_chef_id' ], 'chef_detail_list' => [ - 'query_chef_name', + 'chef_id', ], - 'chefInfo' =>['id'], 'setting_chef' => [ - 'name', - 'avatar_id', 'user_id', 'profile', 'specialties' ], - 'delete' => ['id'], +// 'delete' => ['id'], ]; } diff --git a/app/Service/Admin/System/ChefService.php b/app/Service/Admin/System/ChefService.php index 1b835e3..fe975b2 100644 --- a/app/Service/Admin/System/ChefService.php +++ b/app/Service/Admin/System/ChefService.php @@ -41,7 +41,7 @@ class ChefService extends BaseService ->where('status',UserCode::ENABLE) ->where('role_id',RoleCode::CHEF) ->when(!empty($name), function ($query) use ($name) { - $query->where('name', 'like', "%{$name}%"); + $query->where('chinese_name', 'like', "$name%"); }) ->when($id = $this->request->input('query_chef_id'), function ($query) use ($id) { $query->where('id', $id); @@ -53,42 +53,24 @@ class ChefService extends BaseService public function chefDetailList(): array { - $name = $this->request->input('query_chef_name'); + $chefId = (int)$this->request->input('chef_id'); + $list = $this - ->chefModel - ->where('is_del',UserCode::IS_NO_DEL) - ->when(!empty($name), function ($query) use ($name) { - $query->where('name', 'like', "%{$name}%"); + ->adminUserModel + ->leftJoin('chef', 'admin_user.id', '=', 'chef.user_id') + ->where('admin_user.is_del',UserCode::IS_NO_DEL) + ->where('admin_user.status',UserCode::ENABLE) + ->where('admin_user.role_id',RoleCode::CHEF) + ->when(!empty($chefId), function ($query) use ($chefId) { + $query->where('admin_user.id', $chefId); }) - ->get(['id','name','avatar_id','user_id','profile','specialties']); + ->get(['admin_user.id','admin_user.avatar','admin_user.chinese_name','chef.profile','chef.specialties']); if (empty($list)) return $this->return->success('success',['list' => []]); return $this->return->success('success',['list' => $list->toArray()]); } - /** - * 根据id获取厨师信息 - * @return array - */ - public function chefInfo(): array - { - $data = $this->chefModel - ->getInfoById((int)$this->request->input('id')); - if (empty($data)) throw new ErrException('数据不存在'); - - $res = [ - 'id' => $data->id, - 'name' => $data->name, - 'avatar_id' => $data->avatar_id, - 'user_id' => $data->user_id, - 'profile' => $data->profile, - 'specialties' => $data->specialties, - ]; - - return $this->return->success('success', $res); - } - /** * 设置厨师信息 * @return array @@ -96,18 +78,18 @@ class ChefService extends BaseService public function settingChef(): array { $userId = (int)$this->request->input('user_id'); - $name = $this->request->input('name'); - $avatarId = (int)$this->request->input('avatar_id'); $profile = $this->request->input('profile'); $specialties = $this->request->input('specialties'); $info = $this->chefModel->getInfoByUserId($userId); if (!empty($info)) { - $info->name = $name; - $info->profile = $profile; - $info->specialties = $specialties; - $info->avatar_id = $avatarId; + if(!empty($profile)) + $info->profile = $profile; + if(!empty($specialties)) + $info->specialties = $specialties; + } else { + throw new ErrException('设置厨师信息失败'); } if (!$info->save()) throw new ErrException('设置厨师信息失败'); diff --git a/app/Service/Admin/User/EmployeeService.php b/app/Service/Admin/User/EmployeeService.php index bb4b886..0e50594 100644 --- a/app/Service/Admin/User/EmployeeService.php +++ b/app/Service/Admin/User/EmployeeService.php @@ -136,7 +136,7 @@ class EmployeeService extends BaseService $id = (int)$this->request->input('id'); $name = $this->request->input('chinese_name'); $account = $this->request->input('account'); - $roleId = $this->request->input('role_id', 0); + $roleId = (int)$this->request->input('role_id', 0); $info = $this->adminUserModel->getAdminInfoById($id); if (empty($info)) throw new ErrException('数据不存在'); @@ -151,6 +151,7 @@ class EmployeeService extends BaseService //写入关联表 $del = match ($info->role_id) { RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(), + RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->delete(), default => true, }; @@ -158,6 +159,7 @@ class EmployeeService extends BaseService RoleCode::DRIVER => (new DriverSequence)->insert([ 'driver_id' => $info->id, ]), + RoleCode::CHEF => $this->addChef($info->id), default => true, }; @@ -171,7 +173,7 @@ class EmployeeService extends BaseService $info->avatar = $this->request->input('avatar',0); $info->role_id = $roleId; $info->city_id = $this->request->input('city_id', 0); - $info->section_id = $this->request->input('section_id', 0); +// $info->section_id = $this->request->input('section_id', 0); if (!$info->save()) throw new ErrException('账号修改失败'); @@ -194,7 +196,13 @@ class EmployeeService extends BaseService $info->is_del = UserCode::IS_DEL; - if (!$info->save()) throw new ErrException('账号删除失败'); + $del = match ($info->role_id) { + RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->update(['is_del' => UserCode::IS_DEL]), + RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]), + default => true, + }; + + if (!$info->save() || !$del) throw new ErrException('账号删除失败'); return $this->return->success(); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index fd6ca97..b5b8a25 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -240,4 +240,21 @@ POST {{host}}/admin/site/setting_driver_sequence content-type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -driver_id=1&site_ids=1,2,3 \ No newline at end of file +driver_id=1&site_ids=1,2,3 + +### 厨师列表 +GET {{host}}/admin/chef/chef_list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 厨师详细列表 +GET {{host}}/admin/chef/chef_detail_list +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 设置厨师信息 +POST {{host}}/admin/chef/setting_chef +content-type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +user_id=3&profile=擅长煮煮煮煮&specialties=川菜 \ No newline at end of file