Index.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\BaseController;
  5. use app\common\model\AuthGroupAccessModel;
  6. use app\common\model\AuthGroupModel;
  7. use app\common\model\AuthRuleModel;
  8. use app\Request;
  9. use think\App;
  10. use think\facade\View;
  11. class Index extends BaseController
  12. {
  13. private $authGroupModel;
  14. private $authGroupAccessModel;
  15. private $authRuleModel;
  16. public function __construct(App $app)
  17. {
  18. $this->authGroupModel = new AuthGroupModel();
  19. $this->authGroupAccessModel = new AuthGroupAccessModel();
  20. $this->authRuleModel = new AuthRuleModel();
  21. parent::__construct($app);
  22. }
  23. private function loadRuleTreeByAdminId(int $adminId) {
  24. $access = $this->authGroupAccessModel->where([
  25. ['is_delete', '=', 0],
  26. ['uid','=',$adminId]
  27. ])->find();
  28. if ($access->group_id > 0) {
  29. $group = $this->authGroupModel->where([
  30. ['is_delete','=', 0],
  31. ['id', '=', $access->group_id]
  32. ])->find();
  33. if ($group) {
  34. $rules_str = $group->rules;
  35. if($rules_str == "*"){
  36. $rules = $this->authRuleModel->where('is_delete', 0)->select();
  37. } else {
  38. $rules = $this->authRuleModel->where([
  39. ['is_delete','=', 0],
  40. ['id', 'in', explode(',',$rules_str)]
  41. ])->select();
  42. }
  43. return $rules;
  44. }
  45. }
  46. return [];
  47. }
  48. public function index(Request $request)
  49. {
  50. $adminId = 10000; //$request->param(['adminId']);
  51. $rules = $this->loadRuleTreeByAdminId($adminId);
  52. View::assign('rules',recursion($rules,0));
  53. return view();
  54. }
  55. public function home()
  56. {
  57. return view();
  58. }
  59. }