| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\BaseController;
- use app\common\model\AuthGroupAccessModel;
- use app\common\model\AuthGroupModel;
- use app\common\model\AuthRuleModel;
- use app\Request;
- use think\App;
- use think\facade\View;
- class Index extends BaseController
- {
- private $authGroupModel;
- private $authGroupAccessModel;
- private $authRuleModel;
- public function __construct(App $app)
- {
- $this->authGroupModel = new AuthGroupModel();
- $this->authGroupAccessModel = new AuthGroupAccessModel();
- $this->authRuleModel = new AuthRuleModel();
- parent::__construct($app);
- }
- private function loadRuleTreeByAdminId(int $adminId) {
- $access = $this->authGroupAccessModel->where([
- ['is_delete', '=', 0],
- ['uid','=',$adminId]
- ])->find();
- if ($access->group_id > 0) {
- $group = $this->authGroupModel->where([
- ['is_delete','=', 0],
- ['id', '=', $access->group_id]
- ])->find();
- if ($group) {
- $rules_str = $group->rules;
- if($rules_str == "*"){
- $rules = $this->authRuleModel->where('is_delete', 0)->select();
- } else {
- $rules = $this->authRuleModel->where([
- ['is_delete','=', 0],
- ['id', 'in', explode(',',$rules_str)]
- ])->select();
- }
- return $rules;
- }
- }
- return [];
- }
- public function index(Request $request)
- {
- $adminId = 10000; //$request->param(['adminId']);
- $rules = $this->loadRuleTreeByAdminId($adminId);
- View::assign('rules',recursion($rules,0));
- return view();
- }
- public function home()
- {
- return view();
- }
- }
|