post =$this->request->post(); if(!in_array($this->request->action(),$this->novalidate)){ $vali = $this->validateToken(); if($vali['code']!=0){ error_show($vali['code'],$vali['message'])->send(); die(); } } } /** * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function validateToken(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; $companyNo = isset($this->post['relaComNo']) ? trim($this->post['relaComNo']) : ""; if($token==""){ return ["code"=>101,"message"=>"参数token不能为空"]; } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0) { return ["code"=>$effetc['code'],"message"=>$effetc['message']]; } $this->uid=$effetc['data']['id']??""; $this->uname=$effetc['data']['nickname']??""; $where=[]; if($companyNo!=""){ $where=["companyNo"=>$companyNo]; } $role = Db::name("user_role")->where(["uid"=>$this->uid,"is_del"=>0])->where($where)->findOrEmpty(); if(empty($role)){ return ["code"=>101,"message"=>"账户已禁用"]; } $this->roleid=$role['roleid']; $level =Db::name("role")->where(["id"=>$role['roleid']])->find(); if($role['status']==0 || $level['status']==0 ){ $this->level=''; }else{ $this->level=$level['level']>1 ?2 :($level['level']??1); } return ["code"=>0,"message"=>"验证通过"]; } }