123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- declare (strict_types = 1);
- namespace app\cxinv\controller;
- use app\BaseController;
- use think\App;
- class Base extends BaseController
- {
- protected $noLogin=[];
- protected $uid=0;
- protected $uname="system";
- protected $roleid=0;
- protected $level=0;
- protected $token="";
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->token = $this->request->param('token','','trim');
- if (!action_in_arr($this->noLogin)){
- if($this->token=='')throw new \Exception('token不能为空',101);
- $this->Auth();
- }
- }
- /**授权token鉴定
- * @return \think\response\Json|void
- */
- public function Auth(){
- $User = \app\common\User::instance();
- $reLaNo= $this->request->param('relaComNo','','trim');
- $User->init($this->token);
- if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
- $this->uid = $User->id;
- $this->uname = $User->nickname;
- $this->level = $User->level;
- $this->roleid =1;
- if($User->level==2){
- $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
- if($this->roleid==='') throw new \Exception( '没有该公司的角色或角色已禁用',10000);
- }
- }
- public function validate($data,$rule,$message=[],$field=[]){
- try {
- parent::validate($data,$rule);
- }catch (\Exception $e){
- return $e->getMessage();
- }
- return true;
- }
- }
|