LewaimaiAdminPingtaiAuth.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. use DB;
  3. use DbCriteria;
  4. use Useradmin;
  5. use Yii;
  6. /**
  7. * 这个类主要是用来处理admin平台的账号权限
  8. */
  9. class LewaimaiAdminPingtaiAuth
  10. {
  11. public static $_authIds;
  12. /**
  13. * @var array 不需要登入的 routers
  14. */
  15. public static array $noLoginRouters = [
  16. 'site/login',
  17. ];
  18. /**
  19. * @var array 不需要权限检测的 routers
  20. */
  21. public static array $noAuthCheckRouters = [
  22. 'useradmin/info', // 用户信息
  23. 'useradmin/setting', // 密码修改
  24. 'useradmin/checkpwd', // 密码修改检测
  25. ];
  26. /**
  27. * @var array 超级管理员才能有操作的 routers
  28. */
  29. public static array $superAdminRouters = [
  30. ];
  31. public static function getAuth($num = 0)
  32. {
  33. if (empty($num)) {
  34. return false;
  35. }
  36. if (is_null(self::$_authIds)) {
  37. $model = Useradmin::model()->findByPk(Yii::app()->user->_id);
  38. $authIds = DB::getScalerWithCriteria(
  39. 'role',
  40. DbCriteria::simpleCompare(['id' => $model->role_id])->setSelect('auth_ids')
  41. );
  42. self::$_authIds = $authIds ? explode(',', $authIds) : [];
  43. }
  44. if (in_array($num, self::$_authIds)) {
  45. return true;
  46. }
  47. return false;
  48. }
  49. public static function adminAuth($controller, $action)
  50. {
  51. // 跳过不需要检测的
  52. if (in_array($controller, ["site", "common"])) {
  53. return true;
  54. }
  55. $page = strtolower($controller.'/'.$action);
  56. if (in_array($page, self::$noAuthCheckRouters)) {
  57. return true;
  58. }
  59. /**
  60. * @var array $pageAuth 权限集开始检测 权限ID 和 asyncRoutes.ts 保持一致
  61. * @link ./web/src/router/routes/asyncRoutes.ts
  62. */
  63. $pageAuth = [
  64. // =================== 用户及角色管理 =======================
  65. 'useradmin/rolelist' => 110200, // 角色列表
  66. 'useradmin/saveroleauth' => 110201, // 菜单权限
  67. 'useradmin/editrole' => 110202, // 编辑角色
  68. 'useradmin/deleterole' => 110203, // 删除角色
  69. 'useradmin/userlist' => 110100, // 用户列表
  70. 'useradmin/edituser' => 110101, // 编辑用户
  71. 'useradmin/deleteuser' => 110102, // 删除用户
  72. // =================== 学校 =======================
  73. 'school/list' => 120100,
  74. 'school/info' => 120100,
  75. 'school/add' => 120101,
  76. 'school/edit' => 120102,
  77. 'school/updateattr' => 120102,
  78. 'school/delete' => 120103,
  79. // =================== 学校关系 =======================
  80. 'schoolrelation/list' => 120200,
  81. 'schoolrelation/info' => 120200,
  82. 'schoolrelation/add' => 120201,
  83. 'schoolrelation/edit' => 120202,
  84. 'schoolrelation/updateattr' => 120202,
  85. 'schoolrelation/delete' => 120203,
  86. // =================== 学校跟进 =======================
  87. 'follow/schoollist' => 120300,
  88. 'follow/schoolall' => 120300,
  89. 'follow/schoolinfo' => 120300,
  90. 'follow/schooladd' => 120301,
  91. // =================== 食堂 =======================
  92. 'canteen/list' => 130100,
  93. 'canteen/info' => 130100,
  94. 'canteen/add' => 130101,
  95. 'canteen/edit' => 130102,
  96. 'canteen/updateattr' => 130102,
  97. 'canteen/delete' => 130103,
  98. // =================== 食堂跟进 =======================
  99. 'follow/canteenlist' => 130300,
  100. 'follow/canteenall' => 130300,
  101. 'follow/canteeninfo' => 130300,
  102. 'follow/canteenadd' => 130301,
  103. // =================== 餐饮公司 =======================
  104. 'company/list' => 140100,
  105. 'company/info' => 140100,
  106. 'company/add' => 140101,
  107. 'company/edit' => 140102,
  108. 'company/updateattr' => 140102,
  109. 'company/delete' => 140103,
  110. // =================== 餐饮公司关系 =======================
  111. 'companyrelation/list' => 140200,
  112. 'companyrelation/info' => 140200,
  113. 'companyrelation/add' => 140201,
  114. 'companyrelation/edit' => 140202,
  115. 'companyrelation/updateattr' => 140202,
  116. 'companyrelation/delete' => 140203,
  117. // =================== 餐饮公司跟进 =======================
  118. 'follow/companylist' => 140300,
  119. 'follow/companyall' => 140300,
  120. 'follow/companyinfo' => 140300,
  121. 'follow/companyadd' => 140301,
  122. ];
  123. return !empty($pageAuth[$page]) && self::getAuth($pageAuth[$page]);
  124. }
  125. }