post=$this->request->param(); if(!in_array($this->request->pathinfo(),$this->novalidate)&&!in_array('*', $this->novalidate)){ $this->validateToken($this->request->param()); } } /** * @param string $message * @param int $code * @param null $data */ public function error($message='',$code=1003,$data=null){ $this->result($message,$data,$code); } /** * @param string $msg * @param null $data * @param int $code * @param string|null $type * @param array $header * @param array $options */ private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array $options = []) { $result = [ 'code' => $code, 'message' => $msg, 'data' => $data, ]; $code = 200; if (isset($header['statuscode'])) { $code = $header['statuscode']; unset($header['statuscode']); } $response = Response::create($result, $type, $code)->header($header)->options($options); throw new HttpResponseException($response); } /** * @param string $message * @param int $code * @param null $data */ public function success($message='',$data=null,$code=0){ $this->result($message,$data,$code); } /** * @param $request 校验用户信息 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function validateToken($request){ $token = $request['token']?? ''; $companyNo = $request['relaComNo'] ?? ''; if($token=='') $this->error('参数token不能为空',101); $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0)$this->error($effetc['message'],$effetc['code']); $this->uid=$effetc['data']['id']??''; $this->uname=$effetc['data']['nickname']??''; $where=[]; if($companyNo!=''){ $where=['companyNo'=>$companyNo]; } $userrole = \app\admin\model\UserRole::where(['uid'=>$this->uid,'is_del'=>0])->where($where) ->findOrEmpty(); if($userrole->isEmpty()){ $this->error("账户已禁用",101); } $this->roleid=$userrole->roleid; $role =\app\admin\model\Role::where(['id'=>$userrole->roleid])->findOrEmpty(); if($role->status==0 || $userrole->status==0 ){ $this->level=0; }else $this->level = $effetc['data']['level']; } //供应商公司存在操作账户,请用供应商账户操作 public function NoAction(){ $pathinfo =$this->request->pathinfo(); $relaComNo =$this->request->param('relaComNo'); if (in_array($this->level, [2, 3])) { if (in_array($pathinfo, $this->supperAction) && $this->level == 2) { if ($relaComNo == '') $this->error('关联公司不能为空'); $companyinfo = UserHandle('/hqInfo', ['code' => $relaComNo]); if ($companyinfo['code'] != 0)$this->error($companyinfo['message'],$companyinfo['code']); if (!empty($companyinfo['data']) && $companyinfo['data']['relation_code'] != '') { $db= UserHandle('/userCompanyBasicList', ['companyNo' =>$companyinfo['data']['relation_code']]); if ($db['code'] != 0) $this->error($db['message'],$db['code']); if (!empty($db['data']) && $db['data']['count'] > 0) { $this->error("供应商公司存在操作账户,请用供应商账户操作"); } } } } } }