123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?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 function __construct(App $app) {
- parent::__construct($app);
- $this->post =$this->request->post();
- $this->validateToken();
- }
- /**
- * @return \think\response\Json|void
- * @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']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
- $this->uname=isset($effetc['data']['user']['nickname']) ?$effetc['data']['user']['nickname']:"";
- $role = Db::name("user_role")->where(["uid"=>$this->uid,"is_del"=>0])->find();
- if($role['status']==0){
- return error_show(101,'账户已禁用');
- }
- $this->roleid=$role['roleid'];
- }
- }
|