diff --git a/src/plugin/admin/app/common/Auth.php b/src/plugin/admin/app/common/Auth.php new file mode 100644 index 0000000..25cff9f --- /dev/null +++ b/src/plugin/admin/app/common/Auth.php @@ -0,0 +1,58 @@ +pluck('rules')->toArray(); + if ($rules && in_array('*', $rules)) { + return Admin::pluck('id')->toArray(); + } + } else { + $role_ids = AdminRole::whereIn('admin_id', $admin_ids)->pluck('role_id'); + } + + $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(); + } + + /** + * 是否是超级管理员 + * @param int $admin_id + * @return bool + */ + public static function isSupperAdmin(int $admin_id = 0): bool + { + if (!$admin_id) { + $roles = admin('roles'); + if (!$roles) { + return false; + } + } else { + $roles = AdminRole::where('admin_id', $admin_id)->pluck('role_id'); + } + $rules = Role::whereIn('id', $roles)->pluck('rules'); + return $rules && in_array('*', $rules->toArray()); + } + +} \ No newline at end of file