diff --git a/src/plugin/admin/app/common/Auth.php b/src/plugin/admin/app/common/Auth.php index 25cff9f..4363356 100644 --- a/src/plugin/admin/app/common/Auth.php +++ b/src/plugin/admin/app/common/Auth.php @@ -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(); } /** diff --git a/src/plugin/admin/app/common/Tree.php b/src/plugin/admin/app/common/Tree.php index a8445bc..7191024 100644 --- a/src/plugin/admin/app/common/Tree.php +++ b/src/plugin/admin/app/common/Tree.php @@ -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; } }