Base.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\cxinv\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. if($this->token=='')throw new \Exception('token不能为空',101);
  20. $this->Auth();
  21. }
  22. }
  23. /**授权token鉴定
  24. * @return \think\response\Json|void
  25. */
  26. public function Auth(){
  27. $User = \app\common\User::instance();
  28. $reLaNo= $this->request->param('relaComNo','','trim');
  29. $User->init($this->token);
  30. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  31. $this->uid = $User->id;
  32. $this->uname = $User->nickname;
  33. $this->level = $User->level;
  34. $this->roleid =1;
  35. if($User->level==2){
  36. $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
  37. if($this->roleid==='') throw new \Exception( '没有该公司的角色或角色已禁用',10000);
  38. }
  39. }
  40. public function validate($data,$rule,$message=[],$field=[]){
  41. try {
  42. parent::validate($data,$rule);
  43. }catch (\Exception $e){
  44. return $e->getMessage();
  45. }
  46. return true;
  47. }
  48. }