feat:chef
This commit is contained in:
@@ -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('设置厨师信息失败');
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user