fix:member
This commit is contained in:
20
app/Constants/Admin/MemberCode.php
Normal file
20
app/Constants/Admin/MemberCode.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Admin;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use Hyperf\Constants\Annotation\Constants;
|
||||
|
||||
#[Constants]
|
||||
class MemberCode extends AbstractConstants
|
||||
{
|
||||
/**
|
||||
* 未删除
|
||||
*/
|
||||
const int IS_NO_DEL = 1;
|
||||
|
||||
/**
|
||||
* @Message("该用户已被删除")
|
||||
*/
|
||||
const int IS_DEL = 2;
|
||||
}
|
||||
31
app/Controller/Admin/MemberController.php
Normal file
31
app/Controller/Admin/MemberController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Api\JwtAuthMiddleware;
|
||||
use App\Request\Admin\MemberRequest;
|
||||
use App\Service\Admin\User\MemberService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: 'admin/member')]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class MemberController
|
||||
{
|
||||
/**
|
||||
* @param MemberRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
public function list(MemberRequest $request): array
|
||||
{
|
||||
return (new MemberService)->handle();
|
||||
}
|
||||
}
|
||||
36
app/Request/Admin/MemberRequest.php
Normal file
36
app/Request/Admin/MemberRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class MemberRequest 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_id' =>'sometimes|integer|exists:user,id',
|
||||
'query_name' =>'sometimes|string',
|
||||
'query_mobile' =>'sometimes|digits:11',
|
||||
'query_city_id' => 'sometimes|integer|exists:system_city,id',
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'list' => ['limit','query_id','query_name','query_mobile','query_city_id'],
|
||||
];
|
||||
}
|
||||
53
app/Service/Admin/User/MemberService.php
Normal file
53
app/Service/Admin/User/MemberService.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\User;
|
||||
|
||||
use App\Constants\Admin\MemberCode;
|
||||
use App\Model\User;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class MemberService extends BaseService{
|
||||
|
||||
#[Inject]
|
||||
protected User $userModel;
|
||||
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
private array $filed = ['id','mobile','nickname','password','salt','avatar_id','gender','age','birthday','city','token','last_ip','reg_ip','last_time','create_time','update_time'];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$name = $this->request->input('query_name');
|
||||
$mobile = $this->request->input('query_mobile');
|
||||
$cityId = $this->request->input('query_city_id');
|
||||
|
||||
$list = $this->userModel
|
||||
->where('is_del',MemberCode::IS_NO_DEL)
|
||||
->when(!empty($id), function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
})
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('nickname', 'like', "$name%");
|
||||
})
|
||||
->when(!empty($mobile), function ($query) use ($mobile) {
|
||||
$query->where('mobile', $mobile);
|
||||
})
|
||||
->when(!empty($cityId), function ($query) use ($cityId) {
|
||||
$query->where('city_id', $cityId);
|
||||
})
|
||||
->paginate($limit,$this->filed)
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user