You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.6 KiB
151 lines
5.6 KiB
10 months ago
|
<?php
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
||
|
// +----------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
namespace app\web\controller;
|
||
|
|
||
|
use app\web\model\user\User;
|
||
|
use basic\WapBasic;
|
||
|
use service\JsonService;
|
||
|
use service\SystemConfigService;
|
||
|
use app\web\model\user\MemberShip;
|
||
|
use service\UtilService;
|
||
|
use think\Cache;
|
||
|
use think\cache\driver\Redis;
|
||
|
use think\Cookie;
|
||
|
use think\Session;
|
||
|
use think\Url;
|
||
|
|
||
|
/**全局调用控制器
|
||
|
* Class AuthController
|
||
|
* @package app\web\controller
|
||
|
*/
|
||
|
class AuthController extends WapBasic
|
||
|
{
|
||
|
/**
|
||
|
* 用户ID
|
||
|
* @var int
|
||
|
*/
|
||
|
protected $uid = 0;
|
||
|
/**
|
||
|
* 用户信息
|
||
|
* @var
|
||
|
*/
|
||
|
protected $userInfo;
|
||
|
|
||
|
protected $phone;
|
||
|
|
||
|
protected $redisModel;
|
||
|
|
||
|
protected $subjectUrl = '';
|
||
|
|
||
|
protected function _initialize()
|
||
|
{
|
||
|
parent::_initialize();
|
||
|
$pc_on_display = SystemConfigService::get('pc_on_display');
|
||
|
if (request()->isMobile() || $pc_on_display == 0) {
|
||
|
return $this->redirect(Url::build('wap/index/index'));
|
||
|
}
|
||
|
try {
|
||
|
$this->redisModel = new Redis();
|
||
|
} catch (\Exception $e) {
|
||
|
parent::serRedisPwd($e->getMessage());
|
||
|
}
|
||
|
$NoWechantVisitWhite = $this->NoWechantVisitWhite();
|
||
|
$this->subjectUrl = getUrlToDomain();
|
||
|
try {
|
||
|
$uid = User::getActiveUid();
|
||
|
if (!empty($uid)) {
|
||
|
$this->userInfo = User::getUserInfo($uid);
|
||
|
MemberShip::memberExpiration($uid);
|
||
|
$this->uid = $this->userInfo['uid'];
|
||
|
$this->phone = User::getLogPhone($uid);
|
||
|
if (!isset($this->userInfo['uid'])) $this->userInfo['uid'] = 0;
|
||
|
if (!isset($this->userInfo['avatar'])) $this->userInfo['avatar'] = '';
|
||
|
if (!isset($this->userInfo['nickname'])) $this->userInfo['nickname'] = '';
|
||
|
|
||
|
if (!$NoWechantVisitWhite) {
|
||
|
if (!$this->userInfo || !isset($this->uid)) return $this->failed('读取用户信息失败!');
|
||
|
if (!$this->userInfo['status']) return $this->failed('已被禁止登陆!');
|
||
|
}
|
||
|
}
|
||
|
} catch (\Exception $e) {
|
||
|
Cookie::delete('is_login');
|
||
|
Cookie::delete('__login_phone');
|
||
|
Session::clear('web');
|
||
|
if (!$NoWechantVisitWhite) {
|
||
|
if ($this->request->isAjax())
|
||
|
return JsonService::fail('请登录再进行访问');
|
||
|
else
|
||
|
return $this->redirect(Url::build('web/index/index'));
|
||
|
}
|
||
|
}
|
||
|
$codeUrl = SystemConfigService::get('wechat_qrcode');
|
||
|
$balance_switch = SystemConfigService::get('balance_switch');//余额开关
|
||
|
$is_alipay = SystemConfigService::get('pc_alipay_code_scanning_payment_switch');//pc端支付宝扫码开关
|
||
|
$is_wechat = SystemConfigService::get('pc_wechat_code_scanning_payment_switch');//pc端微信扫码支付开关
|
||
|
$seo_title = SystemConfigService::get('seo_title');//SEO标题
|
||
|
$seo_description = SystemConfigService::get('description');//SEO内容
|
||
|
$now_money = isset($this->userInfo['now_money']) ? $this->userInfo['now_money'] : 0;
|
||
|
$business = isset($this->userInfo['business']) ? $this->userInfo['business'] : 0;//是否是讲师
|
||
|
$this->assign([
|
||
|
'is_yue' => $balance_switch,
|
||
|
'is_alipay' => $is_alipay,
|
||
|
'code_url' => $codeUrl,
|
||
|
'is_wechat' => $is_wechat,
|
||
|
'phone' => $this->phone,
|
||
|
'userInfo' => $this->userInfo,
|
||
|
'seo_title' => $seo_title,
|
||
|
'seo_description' => $seo_description,
|
||
|
'business' => $business,
|
||
|
'now_money' => $now_money,
|
||
|
'Auth_site_name' => SystemConfigService::get('site_name')
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检查白名单控制器方法 存在带名单返回 true 不存在则进行登录
|
||
|
* @return bool
|
||
|
*/
|
||
|
protected function NoWechantVisitWhite()
|
||
|
{
|
||
|
list($module, $controller, $action, $className) = $this->getCurrentController();
|
||
|
if (method_exists($className, 'WhiteList')) {
|
||
|
$whitelist = $className::WhiteList();
|
||
|
if (!is_array($whitelist)) return false;
|
||
|
foreach ($whitelist as $item) {
|
||
|
if (strtolower($module . '\\' . $controller . '\\' . $item) == strtolower($module . '\\' . $controller . '\\' . $action)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取当前的控制器名,模块名,方法名,类名并返回
|
||
|
* @return array
|
||
|
*/
|
||
|
protected function getCurrentController()
|
||
|
{
|
||
|
$module = $this->request->module();
|
||
|
$controller = $this->request->controller();
|
||
|
$action = $this->request->action();
|
||
|
if (strstr($controller, '.'))
|
||
|
$controllerv1 = str_replace('.', '\\', $controller);
|
||
|
else
|
||
|
$controllerv1 = $controller;
|
||
|
$className = 'app\\' . $module . '\\controller\\' . $controllerv1;
|
||
|
return [$module, $controller, $action, $className];
|
||
|
}
|
||
|
|
||
|
}
|