feat:chef

This commit is contained in:
LAPTOP-7SGDREK0\shiweijun
2025-01-08 17:52:29 +08:00
parent ce9d16eeda
commit 804d65b725
6 changed files with 67 additions and 68 deletions

View File

@@ -42,13 +42,6 @@ class ChefController
return (new ChefService())->chefDetailList(); 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 * @param ChefRequest $request
@@ -61,15 +54,15 @@ class ChefController
return (new ChefService)->settingChef(); return (new ChefService)->settingChef();
} }
/** // /**
* 删除厨师数据 // * 删除厨师数据
* @param ChefRequest $request // * @param ChefRequest $request
* @return array // * @return array
*/ // */
#[RequestMapping(path: "delete", methods: "GET")] // #[RequestMapping(path: "delete", methods: "GET")]
#[Scene(scene: "delete")] // #[Scene(scene: "delete")]
public function delete(chefRequest $request) // public function delete(chefRequest $request)
{ // {
return (new chefService)->delete(); // return (new chefService)->delete();
} // }
} }

View File

@@ -4,13 +4,12 @@ declare(strict_types=1);
namespace App\Model; namespace App\Model;
use App\Constants\Admin\UserCode;
use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\Builder;
use Hyperf\DbConnection\Model\Model; use Hyperf\DbConnection\Model\Model;
/** /**
* @property int $id * @property int $id
* @property string $name
* @property int $avatar_id
* @property int $user_id * @property int $user_id
* @property string $profile * @property string $profile
* @property string $specialties * @property string $specialties
@@ -33,7 +32,7 @@ class Chef extends Model
/** /**
* The attributes that should be cast to native types. * 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'; 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 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();
} }
} }

View File

@@ -25,7 +25,10 @@ class ChefRequest extends FormRequest
'limit' => 'required|integer', 'limit' => 'required|integer',
'query_chef_name' =>'sometimes|string', 'query_chef_name' =>'sometimes|string',
'query_chef_id' =>'sometimes|integer|exists:admin_user,id', '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' 'query_chef_id'
], ],
'chef_detail_list' => [ 'chef_detail_list' => [
'query_chef_name', 'chef_id',
], ],
'chefInfo' =>['id'],
'setting_chef' => [ 'setting_chef' => [
'name',
'avatar_id',
'user_id', 'user_id',
'profile', 'profile',
'specialties' 'specialties'
], ],
'delete' => ['id'], // 'delete' => ['id'],
]; ];
} }

View File

@@ -41,7 +41,7 @@ class ChefService extends BaseService
->where('status',UserCode::ENABLE) ->where('status',UserCode::ENABLE)
->where('role_id',RoleCode::CHEF) ->where('role_id',RoleCode::CHEF)
->when(!empty($name), function ($query) use ($name) { ->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) { ->when($id = $this->request->input('query_chef_id'), function ($query) use ($id) {
$query->where('id', $id); $query->where('id', $id);
@@ -53,42 +53,24 @@ class ChefService extends BaseService
public function chefDetailList(): array public function chefDetailList(): array
{ {
$name = $this->request->input('query_chef_name'); $chefId = (int)$this->request->input('chef_id');
$list = $this $list = $this
->chefModel ->adminUserModel
->where('is_del',UserCode::IS_NO_DEL) ->leftJoin('chef', 'admin_user.id', '=', 'chef.user_id')
->when(!empty($name), function ($query) use ($name) { ->where('admin_user.is_del',UserCode::IS_NO_DEL)
$query->where('name', 'like', "%{$name}%"); ->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' => []]); if (empty($list)) return $this->return->success('success',['list' => []]);
return $this->return->success('success',['list' => $list->toArray()]); 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 * @return array
@@ -96,18 +78,18 @@ class ChefService extends BaseService
public function settingChef(): array public function settingChef(): array
{ {
$userId = (int)$this->request->input('user_id'); $userId = (int)$this->request->input('user_id');
$name = $this->request->input('name');
$avatarId = (int)$this->request->input('avatar_id');
$profile = $this->request->input('profile'); $profile = $this->request->input('profile');
$specialties = $this->request->input('specialties'); $specialties = $this->request->input('specialties');
$info = $this->chefModel->getInfoByUserId($userId); $info = $this->chefModel->getInfoByUserId($userId);
if (!empty($info)) { if (!empty($info)) {
$info->name = $name; if(!empty($profile))
$info->profile = $profile; $info->profile = $profile;
$info->specialties = $specialties; if(!empty($specialties))
$info->avatar_id = $avatarId; $info->specialties = $specialties;
} else {
throw new ErrException('设置厨师信息失败');
} }
if (!$info->save()) throw new ErrException('设置厨师信息失败'); if (!$info->save()) throw new ErrException('设置厨师信息失败');

View File

@@ -136,7 +136,7 @@ class EmployeeService extends BaseService
$id = (int)$this->request->input('id'); $id = (int)$this->request->input('id');
$name = $this->request->input('chinese_name'); $name = $this->request->input('chinese_name');
$account = $this->request->input('account'); $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); $info = $this->adminUserModel->getAdminInfoById($id);
if (empty($info)) throw new ErrException('数据不存在'); if (empty($info)) throw new ErrException('数据不存在');
@@ -151,6 +151,7 @@ class EmployeeService extends BaseService
//写入关联表 //写入关联表
$del = match ($info->role_id) { $del = match ($info->role_id) {
RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(), RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(),
RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->delete(),
default => true, default => true,
}; };
@@ -158,6 +159,7 @@ class EmployeeService extends BaseService
RoleCode::DRIVER => (new DriverSequence)->insert([ RoleCode::DRIVER => (new DriverSequence)->insert([
'driver_id' => $info->id, 'driver_id' => $info->id,
]), ]),
RoleCode::CHEF => $this->addChef($info->id),
default => true, default => true,
}; };
@@ -171,7 +173,7 @@ class EmployeeService extends BaseService
$info->avatar = $this->request->input('avatar',0); $info->avatar = $this->request->input('avatar',0);
$info->role_id = $roleId; $info->role_id = $roleId;
$info->city_id = $this->request->input('city_id', 0); $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('账号修改失败'); if (!$info->save()) throw new ErrException('账号修改失败');
@@ -194,7 +196,13 @@ class EmployeeService extends BaseService
$info->is_del = UserCode::IS_DEL; $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(); return $this->return->success();
} }

View File

@@ -240,4 +240,21 @@ POST {{host}}/admin/site/setting_driver_sequence
content-type: application/x-www-form-urlencoded content-type: application/x-www-form-urlencoded
Authorization: Bearer {{admin_token}} Authorization: Bearer {{admin_token}}
driver_id=1&site_ids=1,2,3 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=川菜