Base.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use app\index\model\RoleModel;
  5. class Base extends Controller{
  6. private $noCheck = ['cabinet/check_fcode' , 'cabinet/record_store' , 'cabinet/record_fetch' , 'cabinet/add_cabinet' , 'order/order_bind_code'];
  7. public function initialize(){
  8. $control = lcfirst(request()->controller());
  9. $action = lcfirst(request()->action());
  10. $checkUrl = $control . '/' . $action;
  11. // if(!in_array($checkUrl , $this->noCheck)){
  12. // if(empty(session('username')) || empty(session('id'))){
  13. // //登录超时
  14. // json(json_error_exception('1005'))->send();
  15. // }
  16. // $this->cacheCheck();
  17. // // 检测权限
  18. // if(empty(authCheck($checkUrl))){
  19. // json(json_error_exception('1000'))->send();
  20. // }
  21. // }
  22. }
  23. private function cacheCheck()
  24. {
  25. $action = cache(session('role_id'));
  26. if(is_null($action) || empty($action)){
  27. // 获取该管理员的角色信息
  28. $roleModel = new RoleModel();
  29. $info = $roleModel->getRoleInfo(session('role_id'));
  30. cache(session('role_id'), $info['action']);
  31. }
  32. }
  33. protected function removeRoleCache()
  34. {
  35. $roleModel = new RoleModel();
  36. $roleList = $roleModel->getRole();
  37. foreach ($roleList as $value) {
  38. cache($value['id'], null);
  39. }
  40. }
  41. }