2025-08-05 17:19:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\admin\service;
|
|
|
|
|
|
|
|
|
|
use app\admin\validate\UserValidate;
|
|
|
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
|
|
|
use app\common\model\User;
|
|
|
|
|
use support\Request;
|
|
|
|
|
|
|
|
|
|
class UserService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use CrudServiceTrait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 指定当前要操作的模型
|
|
|
|
|
*/
|
|
|
|
|
protected string $modelClass = User::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected $validator = UserValidate::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取验证器
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator()
|
|
|
|
|
{
|
|
|
|
|
return new $this->validator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造 CrudUtil 查询配置
|
|
|
|
|
*/
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
|
|
|
|
{
|
|
|
|
|
$p = $request->all();
|
|
|
|
|
|
|
|
|
|
$config = [];
|
|
|
|
|
$config['model'] = $this->modelClass;
|
|
|
|
|
switch ($scene) {
|
|
|
|
|
case 'default':
|
|
|
|
|
$config['where']['status'] = 1;
|
|
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
|
break;
|
|
|
|
|
case 'index':
|
|
|
|
|
$config['where']['status'] = 1;
|
|
|
|
|
$config['order']['id'] = 'desc';
|
2025-08-05 17:58:10 +08:00
|
|
|
|
|
|
|
|
// 关键字
|
|
|
|
|
if (isset($p['keyword']) && $p['keyword']) {
|
|
|
|
|
$k = '%' . $p['keyword'] . '%';
|
|
|
|
|
$config['where']['name'] = ['like', $k];
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 17:19:12 +08:00
|
|
|
$config['fields'] = ['id', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'status', 'created_at'];
|
|
|
|
|
break;
|
|
|
|
|
case 'show':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
$config['where']['status'] = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'store':
|
|
|
|
|
break;
|
|
|
|
|
case 'update':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
case 'destroy':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
|
|
|
|
}
|