feat:chef
This commit is contained in:
75
app/Controller/Admin/ChefController.php
Normal file
75
app/Controller/Admin/ChefController.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||||
|
use App\Request\Admin\ChefRequest;
|
||||||
|
use App\Service\Admin\System\ChefService;
|
||||||
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
|
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||||
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
|
#[Controller(prefix: "admin/chef")]
|
||||||
|
#[Middlewares([
|
||||||
|
JwtAuthMiddleware::class,
|
||||||
|
])]
|
||||||
|
class ChefController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 厨师列表
|
||||||
|
* @param ChefRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "chef_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "chef_list")]
|
||||||
|
public function chefList(ChefRequest $request)
|
||||||
|
{
|
||||||
|
return (new ChefService())->chefList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 厨师详细列表
|
||||||
|
* @param ChefRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "chef_detail_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "chef_detail_list")]
|
||||||
|
public function chefDetailList(ChefRequest $request)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "setting_chef", methods: "POST")]
|
||||||
|
#[Scene(scene: "setting_chef")]
|
||||||
|
public function settingChef(ChefRequest $request)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Model/Chef.php
Normal file
60
app/Model/Chef.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
use Hyperf\Database\Model\Builder;
|
||||||
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $name
|
||||||
|
* @property int $avatar_id
|
||||||
|
* @property int $user_id
|
||||||
|
* @property string $profile
|
||||||
|
* @property string $specialties
|
||||||
|
* @property int $is_del
|
||||||
|
* @property string $create_time
|
||||||
|
* @property string $update_time
|
||||||
|
*/
|
||||||
|
class Chef extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'chef';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*/
|
||||||
|
protected array $fillable = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*/
|
||||||
|
protected array $casts = ['id' => 'integer', 'avatar_id' => 'integer', 'user_id' => 'integer', 'is_del' => 'integer'];
|
||||||
|
|
||||||
|
const string CREATED_AT = 'create_time';
|
||||||
|
|
||||||
|
const string UPDATED_AT = 'update_time';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||||
|
*/
|
||||||
|
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||||
|
{
|
||||||
|
return $this->where('id', $id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $userId
|
||||||
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||||
|
*/
|
||||||
|
public function getInfoByUserId(int $userId): \Hyperf\Database\Model\Model|Builder|null
|
||||||
|
{
|
||||||
|
return $this->where('user_id', $userId)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
52
app/Request/Admin/ChefRequest.php
Normal file
52
app/Request/Admin/ChefRequest.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Request\Admin;
|
||||||
|
|
||||||
|
use Hyperf\Validation\Request\FormRequest;
|
||||||
|
|
||||||
|
class ChefRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'limit' => 'required|integer',
|
||||||
|
'query_chef_name' =>'sometimes|string',
|
||||||
|
'query_chef_id' =>'sometimes|integer|exists:admin_user,id',
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected array $scenes = [
|
||||||
|
'chef_list' => [
|
||||||
|
'limit',
|
||||||
|
'query_chef_name',
|
||||||
|
'query_chef_id'
|
||||||
|
],
|
||||||
|
'chef_detail_list' => [
|
||||||
|
'query_chef_name',
|
||||||
|
],
|
||||||
|
'chefInfo' =>['id'],
|
||||||
|
'setting_chef' => [
|
||||||
|
'name',
|
||||||
|
'avatar_id',
|
||||||
|
'user_id',
|
||||||
|
'profile',
|
||||||
|
'specialties'
|
||||||
|
],
|
||||||
|
'delete' => ['id'],
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
136
app/Service/Admin/System/ChefService.php
Normal file
136
app/Service/Admin/System/ChefService.php
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
<?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();
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ use App\Extend\StringUtil;
|
|||||||
use App\Lib\Crypto\CryptoFactory;
|
use App\Lib\Crypto\CryptoFactory;
|
||||||
use App\Model\AdminRole;
|
use App\Model\AdminRole;
|
||||||
use App\Model\AdminUser;
|
use App\Model\AdminUser;
|
||||||
|
use App\Model\Chef;
|
||||||
use App\Model\DriverSequence;
|
use App\Model\DriverSequence;
|
||||||
use App\Service\Admin\BaseService;
|
use App\Service\Admin\BaseService;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -109,6 +110,8 @@ class EmployeeService extends BaseService
|
|||||||
(new DriverSequence)->insert([
|
(new DriverSequence)->insert([
|
||||||
'driver_id' => $model->id,
|
'driver_id' => $model->id,
|
||||||
]),
|
]),
|
||||||
|
RoleCode::CHEF =>
|
||||||
|
$this->addChef($model->id),
|
||||||
default => true,
|
default => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,6 +120,13 @@ class EmployeeService extends BaseService
|
|||||||
return $this->return->success();
|
return $this->return->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addChef($id): bool
|
||||||
|
{
|
||||||
|
$chef = new Chef();
|
||||||
|
$chef->user_id = $id;
|
||||||
|
return $chef->save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
* @return array
|
* @return array
|
||||||
|
|||||||
Reference in New Issue
Block a user