feat:warehouseKeeper
This commit is contained in:
45
app/Controller/Admin/WarehouseKeeperController.php
Normal file
45
app/Controller/Admin/WarehouseKeeperController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\ChefRequest;
|
||||
use App\Request\Admin\WarehouseKeeperRequest;
|
||||
use App\Service\Admin\System\WarehouseService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: "admin/warehouse_keeper")]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class WarehouseKeeperController
|
||||
{
|
||||
/**
|
||||
* 厨师详细列表
|
||||
* @param WarehouseKeeperRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "warehouse_keeper_list", methods: "GET")]
|
||||
#[Scene(scene: "warehouse_keeper_list")]
|
||||
public function warehouseKeeperList(WarehouseKeeperRequest $request)
|
||||
{
|
||||
return (new WarehouseService())->warehouseList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置仓管数据
|
||||
* @param WarehouseKeeperRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "setting_warehouse_keeper", methods: "POST")]
|
||||
#[Scene(scene: "setting_warehouse_keeper")]
|
||||
public function settingWarehouseKeeper(WarehouseKeeperRequest $request)
|
||||
{
|
||||
return (new WarehouseService())->settingWarehouse();
|
||||
}
|
||||
}
|
||||
48
app/Model/WarehouseKeeper.php
Normal file
48
app/Model/WarehouseKeeper.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $kitchen_id
|
||||
* @property int $is_del
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class WarehouseKeeper extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'warehouse_keeper';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getInfoByUserId(int $userId): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('is_del',UserCode::IS_NO_DEL)->where('user_id', $userId)->first();
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class ChefRequest extends FormRequest
|
||||
'user_id' =>'required|integer|exists:chef,user_id',
|
||||
'profile' =>'sometimes',
|
||||
'specialties' =>'sometimes',
|
||||
'query_city_id' => 'sometimes|integer|exists:system_city,id',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,7 +40,9 @@ class ChefRequest extends FormRequest
|
||||
'query_chef_id'
|
||||
],
|
||||
'chef_detail_list' => [
|
||||
'chef_id',
|
||||
'limit',
|
||||
'query_city_id',
|
||||
'query_chef_name'
|
||||
],
|
||||
'setting_chef' => [
|
||||
'user_id',
|
||||
|
||||
44
app/Request/Admin/WarehouseKeeperRequest.php
Normal file
44
app/Request/Admin/WarehouseKeeperRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class WarehouseKeeperRequest 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_name' =>'sometimes|string',
|
||||
'query_city_id' =>'sometimes|integer|exists:system_city,id',
|
||||
'user_id' =>'required|integer|exists:warehouse_keeper,user_id',
|
||||
'kitchen_id' =>'integer|exists:kitchen,id',
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'warehouse_list' => [
|
||||
'limit',
|
||||
'query_city_id',
|
||||
'query_name'
|
||||
],
|
||||
'setting_warehouse' => [
|
||||
'user_id',
|
||||
'kitchen_id',
|
||||
],
|
||||
];
|
||||
}
|
||||
75
app/Service/Admin/System/WarehouseService.php
Normal file
75
app/Service/Admin/System/WarehouseService.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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\WarehouseKeeper;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class WarehouseService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var WarehouseKeeper
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly WarehouseKeeper $warehouseKeeperModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function warehouseList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$cityId = (int)$this->request->input('query_city_id');
|
||||
$name = $this->request->input('query_name');
|
||||
|
||||
$list = $this
|
||||
->warehouseKeeperModel
|
||||
->leftJoin('admin_user', 'admin_user.id', '=', 'warehouse_keeper.user_id')
|
||||
->where('admin_user.is_del',UserCode::IS_NO_DEL)
|
||||
->where('admin_user.status',UserCode::ENABLE)
|
||||
->where('admin_user.role_id',RoleCode::WAREHOUSE)
|
||||
->when(!empty($cityId), function ($query) use ($cityId) {
|
||||
$query->where('admin_user.city_id', $cityId);
|
||||
})
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('admin_user.chinese_name', 'like', "$name%");
|
||||
})
|
||||
->paginate($limit,['warehouse_keeper.id','admin_user.avatar','admin_user.chinese_name','warehouse_keeper.kitchen_id'])->toArray();
|
||||
|
||||
if (empty($list)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
return $this->return->success('success',['list' => $list]);
|
||||
}
|
||||
|
||||
public function settingWarehouse(): array
|
||||
{
|
||||
$userId = (int)$this->request->input('user_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
$info = $this->warehouseKeeperModel->getInfoByUserId($userId);
|
||||
|
||||
if (!empty($info)) {
|
||||
if(!empty($kitchenId))
|
||||
$info->kitchen_id = $kitchenId;
|
||||
} else {
|
||||
throw new ErrException('设置厨师信息失败');
|
||||
}
|
||||
if (!$info->save()) throw new ErrException('设置厨师信息失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ use App\Model\AdminRole;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Chef;
|
||||
use App\Model\DriverSequence;
|
||||
use App\Model\WarehouseKeeper;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -112,6 +113,7 @@ class EmployeeService extends BaseService
|
||||
]),
|
||||
RoleCode::CHEF =>
|
||||
$this->addChef($model->id),
|
||||
RoleCode::WAREHOUSE => $this->addWarehouseKeeper($model->id),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -126,6 +128,12 @@ class EmployeeService extends BaseService
|
||||
$chef->user_id = $id;
|
||||
return $chef->save();
|
||||
}
|
||||
public function addWarehouseKeeper($id): bool
|
||||
{
|
||||
$warehouseKeeper = new WarehouseKeeper();
|
||||
$warehouseKeeper->user_id = $id;
|
||||
return $warehouseKeeper->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
@@ -152,6 +160,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(),
|
||||
RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->delete(),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -160,6 +169,7 @@ class EmployeeService extends BaseService
|
||||
'driver_id' => $info->id,
|
||||
]),
|
||||
RoleCode::CHEF => $this->addChef($info->id),
|
||||
RoleCode::WAREHOUSE => $this->addWarehouseKeeper($info->id),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -199,6 +209,7 @@ class EmployeeService extends BaseService
|
||||
$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]),
|
||||
RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]),
|
||||
default => true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user