Base.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\bug\controller;
  3. use app\bug\model\UserRole;use think\App;
  4. class Base extends \app\BaseController{
  5. protected $noLogin=[];
  6. protected $uid=0;
  7. protected $uname='system';
  8. protected $roleid=0;
  9. protected $level=0;
  10. protected $token='';
  11. protected $model=null;
  12. public function __construct(App $app) {
  13. parent::__construct($app);
  14. $this->token = $this->request->param('token','','trim');
  15. if (!action_in_arr($this->noLogin)){
  16. if($this->token=='')throw new \Exception('token不能为空',101);
  17. $this->Auth();
  18. }
  19. }
  20. /**授权token鉴定
  21. * @return \think\response\Json|void
  22. */
  23. public function Auth(){
  24. $User = \app\common\User::instance();
  25. $User->init($this->token);
  26. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  27. $this->uid = $User->id;
  28. $this->uname = $User->nickname;
  29. $this->level = $User->level;
  30. $this->roleid = (new UserRole())->RoleIdByUid($this->uid);
  31. if($this->roleid==0) throw new \Exception('账户未设置角色!',101);
  32. }
  33. }