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.
 
 
 
 
 
 
zhishifufei_php/application/wap/controller/AuthController.php

301 lines
14 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\controller;
use app\wap\model\user\User;
use app\wap\model\user\WechatUser;
use basic\WapBasic;
use service\JsonService;
use service\SystemConfigService;
use service\UtilService;
use think\Cache;
use think\cache\driver\Redis;
use think\Cookie;
use think\Session;
use think\Url;
use app\wap\model\user\MemberShip;
use service\GroupDataService;
use service\JwtService;
use think\Request;
use think\Exception;
use app\institution\model\institution\InstitutionAdmin;
use app\admin\model\special\Lecturer;
class AuthController extends WapBasic
{
/**
* 用户ID
* @var int
*/
protected $uid = 0;
/**
* 用户信息
* @var
*/
protected $userInfo;
protected $phone;
protected $force_binding;
protected $isWechat = false;
protected $redisModel;
protected $subjectUrl = '';
protected $institution = [];
protected function _initialize()
{
parent::_initialize();
$pc_on_display = SystemConfigService::get('pc_on_display');
$isNextVersion = Request()->header("X-Version") === "next" || Request()->get("__token__", "");
if (!request()->isMobile() &&! $isNextVersion&& is_dir(APP_PATH . 'web') && $pc_on_display) {
return $this->redirect(Url::build('web/index/index'));
}
try {
$this->redisModel = new Redis();
} catch (\Exception $e) {
parent::serRedisPwd($e->getMessage());
}
$this->isWechat = UtilService::isWechatBrowser();
$spread_uid = Request::instance()->param('spread_uid', 0);
$NoWechantVisitWhite = $this->NoWechantVisitWhite();
$subscribe = false;
$site_url = SystemConfigService::get('site_url');
$this->subjectUrl = getUrlToDomain();
$this->site_url = $site_url;
if ($isNextVersion) {
$jwtService = new JwtService();
try {
$token = Request()->header("Authorization");
$token = trim(ltrim($token, 'Bearer'));
if (!$token) {
$token = Request()->get("__token__");
}
if ($token) {
$uid = $jwtService->parseToken($token);
$jwtService->verifyToken();
$this->userInfo = User::getUserInfo($uid);
MemberShip::memberExpiration($uid);
if ($spread_uid) $spreadUserInfo = User::getUserInfo($spread_uid);
$this->uid = $this->userInfo['uid'];
$this->phone = User::getLogPhone($uid);
//绑定推广人
if ($spread_uid && $spreadUserInfo && $this->uid != $spread_uid && $spreadUserInfo['spread_uid'] != $this->uid && $this->userInfo['spread_uid'] != $spread_uid && !$this->userInfo['spread_uid']) {
$storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1; //获取后台分销类型
if ($storeBrokerageStatu == 1) {
if ($spreadUserInfo['is_promoter']) User::edit(['spread_uid' => $spread_uid], $this->uid, 'uid');
} else {
User::edit(['spread_uid' => $spread_uid], $this->uid, 'uid');
}
}
if (!isset($this->userInfo['uid'])) $this->userInfo['uid'] = 0;
if (!isset($this->userInfo['is_promoter'])) $this->userInfo['is_promoter'] = 0;
if (!isset($this->userInfo['avatar'])) $this->userInfo['avatar'] = '';
if (!isset($this->userInfo['nickname'])) $this->userInfo['nickname'] = '';
//是否关注公众号
$subscribe = WechatUser::where('uid', $this->uid)->value('subscribe');
if (!$NoWechantVisitWhite) {
if (!$this->userInfo || !isset($this->uid)) return JsonService::fail('读取用户信息失败!');
if (!$this->userInfo['status']) return JsonService::fail('已被禁止登陆!');
}
}
} catch (Exception $e) {
if ($NoWechantVisitWhite) {
$msg = $e->getMessage();
return JsonService::fail($msg ? $msg : '请登录再进行访问!');
}
}
} else {
try {
$uid = User::getActiveUid();
if (!empty($uid)) {
$this->userInfo = User::getUserInfo($uid);
if ($this->isWechat) {
if ($this->userInfo['nickname'] == '' && $this->userInfo['avatar'] == '' || $this->userInfo['nickname'] == '' && $this->userInfo['avatar'] == '/system/images/user_log.jpg') {
$url = $this->request->url(true);
if (!$this->request->isAjax()) {
return $this->redirect(Url::build('Login/index', ['spread_uid' => $spread_uid]) . '?ref=' . base64_encode(htmlspecialchars($url)));
}
}
}
MemberShip::memberExpiration($uid);
if ($spread_uid) $spreadUserInfo = User::getUserInfo($spread_uid);
$this->uid = $this->userInfo['uid'];
$this->phone = User::getLogPhone($uid);
//绑定推广人
if ($spread_uid && $spreadUserInfo && $this->uid != $spread_uid && $spreadUserInfo['spread_uid'] != $this->uid && $this->userInfo['spread_uid'] != $spread_uid && !$this->userInfo['spread_uid']) {
$storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1; //获取后台分销类型
if ($storeBrokerageStatu == 1) {
if ($spreadUserInfo['is_promoter']) User::edit(['spread_uid' => $spread_uid], $this->uid, 'uid');
} else {
User::edit(['spread_uid' => $spread_uid], $this->uid, 'uid');
}
}
if (!isset($this->userInfo['uid'])) $this->userInfo['uid'] = 0;
if (!isset($this->userInfo['is_promoter'])) $this->userInfo['is_promoter'] = 0;
if (!isset($this->userInfo['avatar'])) $this->userInfo['avatar'] = '';
if (!isset($this->userInfo['nickname'])) $this->userInfo['nickname'] = '';
//是否关注公众号
$subscribe = WechatUser::where('uid', $this->uid)->value('subscribe');
if (!$NoWechantVisitWhite) {
if (!$this->userInfo || !isset($this->uid)) return $this->failed('读取用户信息失败!');
if (!$this->userInfo['status']) return $this->failed('已被禁止登陆!');
}
}
} catch (\Exception $e) {
Session::clear('wap');
Cookie::delete('is_login');
Cookie::delete('__login_phone');
$url = $this->request->url(true);
if (!$NoWechantVisitWhite) {
if ($this->request->isAjax())
return JsonService::fail('请登录再进行访问');
else
return $this->redirect(Url::build('Login/index', ['spread_uid' => $spread_uid]) . '?ref=' . base64_encode(htmlspecialchars($url)));
}
}
}
$institutionInfo = InstitutionAdmin::where('uid',$this->userInfo['uid'])->value('mer_id');
$institution = Lecturer::where(array('agent'=>$institutionInfo,'is_del' => 0))->select()->toArray();
$institution_exp = implode(',',array_column($institution,'mer_id'));
$this->institution = $institution_exp ? $institution_exp . ',' .$institutionInfo : $institutionInfo;
if (Cache::has('__SYSTEM__')) {
$overallShareWechat = Cache::get('__SYSTEM__');
} else {
$overallShareWechat = SystemConfigService::more(['wechat_share_img', 'wechat_share_title', 'wechat_share_synopsis']);
Cache::set('__SYSTEM__', $overallShareWechat, 800);
}
$codeUrl = SystemConfigService::get('wechat_qrcode');
$balance_switch = SystemConfigService::get('balance_switch'); //余额开关
$alipay_switch = SystemConfigService::get('alipay_switch'); //支付宝开关
$h5_wechat_payment_switch = SystemConfigService::get('h5_wechat_payment_switch'); //h5端微信支付开关
$official_account_switch = SystemConfigService::get('official_account_switch'); //关注公众号开关
$this->force_binding = SystemConfigService::get('force_binding'); //微信端是否强制绑定手机号
$share_display_switch = SystemConfigService::get('share_display_switch'); //分享显示开关
$now_money = isset($this->userInfo['now_money']) ? $this->userInfo['now_money'] : 0;
$this->assign([
'callback_url' => $site_url . '/wap/callback/pay_success_synchro',
'code_url' => $codeUrl,
'is_yue' => $balance_switch,
'is_alipay' => $alipay_switch,
'is_h5_wechat_payment_switch' => $h5_wechat_payment_switch,
'is_official_account_switch' => $official_account_switch,
'is_share_display_switch' => $share_display_switch,
'subscribe' => $subscribe,
'subscribeQrcode' => SystemConfigService::get('wechat_qrcode'),
'userInfo' => $this->userInfo,
'uid' => isset($this->userInfo['uid']) ? $this->userInfo['uid'] : 0,
'business' => isset($this->userInfo['business']) ? $this->userInfo['business'] : 0, //是否是讲师
'now_money' => $now_money,
'phone' => $this->phone,
'isWechat' => $this->isWechat,
'overallShareWechat' => json_encode($overallShareWechat),
'Auth_site_name' => SystemConfigService::get('site_name'),
'menus' => GroupDataService::getData('bottom_navigation')
]);
}
public function AuthInfo()
{
$balance_switch = SystemConfigService::get('balance_switch')?true:false; //余额开关
$alipay_switch = SystemConfigService::get('alipay_switch')?true:false; //支付宝开关
$h5_wechat_payment_switch = SystemConfigService::get('h5_wechat_payment_switch')?true:false; //h5端微信支付开关
$official_account_switch = SystemConfigService::get('official_account_switch')?true:false; //关注公众号开关
$this->force_binding = SystemConfigService::get('force_binding'); //微信端是否强制绑定手机号
$share_display_switch = SystemConfigService::get('share_display_switch')?true:false; //分享显示开关
$now_money = isset($this->userInfo['now_money']) ? $this->userInfo['now_money'] : 0;
return JsonService::successful('ok', [
'isBalance' => $balance_switch,
'isAlipay' => $alipay_switch,
'wxpayH5' => $h5_wechat_payment_switch,
'is_official_account_switch' => $official_account_switch,
'is_share_display_switch' => $share_display_switch,
'subscribeQrcode' => SystemConfigService::get('wechat_qrcode'),
'userInfo' => $this->userInfo,
'uid' => isset($this->userInfo['uid']) ? $this->userInfo['uid'] : 0,
'business' => isset($this->userInfo['business']) ? $this->userInfo['business'] : 0, //是否是讲师
'nowMoney' =>floatval($now_money),
'phone' => $this->phone,
'isWechat' => $this->isWechat,
'Auth_site_name' => SystemConfigService::get('site_name'),
'menus' => GroupDataService::getData('bottom_navigation')
]);
}
/**
* 检查白名单控制器方法 存在带名单返回 true 不存在则进行登录
* @return bool
*/
protected function NoWechantVisitWhite()
{
if ($this->isWechat) return false;
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];
}
}