Systematic.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace systematic;
  15. use think\facade\Config;
  16. use think\facade\Cache;
  17. use think\facade\Db;
  18. /**
  19. * 系统类
  20. */
  21. class Systematic
  22. {
  23. public function auth($uid)
  24. {
  25. if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) {
  26. //用户所在权限组及所拥有的权限
  27. $groups = [];
  28. $position_id = Db::name('Admin')->where('id', $uid)->value('position_id');
  29. $groups = Db::name('PositionGroup')
  30. ->alias('a')
  31. ->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
  32. ->where([['a.pid', '=', $position_id], ['g.status', '=', 1]])
  33. ->select()->toArray();
  34. //保存用户所属用户组设置的所有权限规则id
  35. $ids = [];
  36. foreach ($groups as $g) {
  37. $ids = array_merge($ids, explode(',', trim($g['rules'], ',')));
  38. }
  39. $ids = array_unique($ids);
  40. //读取所有权限规则
  41. $rules_all = Db::name('AdminRule')->field('src')->select()->toArray();
  42. //读取用户组所有权限规则
  43. $rules = Db::name('AdminRule')->where('id', 'in', $ids)->field('src')->select()->toArray();
  44. //循环规则,判断结果。
  45. $auth_list_all = [];
  46. $auth_list = [];
  47. foreach ($rules_all as $rule_all) {
  48. $auth_list_all[] = strtolower($rule_all['src']);
  49. }
  50. foreach ($rules as $rule) {
  51. $auth_list[] = strtolower($rule['src']);
  52. }
  53. //规则列表结果保存到Cache
  54. Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000);
  55. Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000);
  56. }
  57. }
  58. //读取文件配置
  59. public function getConfig($key)
  60. {
  61. return Config::get($key);
  62. }
  63. }