Auth.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. namespace app\admin\library;
  3. use app\common\library\Redis;
  4. use app\common\model\Admin;
  5. use app\common\model\AuthGroup;
  6. use app\common\model\AuthGroupAccess;
  7. use app\main\constants\AdminConstants;
  8. use app\main\service\AdminService;
  9. use app\main\service\AppGuideService;
  10. use app\common\service\CheckIpCityService;
  11. use app\main\service\LogService;
  12. use fast\Random;
  13. use fast\Tree;
  14. use think\Config;
  15. use think\Cookie;
  16. use think\Request;
  17. use think\Session;
  18. class Auth extends \fast\Auth
  19. {
  20. //超管
  21. const GROUP_ID_SUPER_ADMIN = 1;
  22. //管理员
  23. const GROUP_ID_ADMIN = 2;
  24. //渠道
  25. const GROUP_ID_CHANNEL = 3;
  26. //代理
  27. const GROUP_ID_AGENT = 4;
  28. //客服
  29. const GROUP_ID_CUSTOMER_SERVICE = 5;
  30. //超管运营
  31. const GROUP_ID_OPERATION = 6;
  32. //VIP
  33. const GROUP_ID_VIP = 7;
  34. //VIP运营
  35. const GROUP_ID_VIP_OPERATION = 8;
  36. //渠道运营
  37. const GROUP_ID_CHANNEL_OPERATION = 9;
  38. protected $requestUri = '';
  39. protected $breadcrumb = [];
  40. protected $logined = false; //登录状态
  41. public function __construct()
  42. {
  43. parent::__construct();
  44. }
  45. public function __get($name)
  46. {
  47. /**
  48. * 渠道号处理
  49. */
  50. if ($name == 'channel_id') {
  51. if ($this->checkGroupId('3')) {
  52. return $this->channel_id = Session::get('admin.id');
  53. } elseif ($this->checkGroupId('4')) {
  54. $result = model('AdminExtend')->where(['admin_id' => Session::get('admin.id')])->find();
  55. if (isset($result['create_by'])) {
  56. return $this->channel_id = $result['create_by'];
  57. }
  58. } else {
  59. return null;
  60. }
  61. }
  62. //如果代理商可配置服务号,返回agent_id
  63. if($name == 'agent_id'){
  64. if($this->checkGroupId('4')){
  65. $row = model('AdminExtend')->where(['admin_id' => Session::get('admin.id')])->find();
  66. if($row['distribute']==1){
  67. return $this->agent_id = Session::get('admin.id');
  68. }else{
  69. return null;
  70. }
  71. }else{
  72. return null;
  73. }
  74. }
  75. return Session::get('admin.' . $name);
  76. }
  77. public function login($username, $password, $keeptime = 0)
  78. {
  79. LogService::info('adminUserLogin user_name:' . $username . ',password:' . $password);
  80. $errorMsg = '密码错误';
  81. $admin = Admin::get(['username' => $username,'status'=>'normal']);
  82. if (!$admin)
  83. {
  84. return [false,1,$errorMsg];
  85. }
  86. $is_login = AdminService::instance()->adminLogin($admin, $password);
  87. if ($is_login == 1) {
  88. $res = CheckIpCityService::instance()->checkIpCity($admin->id, $admin->username, $admin->nickname);
  89. if ($res['code'] == 0) {
  90. $is_login = false;
  91. $errorMsg = $res['msg'];
  92. } else {
  93. AdminService::instance()->insertLoginTrack($admin['id'], AdminConstants::ADMIN_LOGIN_STATUS_SUCCESS,
  94. '登录成功');
  95. }
  96. }
  97. if (!$is_login) {
  98. AdminService::instance()->insertLoginTrack($admin['id'], AdminConstants::ADMIN_LOGIN_STATUS_FAIL,
  99. $errorMsg);
  100. $admin->loginfailure++;
  101. $admin->save();
  102. return [false,$is_login,$errorMsg];
  103. }
  104. $admin->loginfailure = 0;
  105. $admin->logintime = time();
  106. //$admin->token = Random::uuid(); 多处登录 导致自动登录失效
  107. $admin->save();
  108. Session::set("admin", $admin->toArray());
  109. if ($is_login == 2) {
  110. $keeptime = 0;
  111. }
  112. $this->keeplogin($keeptime);
  113. //检查是否有需要弹出的公告dialog
  114. $id = model('Notice')->dialog($admin->id);
  115. if ($id > 0) {
  116. Session::set('notice_id', $id);
  117. }
  118. return [true,$is_login,$errorMsg];
  119. }
  120. public function loginById($id)
  121. {
  122. $admin = Admin::get($id);
  123. if (!$admin)
  124. {
  125. return false;
  126. }
  127. $admin->loginfailure = 0;
  128. $admin->logintime = time();
  129. //$admin->token = Random::uuid(); 多处登录 导致自动登录失效
  130. $admin->save();
  131. Session::set("admin", $admin->toArray());
  132. //检查是否有需要弹出的公告dialog
  133. $id = model('Notice')->dialog($admin->id);
  134. if ($id > 0) {
  135. Session::set('notice_id', $id);
  136. }
  137. return $admin;
  138. }
  139. /**
  140. * 切换账号(多账号切换)
  141. * @param $username
  142. * @param $password
  143. * @param int $keeptime
  144. * @return bool
  145. */
  146. public function switchlogin($username, $password,$keeptime = 0)
  147. {
  148. $admin = Admin::get(['username' => $username,'status'=>'normal']);
  149. if (!$admin)
  150. {
  151. return false;
  152. }
  153. if ($password != $admin->password)
  154. {
  155. $admin->loginfailure++;
  156. $admin->save();
  157. return false;
  158. }
  159. $res = CheckIpCityService::instance()->checkIpCity($admin->id, $admin->username, $admin->nickname);
  160. if ($res['code'] == 0){
  161. return 0;
  162. }
  163. $admin->loginfailure = 0;
  164. $admin->logintime = time();
  165. //$admin->token = Random::uuid();
  166. $admin->save();
  167. Session::set("admin", $admin->toArray());
  168. AdminService::instance()->setAdminSessionId($admin->id);
  169. $this->keeplogin($keeptime);
  170. //检查是否有需要弹出的公告dialog
  171. $id = model('Notice')->dialog($admin->id);
  172. if ($id > 0) {
  173. Session::set('notice_id', $id);
  174. }
  175. return true;
  176. }
  177. /**
  178. * 注销登录
  179. */
  180. public function logout()
  181. {
  182. $admin = Admin::get(intval($this->id));
  183. if (!$admin)
  184. {
  185. return true;
  186. }
  187. //$admin->token = '';
  188. $admin->save();
  189. $admin = Session::get("admin");
  190. Session::delete("admin");
  191. Session::delete("notice_id");
  192. Redis::instance()->hDel("SESSION_LIST:" . $admin['id'], session_id());
  193. Session::regenerate();
  194. Cookie::delete('keeplogin');
  195. return true;
  196. }
  197. /**
  198. * 自动登录
  199. * @return boolean
  200. */
  201. public function autologin()
  202. {
  203. $keeplogin = Cookie::get('keeplogin');
  204. if (!$keeplogin)
  205. {
  206. return false;
  207. }
  208. list($id, $keeptime, $expiretime, $key) = explode('|', $keeplogin);
  209. if ($id && $keeptime && $expiretime && $key && $expiretime > time())
  210. {
  211. $admin = Admin::get($id);
  212. //if (!$admin || !$admin->token)
  213. if (!$admin)
  214. {
  215. return false;
  216. }
  217. //token有变更
  218. if ($key != md5(md5($id) . md5($keeptime) . md5($expiretime) . $admin->token))
  219. {
  220. return false;
  221. }
  222. $res = CheckIpCityService::instance()->checkIpCity($admin->id, $admin->username, $admin->nickname);
  223. if ($res['code'] == 0){
  224. return 0;
  225. }
  226. Session::set("admin", $admin->toArray());
  227. //刷新自动登录的时效
  228. $this->keeplogin($keeptime);
  229. //检查是否有需要弹出的公告dialog
  230. $id = model('Notice')->dialog($admin->id);
  231. if ($id > 0) {
  232. Session::set('notice_id', $id);
  233. }
  234. AdminService::instance()->insertLoginTrack($admin['id'], AdminConstants::ADMIN_LOGIN_STATUS_SUCCESS, '登录成功',
  235. AdminConstants::ADMIN_LOGIN_FROM_COOKIE);
  236. return true;
  237. } else {
  238. return false;
  239. }
  240. }
  241. /**
  242. * 刷新保持登录的Cookie
  243. * @param int $keeptime
  244. * @return boolean
  245. */
  246. public function keeplogin($keeptime = 0)
  247. {
  248. if ($keeptime)
  249. {
  250. $expiretime = time() + $keeptime;
  251. $key = md5(md5($this->id) . md5($keeptime) . md5($expiretime) . $this->token);
  252. $data = [$this->id, $keeptime, $expiretime, $key];
  253. Cookie::set('keeplogin', implode('|', $data), $keeptime);
  254. return true;
  255. }
  256. return false;
  257. }
  258. /**
  259. * vip进入渠道商账号的密码加密算法
  260. * @param $vipPwd vip账号密码
  261. * @param $channelPwd 渠道商账号密码
  262. * @return string
  263. */
  264. public function getVipQdsKey($vipPwd, $channelPwd, $time)
  265. {
  266. $key = md5($vipPwd . $channelPwd . $time . 'HYJoF1lbB9Eu2HXv');
  267. return $key;
  268. }
  269. public function check($name, $uid = '', $relation = 'or', $mode = 'url')
  270. {
  271. return parent::check($name, $this->id, $relation, $mode);
  272. }
  273. /**
  274. * 检测当前控制器和方法是否匹配传递的数组
  275. *
  276. * @param array $arr 需要验证权限的数组
  277. */
  278. public function match($arr = [])
  279. {
  280. $request = Request::instance();
  281. $arr = is_array($arr) ? $arr : explode(',', $arr);
  282. if (!$arr)
  283. {
  284. return FALSE;
  285. }
  286. // 是否存在
  287. if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr))
  288. {
  289. return TRUE;
  290. }
  291. // 没找到匹配
  292. return FALSE;
  293. }
  294. /**
  295. * 检测是否登录
  296. *
  297. * @return boolean
  298. */
  299. public function isLogin()
  300. {
  301. if ($this->logined)
  302. {
  303. return true;
  304. }
  305. $admin = Session::get('admin');
  306. if (!$admin)
  307. {
  308. return false;
  309. }
  310. if ($admin['status'] != 'normal') {
  311. return false;
  312. }
  313. //判断是否同一时间同一账号只能在一个地方登录
  314. // if (Config::get('fastadmin.login_unique'))
  315. // {
  316. $my = Admin::get($admin['id']);
  317. if (!$my || $my->token != $admin['token'] || $my->status != 'normal' )
  318. {
  319. return false;
  320. }
  321. // }
  322. $this->logined = true;
  323. return true;
  324. }
  325. /**
  326. * 获取当前请求的URI
  327. * @return string
  328. */
  329. public function getRequestUri()
  330. {
  331. return $this->requestUri;
  332. }
  333. /**
  334. * 设置当前请求的URI
  335. * @param string $uri
  336. */
  337. public function setRequestUri($uri)
  338. {
  339. $this->requestUri = $uri;
  340. }
  341. public function getGroups($uid = null)
  342. {
  343. $uid = is_null($uid) ? $this->id : $uid;
  344. return parent::getGroups($uid);
  345. }
  346. public function getRuleList($uid = null)
  347. {
  348. $uid = is_null($uid) ? $this->id : $uid;
  349. return parent::getRuleList($uid);
  350. }
  351. public function getUserInfo($uid = null)
  352. {
  353. $uid = is_null($uid) ? $this->id : $uid;
  354. return $uid != $this->id ? Admin::get(intval($uid)) : Session::get('admin');
  355. }
  356. public function getRuleIds($uid = null)
  357. {
  358. $uid = is_null($uid) ? $this->id : $uid;
  359. return parent::getRuleIds($uid);
  360. }
  361. public function isSuperAdminManager(){
  362. return $this->id == AdminConstants::ADMIN_SUPER_MANAGER_ID;
  363. }
  364. public function isSuperAdmin()
  365. {
  366. return $this->checkGroupId(1);
  367. }
  368. /**
  369. * 根据组ID,取出当前组下面所有节点
  370. * @param int $group_id 分组ID
  371. * @param boolean $withself 是否包含当前所在的分组
  372. * @return array
  373. * @throws \think\exception\DbException
  374. */
  375. public function getChildByGroupId($group_id,$withself = false)
  376. {
  377. $group_pid = AuthGroup::where('id',$group_id)->value('pid');
  378. // 取出所有分组
  379. $groupList = model('AuthGroup')->all(['status' => 'normal']);
  380. $objList = [];
  381. // 取出包含自己的所有子节点
  382. $childrenList = Tree::instance()->init($groupList)->getChildren($group_id, true);
  383. $obj = Tree::instance()->init($childrenList)->getTreeArray($group_pid);
  384. $objList = array_merge($objList, Tree::instance()->getTreeList($obj));
  385. $childrenGroupIds = [];
  386. foreach ($objList as $k => $v)
  387. {
  388. $childrenGroupIds[] = $v['id'];
  389. }
  390. if (!$withself)
  391. {
  392. $childrenGroupIds = array_diff($childrenGroupIds, [$group_id]);
  393. }
  394. return $childrenGroupIds;
  395. }
  396. /**
  397. * 获取管理员所属于的分组ID
  398. * @param int $uid
  399. * @return array
  400. */
  401. public function getGroupIds($uid = null)
  402. {
  403. $groups = $this->getGroups($uid);
  404. $groupIds = [];
  405. foreach ($groups as $K => $v)
  406. {
  407. $groupIds[] = (int) $v['group_id'];
  408. }
  409. return $groupIds;
  410. }
  411. /**
  412. * 取出当前管理员所拥有权限的分组
  413. * @param boolean $withself 是否包含当前所在的分组
  414. * @return array
  415. */
  416. public function getChildrenGroupIds($withself = false)
  417. {
  418. //取出当前管理员所有的分组
  419. $groups = $this->getGroups();
  420. $groupIds = [];
  421. foreach ($groups as $k => $v)
  422. {
  423. $groupIds[] = $v['id'];
  424. }
  425. // 取出所有分组
  426. $groupList = model('AuthGroup')->all(['status' => 'normal']);
  427. $objList = [];
  428. foreach ($groups as $K => $v)
  429. {
  430. if ($v['rules'] === '*')
  431. {
  432. $objList = $groupList;
  433. break;
  434. }
  435. // 取出包含自己的所有子节点
  436. $childrenList = Tree::instance()->init($groupList)->getChildren($v['id'], true);
  437. $obj = Tree::instance()->init($childrenList)->getTreeArray($v['pid']);
  438. $objList = array_merge($objList, Tree::instance()->getTreeList($obj));
  439. }
  440. $childrenGroupIds = [];
  441. foreach ($objList as $k => $v)
  442. {
  443. $childrenGroupIds[] = $v['id'];
  444. }
  445. if (!$withself)
  446. {
  447. $childrenGroupIds = array_diff($childrenGroupIds, $groupIds);
  448. }
  449. return $childrenGroupIds;
  450. }
  451. /**
  452. * 取出当前管理员所拥有权限的管理员
  453. * @param boolean $withself 是否包含自身
  454. * @return array
  455. */
  456. public function getChildrenAdminIds($withself = false)
  457. {
  458. $childrenAdminIds = [];
  459. if (!$this->isSuperAdmin())
  460. {
  461. $groupIds = $this->getChildrenGroupIds(false);
  462. $authGroupList = model('AuthGroupAccess')
  463. ->field('uid,group_id')
  464. ->where('group_id', 'in', $groupIds)
  465. ->select();
  466. foreach ($authGroupList as $k => $v)
  467. {
  468. $childrenAdminIds[] = $v['uid'];
  469. }
  470. }
  471. else
  472. {
  473. //超级管理员拥有所有人的权限
  474. $childrenAdminIds = Admin::column('id');
  475. }
  476. if ($withself)
  477. {
  478. if (!in_array($this->id, $childrenAdminIds))
  479. {
  480. $childrenAdminIds[] = $this->id;
  481. }
  482. }
  483. else
  484. {
  485. $childrenAdminIds = array_diff($childrenAdminIds, [$this->id]);
  486. }
  487. return $childrenAdminIds;
  488. }
  489. /**
  490. * 获得面包屑导航
  491. * @param string $path
  492. * @return array
  493. */
  494. public function getBreadCrumb($path = '')
  495. {
  496. if ($this->breadcrumb || !$path)
  497. return $this->breadcrumb;
  498. $path_rule_id = 0;
  499. foreach ($this->rules as $rule)
  500. {
  501. $path_rule_id = $rule['name'] == $path ? $rule['id'] : $path_rule_id;
  502. }
  503. if ($path_rule_id)
  504. {
  505. $this->breadcrumb = Tree::instance()->init($this->rules)->getParents($path_rule_id, true);
  506. foreach ($this->breadcrumb as $k => &$v)
  507. {
  508. $v['url'] = url($v['name']);
  509. $v['title'] = __($v['title']);
  510. }
  511. }
  512. return $this->breadcrumb;
  513. }
  514. /**
  515. * 获取左侧菜单栏
  516. *
  517. * @param array $params URL对应的badge数据
  518. * @return string
  519. */
  520. public function getSidebar($params = [], $fixedPage = 'notice')
  521. {
  522. $colorArr = ['red', 'green', 'yellow', 'blue', 'teal', 'orange', 'purple'];
  523. $colorNums = count($colorArr);
  524. $badgeList = [];
  525. $module = request()->module();
  526. // 生成菜单的badge
  527. foreach ($params as $k => $v)
  528. {
  529. $url = $k;
  530. if (is_array($v))
  531. {
  532. $nums = isset($v[0]) ? $v[0] : 0;
  533. $color = isset($v[1]) ? $v[1] : $colorArr[(is_numeric($nums) ? $nums : strlen($nums)) % $colorNums];
  534. $class = isset($v[2]) ? $v[2] : 'label';
  535. }
  536. else
  537. {
  538. $nums = $v;
  539. $color = $colorArr[(is_numeric($nums) ? $nums : strlen($nums)) % $colorNums];
  540. $class = 'label';
  541. }
  542. //必须nums大于0才显示
  543. if ($nums)
  544. {
  545. $badgeList[$url] = '<small class="' . $class . ' pull-right bg-' . $color . '">' . $nums . '</small>';
  546. }
  547. }
  548. // 读取管理员当前拥有的权限节点
  549. $userRule = $this->getRuleList();
  550. $select_id = 0;
  551. $pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
  552. // 必须将结果集转换为数组
  553. $ruleList = collection(model('AuthRule')->where('ismenu', 1)->order('weigh', 'desc')->cache("__menu__")->select())->toArray();
  554. $reward_state = 1;
  555. $distribute = 1;
  556. if($this->getGroupIds()[0] == 4 || $this->getGroupIds()[0] == 3){
  557. $extend = model('admin_extend')->field('reward_state,distribute')->where('admin_id',$this->id)->find();
  558. if($extend){
  559. $reward_state = $extend->reward_state;
  560. if($this->getGroupIds()[0] == 4){
  561. $distribute = $extend->distribute;
  562. }
  563. }
  564. }
  565. $isVipLimit = 0;
  566. if($this->getGroupIds()[0] == 7 || $this->getGroupIds()[0] == 8){
  567. $isVipLimit = 1;
  568. }
  569. foreach ($ruleList as $k => &$v)
  570. {
  571. if (!in_array($v['name'], $userRule))
  572. {
  573. unset($ruleList[$k]);
  574. continue;
  575. }
  576. $select_id = $v['name'] == $fixedPage ? $v['id'] : $select_id;
  577. $v['url'] = '/' . $module . '/' . $v['name'];
  578. $v['badge'] = isset($badgeList[$v['name']]) ? $badgeList[$v['name']] : '';
  579. $v['py'] = $pinyin->abbr($v['title'], '');
  580. $v['pinyin'] = $pinyin->permalink($v['title'], '');
  581. $v['title'] = __($v['title']);
  582. if ($v['url'] == '/admin/general/config/giveshubi') {
  583. if (in_array($this->id, [7370])) {
  584. unset($ruleList[$k]);
  585. }
  586. }
  587. //特殊菜单 判断渠道是否设置
  588. if (isset($v['is_special']) && $v['is_special']) {
  589. if (!AdminService::instance()->channelSpecialMenuConfig($this->id, $v['id'])) {
  590. unset($ruleList[$k]);
  591. }
  592. }
  593. if($reward_state == 0 && $v['title'] =='赏金管理'){ //如果是代理商赏金管理未激活则不显示赏金管理菜单 modified by licc 2018/5/15
  594. unset($ruleList[$k]);
  595. }
  596. if (in_array($this->getGroupIds()[0], [
  597. AdminConstants::ADMIN_GROUP_ID_VIP,
  598. AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR
  599. ]) && $v['title'] == '用户管理') {
  600. $v['title'] = "客服管理";
  601. }
  602. //隐藏切换账号
  603. if ($v['title']=='多账号切换') {
  604. unset($ruleList[$k]);
  605. }
  606. if($distribute==0 && ($v['title']=='微信管理' || $v['title']=='用户管理' || $v['title']=='用户统计' || $v['title']=='智能推送' || $v['title']=='客服消息' || $v['title']=='客服消息管理' || $v['title']=='模板消息')){ //如果是代理商配置服务号未打开不显示某些菜单
  607. unset($ruleList[$k]);
  608. }
  609. if ($distribute == 0 && $v['title'] == '页面模板') { //如果是代理商配号未激活则不显示页面模板菜单 modified by lichong 2018/5/24
  610. unset($ruleList[$k]);
  611. }
  612. if($distribute == 0 && $v['title'] == 'VIP充值管理'){
  613. unset($ruleList[$k]);
  614. }
  615. if($distribute == 0 && $v['title']=='自定义二维码'){
  616. unset($ruleList[$k]);
  617. }
  618. if($distribute == 0 && $v['title']=='推广书单'){
  619. unset($ruleList[$k]);
  620. }
  621. if($distribute == 0 && $v['title']=='运营者推广书单'){
  622. unset($ruleList[$k]);
  623. }
  624. if ($distribute == 0 && ($v['title'] == '图文客服消息管理' || $v['title'] == '文字客服消息管理' || $v['title'] == '图文客服消息数据统计' || $v['title'] == '文字客服消息数据统计')) {
  625. unset($ruleList[$k]);
  626. }
  627. if ($isVipLimit == 1 && $v['title'] == '推广链接') {
  628. unset($ruleList[$k]);
  629. }
  630. if (in_array($this->getGroupIds()[0], [3, 4, 7, 8]) && $v['name'] == 'guideappcollect') {
  631. if (!AppGuideService::instance()->isShowAdminMenu($this->id)) {
  632. unset($ruleList[$k]);
  633. }
  634. }
  635. }
  636. // 构造菜单数据
  637. Tree::instance()->init($ruleList);
  638. $menu = Tree::instance()->getTreeMenu(0, '<li class="@class"><a href="@url@addtabs" addtabs="@id" url="@url" py="@py" pinyin="@pinyin"><i class="@icon"></i> <span>@title</span> <span class="pull-right-container">@caret @badge</span></a> @childlist</li>', $select_id, '', 'ul', 'class="treeview-menu"');
  639. return $menu;
  640. }
  641. /**
  642. * 检查管理员是否所属某分组
  643. * @param int|array $group_id
  644. * @param int $uid
  645. * @return bool
  646. */
  647. public function checkGroupId($group_id, $uid = null)
  648. {
  649. $groups = $this->getGroups($uid);
  650. foreach ($groups as $K => $v) {
  651. if (is_array($group_id)) {
  652. if (in_array($v['group_id'], $group_id)) {
  653. return true;
  654. }
  655. } elseif ($v['group_id'] == $group_id) {
  656. return true;
  657. }
  658. }
  659. return false;
  660. }
  661. }