51 lines
1.3 KiB
PHP
Executable File
51 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* This file is part of the youyao/admin-api.
|
|
*
|
|
* (c) youyao <info@nuancebiotech.cn>
|
|
* This source file is subject to the license under the project that is bundled.
|
|
*/
|
|
namespace App\Repository\Admin;
|
|
|
|
//use App\Constants\Status;
|
|
use App\Model\User;
|
|
use App\Model\UserRole;
|
|
use Hyperf\Utils\Collection;
|
|
|
|
class UserRepository
|
|
{
|
|
public static function getUserByIDS(array $userIds): Collection
|
|
{
|
|
// return User::query()
|
|
// ->whereIn('id', $userIds)
|
|
// ->get();
|
|
}
|
|
|
|
|
|
# 原始
|
|
// public static function getUserValidRoles2(User $user, $onlyNormal = true): Collection
|
|
// {
|
|
// return UserRole::query()
|
|
// ->join('role', 'role.id', '=', 'user_role.role_id')
|
|
// ->where('user_role.user_id', $user->id)
|
|
// ->when($onlyNormal, function ($query) {
|
|
// $query->where('role.status', 1);
|
|
// })->select(['role.*'])
|
|
// ->get();
|
|
// }
|
|
|
|
|
|
public static function getUserValidRoles(): Collection
|
|
{
|
|
return UserRole::query()
|
|
->join('role', 'role.id', '=', 'user_role.role_id')
|
|
->where('user_role.user_id', 1)
|
|
->when(true, function ($query) {
|
|
$query->where('role.status', 1);
|
|
})->select(['role.*'])
|
|
->get();
|
|
}
|
|
}
|