mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
fix : update path And request
This commit is contained in:
81
app/Common/Repository/AdminUserRepository.php
Normal file
81
app/Common/Repository/AdminUserRepository.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Common\Repository;
|
||||
|
||||
use App\Model\AdminUser;
|
||||
use Hyperf\Collection\Arr;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
|
||||
/**
|
||||
* Class AdminUserRepository
|
||||
* @extends BaseRepository<AdminUser>
|
||||
*/
|
||||
final class AdminUserRepository extends BaseRepository
|
||||
{
|
||||
public function __construct(protected readonly AdminUser $model) {}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return AdminUser|null
|
||||
*/
|
||||
public function findByUserName(string $username): AdminUser|null
|
||||
{
|
||||
// @phpstan-ignore-next-line
|
||||
return $this->model->newQuery()
|
||||
->where('username', $username)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @param array $params
|
||||
* @return Builder
|
||||
*/
|
||||
public function handleSearch(Builder $query, array $params): Builder
|
||||
{
|
||||
return $query
|
||||
->when(Arr::get($params, 'unique_username'), static function (Builder $query, $uniqueUsername) {
|
||||
$query->where('username', $uniqueUsername);
|
||||
})
|
||||
->when(Arr::get($params, 'username'), static function (Builder $query, $username) {
|
||||
$query->where('username', 'like', '%' . $username . '%');
|
||||
})
|
||||
->when(Arr::get($params, 'phone'), static function (Builder $query, $phone) {
|
||||
$query->where('phone', $phone);
|
||||
})
|
||||
->when(Arr::get($params, 'email'), static function (Builder $query, $email) {
|
||||
$query->where('email', $email);
|
||||
})
|
||||
->when(Arr::exists($params, 'status'), static function (Builder $query) use ($params) {
|
||||
$query->where('status', Arr::get($params, 'status'));
|
||||
})
|
||||
->when(Arr::exists($params, 'user_type'), static function (Builder $query) use ($params) {
|
||||
$query->where('user_type', Arr::get($params, 'user_type'));
|
||||
})
|
||||
->when(Arr::exists($params, 'nickname'), static function (Builder $query) use ($params) {
|
||||
$query->where('nickname', 'like', '%' . Arr::get($params, 'nickname') . '%');
|
||||
})
|
||||
->when(Arr::exists($params, 'created_at'), static function (Builder $query) use ($params) {
|
||||
$query->whereBetween('created_at', [
|
||||
Arr::get($params, 'created_at')[0] . ' 00:00:00',
|
||||
Arr::get($params, 'created_at')[1] . ' 23:59:59',
|
||||
]);
|
||||
})
|
||||
->when(Arr::get($params, 'user_ids'), static function (Builder $query, $userIds) {
|
||||
$query->whereIn('id', $userIds);
|
||||
})
|
||||
->when(Arr::get($params, 'role_id'), static function (Builder $query, $roleId) {
|
||||
$query->whereHas('roles', static function (Builder $query) use ($roleId) {
|
||||
$query->where('role_id', $roleId);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user