save
This commit is contained in:
parent
073ab4afcc
commit
5ec88341e3
@ -13,7 +13,7 @@ class Auth
|
||||
* @param array $admin_ids
|
||||
* @return array
|
||||
*/
|
||||
public static function getAdminIds(array $admin_ids = []): array
|
||||
public static function getDescendantRoleIds(array $admin_ids = []): array
|
||||
{
|
||||
if (!$admin_ids) {
|
||||
$admin = admin();
|
||||
@ -31,9 +31,18 @@ class Auth
|
||||
|
||||
$roles = Role::get();
|
||||
$tree = new Tree($roles);
|
||||
$descendants = $tree->getDescendants($role_ids, true);
|
||||
$role_ids = array_column($descendants, 'id');
|
||||
return AdminRole::whereIn('role_id', $role_ids)->pluck('admin_id')->toArray();
|
||||
$descendants = $tree->getDescendant($role_ids, true);
|
||||
return array_column($descendants, 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员及子管理员id数组
|
||||
* @param array $admin_ids
|
||||
* @return array
|
||||
*/
|
||||
public static function getDescendantAdminIds(array $admin_ids = []): array
|
||||
{
|
||||
return AdminRole::whereIn('role_id', static::getDescendantRoleIds())->pluck('admin_id')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ class Tree
|
||||
* @param bool $with_self
|
||||
* @return array
|
||||
*/
|
||||
public function getDescendants(array $include, bool $with_self = false): array
|
||||
public function getDescendant(array $include, bool $with_self = false): array
|
||||
{
|
||||
$items = [];
|
||||
foreach ($include as $id) {
|
||||
@ -58,7 +58,7 @@ class Tree
|
||||
foreach ($this->hashTree[$id]['children'] ?? [] as $item) {
|
||||
unset($item['children']);
|
||||
$items[$item['id']] = $item;
|
||||
foreach ($this->getDescendants([$item['id']]) as $it) {
|
||||
foreach ($this->getDescendant([$item['id']]) as $it) {
|
||||
$items[$it['id']] = $it;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user