1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?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 function __construct(App $app) {
- parent::__construct($app);
- $this->post =$this->request->post();
- $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']];
- // return error_show($effetc['code'], $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,"status"=>1,"is_del"=>0])
- ->where($where)->findOrEmpty();
- if(empty($role)){
- return ["code"=>101,"message"=>"账户已禁用"];
- }
- $this->roleid=$role['roleid'];
- $this->level=Db::name("role")->where(["id"=>$role['roleid'],"status"=>1])->value("level",'');
- if($this->level=='') return ["code"=>101,"message"=>"账户角色已禁用"];
- return ["code"=>0,"message"=>"验证通过"];
- }
- }
|