136 lines
3.8 KiB
PHP
136 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\System;
|
|
|
|
use App\Constants\Admin\UserCode;
|
|
use App\Constants\Common\RoleCode;
|
|
use App\Exception\ErrException;
|
|
use App\Model\AdminUser;
|
|
use App\Model\Chef;
|
|
use App\Service\Admin\BaseService;
|
|
use Exception;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class ChefService extends BaseService
|
|
{
|
|
|
|
public function handle()
|
|
{
|
|
//todo Write logic
|
|
}
|
|
|
|
/**
|
|
* @var AdminUser
|
|
*/
|
|
#[Inject]
|
|
protected readonly AdminUser $adminUserModel;
|
|
|
|
#[Inject]
|
|
protected readonly Chef $chefModel;
|
|
|
|
public function chefList(): array
|
|
{
|
|
$limit = (int)$this->request->input('limit', 10);
|
|
$name = $this->request->input('query_chef_name');
|
|
|
|
$list = $this
|
|
->adminUserModel
|
|
->where('is_del',UserCode::IS_NO_DEL)
|
|
->where('status',UserCode::ENABLE)
|
|
->where('role_id',RoleCode::CHEF)
|
|
->when(!empty($name), function ($query) use ($name) {
|
|
$query->where('name', 'like', "%{$name}%");
|
|
})
|
|
->when($id = $this->request->input('query_chef_id'), function ($query) use ($id) {
|
|
$query->where('id', $id);
|
|
})
|
|
->paginate($limit,['chinese_name','id','mobile','status'])->toArray();
|
|
|
|
return $this->return->success('success',$list);
|
|
}
|
|
|
|
public function chefDetailList(): array
|
|
{
|
|
$name = $this->request->input('query_chef_name');
|
|
$list = $this
|
|
->chefModel
|
|
->where('is_del',UserCode::IS_NO_DEL)
|
|
->when(!empty($name), function ($query) use ($name) {
|
|
$query->where('name', 'like', "%{$name}%");
|
|
})
|
|
->get(['id','name','avatar_id','user_id','profile','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
|
|
*/
|
|
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 (!$info->save()) throw new ErrException('设置厨师信息失败');
|
|
|
|
return $this->return->success();
|
|
}
|
|
|
|
// /**
|
|
// * 删除厨师
|
|
// * @return array
|
|
// * @throws Exception
|
|
// */
|
|
// public function delete(): array
|
|
// {
|
|
// $id = (int)$this->request->input('id');
|
|
//
|
|
// $info = $this->chefModel->getInfoById($id);
|
|
// if (empty($info)) throw new ErrException('数据不存在');
|
|
//
|
|
// $info->is_del = UserCode::IS_DEL;
|
|
//
|
|
// if (!$info->save()) throw new ErrException('删除失败');
|
|
//
|
|
// return $this->return->success();
|
|
// }
|
|
} |