1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\admin;
- use think\App;
- use app\BaseController as base;
- use think\facade\Db;
- /**
- * Class BaseController
- * @package app\admin
- * 基础控制器
- */
- class BaseController extends base{
- public $post=[];
- public $uid='';
- public $uname='';
- public $roleid='';
- public $level='';
- public $novalidate=['GetLast',"performance","productTh","productPerformance"];
- public function __construct(App $app) {
- parent::__construct($app);
- $this->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"=>"验证通过"];
- }
- }
|