From 2980a9dd34dfdd4248056c80f1c2056332c69cf3 Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Tue, 1 Apr 2025 16:55:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/fast/Auth.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/extend/fast/Auth.php b/extend/fast/Auth.php index 2217416..626ac91 100644 --- a/extend/fast/Auth.php +++ b/extend/fast/Auth.php @@ -263,4 +263,30 @@ class Auth return $user_info[$uid]; } + + + /** + * 根据用户id获取Api用户组,返回值为数组 + * @param int $uid 用户id + * @return array 用户所属的用户组 array( + * array('uid'=>'用户id','group_id'=>'用户组id','name'=>'用户组名称','rules'=>'用户组拥有的规则id,多个,号隔开'), + * ...) + */ + public function getApiGroups($uid) + { + static $groups = []; + if (isset($groups[$uid])) { + return $groups[$uid]; + } + + // 执行查询 + $user_groups = Db::name('api_auth_group_access') + ->alias('aga') + ->join('__' . strtoupper("api_auth_group") . '__ ag', 'aga.group_id = ag.id', 'LEFT') + ->field('aga.uid,aga.group_id,ag.id,ag.pid,ag.name,ag.rules') + ->where("aga.uid='{$uid}' and ag.status='normal'") + ->select(); + $groups[$uid] = $user_groups ?: []; + return $groups[$uid]; + } }