Base.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. protected $model=null;
  15. public function __construct(App $app) {
  16. parent::__construct($app);
  17. $this->token = $this->request->param('token','','trim');
  18. if (!action_in_arr($this->noLogin)){
  19. $this->Auth();
  20. }
  21. }
  22. /**授权token鉴定
  23. * @return \think\response\Json|void
  24. */
  25. public function Auth(){
  26. $User = \app\common\User::instance();
  27. $reLaNo= $this->request->param('relaComNo','','trim');
  28. $User->init($this->token);
  29. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  30. $this->uid = $User->id;
  31. $this->uname = $User->nickname;
  32. $this->level = $User->level;
  33. $this->roleid =1;
  34. if($User->level==2){
  35. $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
  36. if($this->roleid==='') throw new \Exception( '没有该公司的角色','101');
  37. }
  38. }
  39. }