118 lines
3.4 KiB
PHP
118 lines
3.4 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('chinese_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
|
|
{
|
|
$chefId = (int)$this->request->input('chef_id');
|
|
|
|
$list = $this
|
|
->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(['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()]);
|
|
}
|
|
|
|
/**
|
|
* 设置厨师信息
|
|
* @return array
|
|
*/
|
|
public function settingChef(): array
|
|
{
|
|
$userId = (int)$this->request->input('user_id');
|
|
$profile = $this->request->input('profile');
|
|
$specialties = $this->request->input('specialties');
|
|
|
|
$info = $this->chefModel->getInfoByUserId($userId);
|
|
|
|
if (!empty($info)) {
|
|
if(!empty($profile))
|
|
$info->profile = $profile;
|
|
if(!empty($specialties))
|
|
$info->specialties = $specialties;
|
|
} else {
|
|
throw new ErrException('设置厨师信息失败');
|
|
}
|
|
|
|
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();
|
|
// }
|
|
} |