Base.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\BaseController;
  5. use think\App;
  6. class Base extends BaseController
  7. {
  8. protected $noLogin=[];
  9. protected $uid=0;
  10. protected $uname="system";
  11. protected $roleid=0;
  12. protected $level="0";
  13. protected $token="";
  14. public function __construct(App $app) {
  15. parent::__construct($app);
  16. $this->token = $this->request->param('token','','trim');
  17. if (!action_in_arr($this->noLogin)){
  18. $this->Auth();
  19. }
  20. }
  21. /**授权token鉴定
  22. * @return \think\response\Json|void
  23. */
  24. public function Auth(){
  25. $User = \app\common\User::instance();
  26. $reLaNo= $this->request->param('relaComNo','','trim');
  27. $User->init($this->token);
  28. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  29. $this->uid = $User->id;
  30. $this->uname = $User->nickname;
  31. $this->level = $User->level;
  32. $this->roleid =1;
  33. if($User->level==2){
  34. $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
  35. if($this->roleid==='') throw new \Exception( '没有该公司的角色','101');
  36. }
  37. }
  38. }