You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
112
hyhproject/app/controller/Base.php
Executable file
112
hyhproject/app/controller/Base.php
Executable file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
namespace wstmart\app\controller;
|
||||
use think\Controller;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 基础控制器
|
||||
*/
|
||||
class Base extends Controller {
|
||||
//token
|
||||
private $token = '';
|
||||
//用户 id
|
||||
private $userId = 0;
|
||||
|
||||
protected $user = [];
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
// 权限验证方法
|
||||
protected function checkDataAuth(){
|
||||
$shopId = (int)input('post.shopId');
|
||||
if(!$shopId ){
|
||||
exit(jsonReturn('参数传递不完整'));
|
||||
}
|
||||
$shopInfo = Model('shops')->getFieldsById($shopId,'shopId,userId');
|
||||
if(empty($shopInfo) || $shopInfo['userId'] != $this->getUserId()){
|
||||
exit(jsonReturn('没有权限!'.$this->getUserId()));
|
||||
}
|
||||
session('WST_USER.shopId',$shopId);
|
||||
}
|
||||
// 权限验证方法
|
||||
protected function checkAuth(){
|
||||
//正式上线要解开注释
|
||||
$user = session('WST_USER');
|
||||
if(empty($user)){
|
||||
if(!$this->checkToken()){
|
||||
die('{"status":-999,"msg":"您还未登录!"}');
|
||||
}
|
||||
}else{
|
||||
$this->user = $user;
|
||||
}
|
||||
//商家需要判断是否有优惠款未提交
|
||||
if($this->user['userType'] == 1 && strtolower(request()->controller()) != 'shoporders'){
|
||||
$rs = Model('common/Orders')->checkCertificate($this->getUserId());
|
||||
if(1 != $rs['status']){
|
||||
exit(json_encode($rs));
|
||||
}
|
||||
}
|
||||
// if(0 == $this->user['userStatus']){
|
||||
// die('{"status":-1,"msg":"此账号已被禁用,请重新登录!"}');
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* token检查验证
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function checkToken(){
|
||||
$token = $this->request->header('HYH-Token');
|
||||
if (empty($token)) {
|
||||
return false;//未发送token
|
||||
}
|
||||
$this->token = $token;
|
||||
$user = getUserByToken($token);
|
||||
if (empty($user)) {
|
||||
return false;//登录已失效!
|
||||
}
|
||||
$this->user = $user;
|
||||
session('WST_USER',$user);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 获取会员ID
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getUserId(){
|
||||
return $this->user['userId'];
|
||||
}
|
||||
/**
|
||||
* 获取推荐ID
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getPid(){
|
||||
return Model('UserTrees')->getField($this->userId);
|
||||
}
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
public function uploadPic(){
|
||||
return WSTUploadPic(0);
|
||||
}
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
public function getVerify(){
|
||||
WSTVerify();
|
||||
}
|
||||
//登录验证方法--商家
|
||||
protected function checkShopAuth(){
|
||||
// $user = session('WST_USER');
|
||||
// if(empty($user)){
|
||||
// if(!$this->checkToken()){
|
||||
// // die('{"status":-999,"msg":"您还未登录"}');
|
||||
// }
|
||||
if(empty($this->user['userType']) || $this->user['userType'] == 0) die('{"status":-2,"msg":"请先申请开店"}');
|
||||
// }else{
|
||||
// if($user['userType'] == 0) die('{"status":-2,"msg":"请先申请开店"}');
|
||||
// $this->user = $user;
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user