LewaimaiAdminPingtaiAuth.php 5.0 KB

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