* Date: 2018-4-3 */ namespace app\user\controller; use think\Db; use think\Config; use think\Page; use think\Verify; use app\user\logic\SmtpmailLogic; class Users extends Base { public $smtpmailLogic; public function _initialize() { parent::_initialize(); $this->smtpmailLogic = new SmtpmailLogic; $this->users_db = Db::name('users'); // 会员数据表 $this->users_level_db = Db::name('users_level'); // 会员等级表 $this->users_parameter_db = Db::name('users_parameter'); // 会员属性表 $this->users_list_db = Db::name('users_list'); // 会员属性信息表 $this->users_config_db = Db::name('users_config');// 会员配置表 $this->users_money_db = Db::name('users_money');// 会员金额明细表 $this->smtp_record_db = Db::name('smtp_record');// 发送邮箱记录表 $this->sms_log_db = Db::name('sms_log');// 发送手机记录表 // 微信配置信息 $this->pay_wechat_config = unserialize(getUsersConfigData('pay.pay_wechat_config')); // 查询部分模型开启信息 下载 视频 问答 $partChannel = []; $usersOrderUrl = ''; if (in_array(ACTION_NAME, ['index', 'article_index', 'download_index', 'media_index'])) { $where = [ 'nid' => ['IN', ['media', 'article', 'download']] ]; $partChannel = Db::name('channeltype')->where($where)->field('id, nid, ntitle, status, data')->order('id asc')->getAllWithIndex('nid'); foreach ($partChannel as $key => $value) { $value['data'] = !empty($value['data']) ? json_decode($value['data'], true) : []; if ('media' == $key && !empty($this->eyou['global']['php_servicemeal']) && 1 < intval($this->eyou['global']['php_servicemeal'])) { $value['data']['is_media_pay'] = 1; } if (empty($usersOrderUrl)) { if (!empty($value['data']['is_article_pay']) && 1 === intval($value['data']['is_article_pay'])) { $usersOrderUrl = url('user/Users/article_index'); } else if (!empty($value['data']['is_download_pay']) && 1 === intval($value['data']['is_download_pay'])) { $usersOrderUrl = url('user/Users/download_index'); } else if (!empty($value['data']['is_media_pay']) && 1 === intval($value['data']['is_media_pay'])) { $usersOrderUrl = url('user/Users/media_index'); } } $partChannel[$key] = $value; } } $this->assign('partChannel', $partChannel); $this->assign('usersOrderUrl', $usersOrderUrl); $isCount = Db::name('users_menu')->where([ 'mca' => 'plugins/PointsShop/index', 'lang' => 'cn', ])->count(); if (empty($isCount)) { Db::name('users_menu')->add([ 'title' => '积分兑换', 'mca' => 'plugins/PointsShop/index', 'is_userpage' => 0, 'sort_order' => 100, 'status' => 1, 'lang' => 'cn', 'add_time' => getTime(), 'update_time' => getTime(), ]); } } // 会员中心首页 public function index() { if (1 == config('global.opencodetype')) { return action('user/Users/index2'); } if ($this->usersTplVersion == 'v1') { return action('user/Users/info'); } $result = []; // 资料信息 $result['users_para'] = model('Users')->getDataParaList($this->users_id); $this->assign('users_para', $result['users_para']); $eyou = array( 'field' => $result, ); $this->assign('eyou', $eyou); // 是否绑定了微站点,否则自动绑定 $referurl = ''; if (!empty($this->users_id)) { auto_bind_wechatlogin($this->users, $referurl); if (!empty($referurl)) { header('Location: '. $referurl); exit; } } //其他数据 $others = array(); $users_id = $this->users_id; //收藏数 $others['collect_num'] = Db::name('users_collection')->where(['users_id'=>$users_id])->count("id"); //足迹 $others['footprint_num'] = Db::name('users_footprint')->where(['users_id'=>$users_id])->count('id'); //今日签到信息 $others['signin_conf'] = getUsersConfigData('score'); if ($others['signin_conf'] && isset($others['signin_conf']['score_signin_status']) && $others['signin_conf']['score_signin_status'] == 1) { $now_time = time(); $today_start = mktime(0,0,0,date("m",$now_time),date("d",$now_time),date("Y",$now_time)); $today_end = mktime(23,59,59,date("m",$now_time),date("d",$now_time),date("Y",$now_time)); $others['signin_info'] = Db::name('users_signin')->where(['users_id'=>$users_id,'add_time'=>['BETWEEN',[$today_start,$today_end]]])->value("id"); } //查询插件信息 $weapp_menu_info = Db::name('users_menu')->field("id,title,version,mca")->where(['version'=>'weapp','status'=>1])->select(); $others['weapp_menu_info'] = []; if ($weapp_menu_info) { $weapp_row = Db::name('weapp')->field("code,name,config")->where(['status'=>1])->getAllWithIndex('code'); foreach ($weapp_menu_info as $k=>$v) { preg_match_all('/\/(\w+)\//i', $v['mca'],$preg_res); if (!empty($preg_res[1])) { $code_str = $preg_res[1][0]; $weapp_info = empty($weapp_row[$code_str]) ? [] : $weapp_row[$code_str]; if (empty($weapp_info)/* || ('PointsShop' == $weapp_info['code'] && empty($weapp_row['DiyminiproMall']))*/) { unset($weapp_menu_info[$k]); continue; } $weapp_menu_info[$k]['litpic'] = json_decode($weapp_info['config'],true)['litpic']; } } $others['weapp_menu_info'] = $weapp_menu_info; } $this->assign('others', $others); //查询部分模型开启信息 下载 视频 问答 $part_channel = Db::name('channeltype') ->where('nid','in',['ask','download','media','article']) ->field('nid,status,data') ->getAllWithIndex('nid'); if (!empty($part_channel['article']['data'])){ $part_channel['article']['data'] = json_decode($part_channel['article']['data'], true); } if (!empty($part_channel['download']['data'])){ $part_channel['download']['data'] = json_decode($part_channel['download']['data'], true); } $this->assign('part_channel', $part_channel); // 多语言 $condition_bottom['a.status'] = array('eq', 1); $condition_bottom['a.display'] = array('eq', 1); $bottom_menu_list = Db::name('users_bottom_menu')->field('a.*') ->alias('a') ->where($condition_bottom) ->order('a.sort_order asc, a.id asc') ->limit(4) ->select(); $this->assign('bottom_menu_list', $bottom_menu_list); // 问候语 $hour = date('H'); $greeting = '晚上好~'; if (0 < intval($hour) && intval($hour) < 12) { $greeting = '早上好~'; } else if (12 < intval($hour) && intval($hour) < 19) { $greeting = '下午好~'; } $this->assign('greeting', $greeting); // 积分兑换是否已在用 $shopLogic = new \app\admin\logic\ShopLogic; $useFunc = $shopLogic->useFuncLogic(); $this->assign('useFunc', $useFunc); $clear_session_url = $this->root_dir."/index.php?m=api&c=Ajax&a=clear_session"; $replace = << clear_session(); function clear_session() { $.ajax({ url: "{$clear_session_url}", type: 'post', dataType: 'JSON', data: {_ajax: 1}, success: function(res){ } }); } EOF; $html = $this->fetch('users_welcome'); $html = str_ireplace('', $replace, $html); return $html; } // 个人信息 public function info() { $result = []; // 资料信息 $result['users_para'] = model('Users')->getDataParaList($this->users_id); $this->assign('users_para', $result['users_para']); // 邮箱发送限制时间 $this->assign('email_send_time', config('global.email_send_time')); // 手机发送限制时间 $this->assign('mobile_send_time', config('global.mobile_send_time')); // 菜单名称 $result['title'] = Db::name('users_menu')->where([ 'mca' => 'user/Users/index', ])->getField('title'); $eyou = array( 'field' => $result, ); $this->assign('eyou', $eyou); $thirdparty = []; $loginApp = Db::name("weapp")->where(['code'=>['in',['QqLogin','WxLogin']]])->getAllWithIndex('code'); //qq绑定信息 if (!empty($loginApp['QqLogin']) && $loginApp['QqLogin']['status'] == 1){ //qq登陆插件安装且处于开启状态 $qqlogin_config = json_decode($loginApp['QqLogin']['config'],true); if (!empty($qqlogin_config['version']) && $qqlogin_config['version'] >= 'v1.4.2'){ try{ $thirdparty['qq'] = Db::name("weapp_qqlogin")->where(['users_id'=>$this->users_id])->find(); $thirdparty['is_qq'] = 1; }catch(\Exception $e){} } } //微信绑定信息 if (!empty($loginApp['WxLogin']) && $loginApp['WxLogin']['status'] == 1){ //qq登陆插件安装且处于开启状态 $wxlogin_config = json_decode($loginApp['WxLogin']['config'],true); if (!empty($wxlogin_config['version']) && $wxlogin_config['version'] >= 'v1.2.2'){ try{ $thirdparty['wx'] = Db::name("weapp_wxlogin")->where(['users_id'=>$this->users_id])->find(); $thirdparty['is_wx'] = 1; }catch(\Exception $e){} } } $this->assign('thirdparty',$thirdparty); /*等保密码复杂度验证 start*/ $pwdJsCode = ''; if (is_dir('./weapp/Equal/')) { $equalLogic = new \weapp\Equal\logic\EqualLogic; $pwdJsCode = $equalLogic->pwdJsCode(); } if ('close' == $pwdJsCode) { $pwdJsCode = ''; } $this->assign('pwdJsCode', $pwdJsCode); /*等保密码复杂度验证 end*/ $html = $this->fetch('users_centre'); // 会员模板版本号 if ($this->usersTplVersion == 'v1') { /*第三方注册的用户,无需修改登录密码*/ if (!empty($this->users['thirdparty'])) { $html = str_ireplace('onclick="ChangePwdMobile();"', 'onclick="ChangePwdMobile();" style="display: none;"', $html); $html = str_ireplace('onclick="ChangePwd();"', 'onclick="ChangePwd();" style="display: none;"', $html); } /*end*/ // 美化昵称输入框 $html = str_ireplace('type="text" name="nickname"', 'type="text" name="nickname" class="input-txt"', $html); } $token_input = token('__token_users_centre_update__'); $replace =<< EOF; $html = str_ireplace('', $replace, $html); return $html; } // 会员选择登陆方式界面 public function users_select_login() { // 若存在则调转至会员中心 if ($this->users_id > 0) { $this->redirect('user/Users/centre'); exit; } // 跳转链接 $referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : url("user/Users/centre"); $referurl = strip_tags($referurl); session('eyou_referurl', $referurl); // 拼装url $result = [ 'wechat_url' => url("user/Users/ajax_wechat_login"), 'website_url' => $this->root_dir . "/index.php?m=user&c=Users&a=login&website=website", ]; // 若为微信端并且开启微商城模式则重定向 if (isWeixin() && !empty($this->usersConfig['shop_micro'])) { $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : []; if (!empty($WeChatLoginConfig)) { $this->redirect($result['wechat_url']); } } // 若后台功能设置-登录设置中,微信端本站登录为关闭状态,则直接跳转到微信授权页面 if (isset($this->usersConfig['users_open_website_login']) && empty($this->usersConfig['users_open_website_login'])) { $this->redirect($result['wechat_url']); exit; } // 数据加载 $eyou = array( 'field' => $result, ); $this->assign('eyou', $eyou); // 默认开启验证码 $is_vertify = 1; $users_login_captcha = config('captcha.users_login'); if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) { $is_vertify = 0; // 函数不存在,不符合开启的条件 } $this->assign('is_vertify', $is_vertify); return $this->fetch('users_select_login'); } // 使用ajax微信授权登陆 public function ajax_wechat_login() { $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : []; // 微信授权登陆 if (!empty($WeChatLoginConfig['appid']) && !empty($WeChatLoginConfig['appsecret'])) { if (isMobile() && isWeixin()) { // 判断登陆成功跳转的链接,若为空则默认会员中心链接并存入session $referurl = session('eyou_referurl'); if (empty($referurl)) { $referurl = url('user/Users/index', '', true, true); session('eyou_referurl', $referurl); } // 获取微信配置授权登陆 $appid = $WeChatLoginConfig['appid']; $NewUrl = urlencode(url('user/Users/get_wechat_info', '', true, true)); $ReturnUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . $NewUrl . "&response_type=code&scope=snsapi_userinfo&state=eyoucms&#wechat_redirect"; if (isset($this->usersConfig['users_open_website_login']) && empty($this->usersConfig['users_open_website_login'])) { $this->redirect($ReturnUrl); } else { if (IS_AJAX_POST) { $this->success('授权成功!', $ReturnUrl); } else { $this->redirect($ReturnUrl); } } } $this->error('非手机端微信、小程序,不可以使用微信登陆,请选择本站登陆!'); } $this->error('后台微信配置尚未配置AppSecret,不可以微信登陆,请选择本站登陆!'); } // 在微信端,非微站点登录成功后,进行授权获取openid public function auto_bind_wechat_info() { $eyou_referurl = session('eyou_referurl'); if (empty($eyou_referurl)) { $eyou_referurl = url('user/Users/index', '', true, true); } // 微信配置信息 $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : []; $appid = $WeChatLoginConfig['appid']; $secret = $WeChatLoginConfig['appsecret']; $code = input('param.code/s'); // 获取到会员openid $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code'; $result = json_decode(httpRequest($url), true); // 授权过期,请重新授权 if (empty($result) || (!empty($result['errcode']) && !empty($result['errmsg']))) $this->error('微信授权过期,请重新授权'); // 授权成功,记录授权信息并重定向回原页面 if (!empty($result) && !empty($result['openid'])) { // 记录微信授权 cookie model('ShopPublicHandle')->weChatauthorizeCookie($this->users_id, 'set', ['openid' => $result['openid'], 'expire' => 86400]); } // 重定向回原页面 $this->redirect($eyou_referurl); // // 获取到会员openid // $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code'; // $data = httpRequest($get_token_url); // $WeChatData = json_decode($data, true); // if (empty($WeChatData) || (!empty($WeChatData['errcode']) && !empty($WeChatData['errmsg']))) { // session('auto_bind_wechat_info', '-1'); // $this->redirect($eyou_referurl); // exit; // } // // 获取会员信息 // $get_userinfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $WeChatData["access_token"] . '&openid=' . $WeChatData["openid"] . '&lang=zh_CN'; // $UserInfo = httpRequest($get_userinfo); // $UserInfo = json_decode($UserInfo, true); // if (empty($UserInfo['nickname']) && empty($UserInfo['headimgurl'])) { // session('auto_bind_wechat_info', '-1'); // $this->redirect($eyou_referurl); // exit; // } // $UserInfo['unionid'] = !empty($UserInfo['unionid']) ? $UserInfo['unionid'] : ''; // $Users = $this->users_db->where(['users_id'=>$this->users_id])->find(); // if (!empty($Users)) { // if (empty($Users['union_id']) && !empty($UserInfo['unionid'])){ // $row = Db::name('users')->where(['union_id'=>$UserInfo['unionid']])->find(); // if (empty($row)) { // $Users['union_id'] = $UserInfo['unionid']; // $this->users_db->where('users_id', $Users['users_id'])->update(['union_id'=>$UserInfo['unionid'],'update_time'=>getTime()]); // } // } // if (!empty($UserInfo['openid'])) { // $wxlogin_info = []; // if (is_dir('./weapp/WxLogin/')) { // $wxlogin_info = Db::name("weapp_wxlogin")->where(['users_id'=>$Users['users_id']])->find(); // } // if (empty($Users['open_id']) || (isset($wxlogin_info['openid']) && $Users['open_id'] == $wxlogin_info['openid'])) { // $row = Db::name('users')->where(['union_id'=>$UserInfo['openid']])->find(); // if (empty($row)) { // $Users['open_id'] = $UserInfo['openid']; // $this->users_db->where('users_id', $Users['users_id'])->update(['open_id'=>$UserInfo['openid'],'update_time'=>getTime()]); // } // } // } // // 已注册 // session('users_id', $Users['users_id']); // session('users', $Users); // session('eyou_referurl', ''); // cookie('users_id', $Users['users_id']); // $this->redirect($eyou_referurl); // exit; // } else { // session('auto_bind_wechat_info', '-1'); // $this->redirect($eyou_referurl); // exit; // } } // 授权之后,获取会员信息 public function get_wechat_info() { $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : []; // 微信配置信息 $appid = $WeChatLoginConfig['appid']; $secret = $WeChatLoginConfig['appsecret']; $code = input('param.code/s'); // 获取到会员openid $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code'; $data = httpRequest($get_token_url); $WeChatData = json_decode($data, true); if (empty($WeChatData) || (!empty($WeChatData['errcode']) && !empty($WeChatData['errmsg']))) { $this->error('AppSecret错误或已过期', $this->root_dir.'/'); } // 获取会员信息 $get_userinfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $WeChatData["access_token"] . '&openid=' . $WeChatData["openid"] . '&lang=zh_CN'; $UserInfo = httpRequest($get_userinfo); $UserInfo = json_decode($UserInfo, true); if (empty($UserInfo['nickname']) && empty($UserInfo['headimgurl'])) { $this->error('用户授权异常,建议清理手机缓存再进行登录', $this->root_dir.'/'); } $UserInfo['unionid'] = !empty($UserInfo['unionid']) ? $UserInfo['unionid'] : ''; $Users = []; if (!empty($UserInfo['unionid'])){ // 查询这个unionid是否已注册 $where = [ 'union_id' => $UserInfo['unionid'], ]; $Users = $this->users_db->where($where)->find(); } if (empty($Users)){ //根据openid和空union_id查询是否为老用户 $where = [ 'open_id' => $UserInfo['openid'], ]; $Users = $this->users_db->where($where)->find(); } if (!empty($Users)) { if (empty($Users['union_id']) && !empty($UserInfo['unionid'])){ $Users['union_id'] = $UserInfo['unionid']; $this->users_db->where('users_id', $Users['users_id'])->update(['union_id'=>$UserInfo['unionid'],'update_time'=>getTime()]); } if (!empty($UserInfo['openid'])) { $wxlogin_info = []; if (is_dir('./weapp/WxLogin/')) { $wxlogin_info = Db::name("weapp_wxlogin")->where(['users_id'=>$Users['users_id']])->find(); } if (empty($Users['open_id']) || (isset($wxlogin_info['openid']) && $Users['open_id'] == $wxlogin_info['openid'])) { $Users['open_id'] = $UserInfo['openid']; $this->users_db->where('users_id', $Users['users_id'])->update(['open_id'=>$UserInfo['openid'],'update_time'=>getTime()]); } } // 已注册 $eyou_referurl = session('eyou_referurl'); if (empty($eyou_referurl)) { $eyou_referurl = url('user/Users/index', '', true, true); } session('users_id', $Users['users_id']); session('users', $Users); session('eyou_referurl', ''); cookie('users_id', $Users['users_id']); model('EyouUsers')->loginAfter($Users); $this->redirect($eyou_referurl); } else { // 未注册 $username = substr($WeChatData['openid'], 6, 8); // 查询用户名是否已存在 $result = $this->users_db->where('username', $username)->count(); if (!empty($result)) { $username = $username . rand('100,999'); } // 新增会员和微信绑定 $UsersData = [ 'username' => $username, 'nickname' => filterNickname($UserInfo['nickname']), 'open_id' => $WeChatData['openid'], 'password' => '', // 密码默认为空 'reg_time' => getTime(), 'last_ip' => clientIP(), 'last_login' => getTime(), 'is_activation' => 1, // 微信注册会员,默认开启激活 'register_place' => 2, // 前台微信注册会员 'thirdparty' => 5, // 微站点 'login_count' => Db::raw('login_count+1'), 'head_pic' => $UserInfo['headimgurl'], 'union_id' => $UserInfo['unionid'], 'lang' => $this->home_lang, ]; //来源 if (isMobile()){ if (isWeixin()){ $UsersData['source'] = 3;//1-PC端 2-H5 3-微信公众号/微站点 4-微信小程序 5-百度小程序 6-抖音小程序 }else{ $UsersData['source'] = 2;//1-PC端 2-H5 3-微信公众号 4-微信小程序 5-百度小程序 6-抖音小程序 } } // 查询默认会员级别,存入会员表 $level_id = $this->users_level_db->where([ 'is_system' => 1, ])->getField('level_id'); $UsersData['level'] = $level_id; $users_id = $this->users_db->add($UsersData); if (!empty($users_id)) { if (6 > strlen($users_id)){ $users_id = sprintf("%06d",$users_id);//不足6位补0 } $username = 'U'.$users_id; $username = rand_username($username, 'U', 3); $this->users_db->where('users_id', $users_id)->update(['username'=>$username,'update_time'=>getTime()]); // 新增成功,将会员信息存入session $eyou_referurl = session('eyou_referurl'); if (empty($eyou_referurl)) { $eyou_referurl = url('user/Users/index', '', true, true); } $GetUsers = $this->users_db->where('users_id', $users_id)->find(); session('users_id', $GetUsers['users_id']); session('users', $GetUsers); session('eyou_referurl', ''); cookie('users_id', $GetUsers['users_id']); model('EyouUsers')->loginAfter($GetUsers); $this->redirect($eyou_referurl); } else { $this->error('未知错误,无法继续!'); } } } // 登陆 public function login() { /*$config = Config::get('session'); var_dump($config); dump(config('session')); var_dump(session_id()); echo session('openid'); session('openid', '123456'); die;*/ // 若已登录则重定向 if ($this->users_id > 0) $this->redirect('user/Users/centre'); // 回跳路径 $referurl = input('param.referurl/s', null, 'htmlspecialchars_decode,urldecode'); if (empty($referurl)) { if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) { $referurl = $_SERVER['HTTP_REFERER']; } else { $referurl = url("user/Users/centre"); } } $referurl = strip_tags($referurl); // 切换账号后,在动态URL模式下登录404,与付费文档有关 $referurl_2 = input('param.referurl/s', null, 'htmlspecialchars_decode'); if (stristr($referurl_2, '&referurl=')) { parse_str($referurl_2, $parse); $referurl = str_replace("&referurl={$parse['referurl']}", "&referurl=".urlencode($parse['referurl']), $referurl); } session('eyou_referurl', $referurl); // 若为微信端并且开启微商城模式则重定向直接使用微信登录 if (isWeixin() && !empty($this->usersConfig['shop_micro'])) { $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : []; if (!empty($WeChatLoginConfig) && !IS_AJAX) { $this->redirect('user/Users/ajax_wechat_login'); exit; } } // 若为微信端并且没有开启微商城模式则重定向到登录选择页 $website = input('param.website/s'); if (isWeixin() && empty($website)) $this->redirect('user/Users/users_select_login'); // 默认开启验证码 $is_vertify = 1; $users_login_captcha = config('captcha.users_login'); if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) { $is_vertify = 0; // 函数不存在,不符合开启的条件 } $this->assign('is_vertify', $is_vertify); if (IS_AJAX_POST) { $post = input('post.'); $post['username'] = trim($post['username']); if (empty($post['username'])) { $this->error('用户名不能为空!', null, ['status' => 1]); } else if (!preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $post['username'])) { $this->error('用户名不正确!', null, ['status' => 1]); } if (empty($post['password']) || !trim($post['password'])) { $this->error('密码不能为空!', null, ['status' => 1]); } if (1 == $is_vertify) { if (empty($post['vertify'])) { $this->error('图片验证码不能为空!', null, ['status' => 1]); } $verify = new Verify(); if (!$verify->check($post['vertify'], "users_login")) { $this->error('验证码错误', null, ['status' => 'vertify']); } } $where = []; $rawStr = " username = '{$post['username']}' "; if (check_mobile($post['username'])) { $rawStr .= " OR (mobile = '{$post['username']}' AND is_mobile = 1)"; } $where[] = Db::raw($rawStr); $users = $this->users_db->where($where)->find(); if (!empty($users['is_del'])) $users = []; $uc_uid = 0; if (is_dir('./weapp/UCenter/')) { $ucenter = new \weapp\UCenter\logic\UCenterLogic(); $uc_uid = $ucenter->uc_login_synlogin($post, $users); } if (!empty($users)) { if (!empty($users['admin_id'])) { // 后台账号不允许在前台通过账号密码登录,只能后台登录时同步到前台 $this->error('前台禁止管理员登录!', null, ['status' => 'vertify']); } if (empty($users['is_activation'])) { $this->error('该会员尚未激活,请联系管理员!', null, ['status' => 'vertify']); } $users_id = $users['users_id']; /*等保密码复杂度验证 start*/ if (is_dir('./weapp/Equal/')) { $equal_privkey = input('post.equal_privkey/s'); $equalLogic = new \weapp\Equal\logic\EqualLogic; $equalLogic->loginLogic($post['password'], $equal_privkey); } /*等保密码复杂度验证 end*/ $encry_password = func_encrypt($post['password'], false, pwd_encry_type($users['password'])); if ($uc_uid > 0 || strval($users['password']) === strval($encry_password)) { // 判断是前台还是后台注册的会员,后台注册不受注册验证影响,1为后台注册,2为前台注册。 if (2 == $users['register_place']) { $usersVerificationRow = M('users_config')->where([ 'name' => 'users_verification', ])->find(); if ($usersVerificationRow['update_time'] <= $users['reg_time']) { // 判断是否需要后台审核 if ($usersVerificationRow['value'] == 1 && $users['is_activation'] == 0) { $this->error('管理员审核中,请稍等!', null, ['status' => 2]); } } } // 会员users_id存入session model('EyouUsers')->loginAfter($users); $users_config = getUsersConfigData('users'); if (!empty($users_config['users_login_jump_type']) && 1 == $users_config['users_login_jump_type']){ $referurl = ROOT_DIR."/";//跳到首页 }elseif (!empty($users_config['users_login_jump_type']) && 3 == $users_config['users_login_jump_type']){ $referurl = url('user/Users/centre');//跳到会员中心 }elseif (!empty($users_config['users_login_jump_type']) && 4 == $users_config['users_login_jump_type']){ $referurl = htmlspecialchars_decode($users_config['users_login_jump_url']);//跳到自定义URL $referurl = strip_tags($referurl); } // 是否绑定了微站点,否则自动绑定 auto_bind_wechatlogin($users, $referurl); $this->success('登录成功', $referurl); } else { $this->error('密码不正确!', null, ['status' => 'vertify']); } } else { $this->error('该用户名不存在,请注册!', null, ['status' => 'vertify']); } } /*微信登录插件 - 判断是否显示微信登录按钮*/ $weapp_wxlogin = 0; if (is_dir('./weapp/WxLogin/')) { $wx = Db::name('weapp')->field('data,status,config')->where(['code' => 'WxLogin'])->find(); if ($wx) { $wx['data'] = unserialize($wx['data']); if ($wx['status'] == 1 && $wx['data']['login_show'] == 1) { $weapp_wxlogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $wx['config'] = json_decode($wx['config'], true); if (isMobile() && !in_array($wx['config']['scene'], [0,1])) { $weapp_wxlogin = 0; } else if (!isMobile() && !in_array($wx['config']['scene'], [0,2])) { $weapp_wxlogin = 0; } } } $this->assign('weapp_wxlogin', $weapp_wxlogin); /*end*/ /*QQ登录插件 - 判断是否显示QQ登录按钮*/ $weapp_qqlogin = 0; if (is_dir('./weapp/QqLogin/')) { $qq = Db::name('weapp')->field('data,status,config')->where(['code' => 'QqLogin'])->find(); if (!empty($qq)) { $qq['data'] = unserialize($qq['data']); if ($qq['status'] == 1 && $qq['data']['login_show'] == 1) { $weapp_qqlogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $qq['config'] = json_decode($qq['config'], true); if (isMobile() && !in_array($qq['config']['scene'], [0,1])) { $weapp_qqlogin = 0; } else if (!isMobile() && !in_array($qq['config']['scene'], [0,2])) { $weapp_qqlogin = 0; } } } $this->assign('weapp_qqlogin', $weapp_qqlogin); /*end*/ /*微博插件 - 判断是否显示微博按钮*/ $weapp_wblogin = 0; if (is_dir('./weapp/Wblogin/')) { $wb = Db::name('weapp')->field('data,status,config')->where(['code' => 'Wblogin'])->find(); if (!empty($wb)) { $wb['data'] = unserialize($wb['data']); if ($wb['status'] == 1 && $wb['data']['login_show'] == 1) { $weapp_wblogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $wb['config'] = json_decode($wb['config'], true); if (isMobile() && !in_array($wb['config']['scene'], [0,1])) { $weapp_wblogin = 0; } else if (!isMobile() && !in_array($wb['config']['scene'], [0,2])) { $weapp_wblogin = 0; } } } $this->assign('weapp_wblogin', $weapp_wblogin); /*end*/ /*等保密码复杂度验证 start*/ $pwdJsCode = ''; if (is_dir('./weapp/Equal/')) { $equalLogic = new \weapp\Equal\logic\EqualLogic; $pwdJsCode = $equalLogic->pwdJsCode(); } if ('close' == $pwdJsCode) { $pwdJsCode = ''; } $this->assign('pwdJsCode', $pwdJsCode); /*等保密码复杂度验证 end*/ if (1 == config('global.opencodetype')) { $type = input('param.type/s'); $this->assign('type', $type); } cookie('referurl', $referurl); $this->assign('referurl', $referurl); return $this->fetch('users_login'); } // 手机号登陆 public function mobile_login() { if (IS_AJAX_POST) { $post = input('post.'); if (empty($post['mobile'])){ $this->error('手机号码不能为空!', null, ['status' => 1]); } if (!check_mobile($post['mobile'])){ $this->error('手机号码格式不正确!', null, ['status' => 1]); } if (empty($post['mobile_code'])) { $this->error('验证码不能为空!', null, ['status' => 1]); } // 验证验证码 $RecordWhere = [ 'source' => 2, 'mobile' => $post['mobile'], 'code' => $post['mobile_code'], 'is_use' => 0, 'lang' => $this->home_lang ]; $is_verify = $this->sms_log_db->where($RecordWhere)->find(); if (!empty($is_verify)){ $RecordData = [ 'is_use' => 1, 'update_time' => getTime() ]; // 更新数据 $this->sms_log_db->where($RecordWhere)->update($RecordData); }else{ $this->error('验证码已失效!', null, ['status' => 1]); } $users = $this->users_db->where([ 'mobile' => $post['mobile'], 'is_del' => 0, ])->find(); if (!empty($users)) { if (!empty($users['admin_id'])) { // 后台账号不允许在前台通过账号密码登录,只能后台登录时同步到前台 $this->error('前台禁止管理员登录!', null, ['status' => 'vertify']); } if (empty($users['is_activation'])) { $this->error('该会员尚未激活,请联系管理员!', null, ['status' => 'vertify']); } // 判断是前台还是后台注册的会员,后台注册不受注册验证影响,1为后台注册,2为前台注册。 if (2 == $users['register_place']) { $usersVerificationRow = M('users_config')->where([ 'name' => 'users_verification', ])->find(); if ($usersVerificationRow['update_time'] <= $users['reg_time']) { // 判断是否需要后台审核 if ($usersVerificationRow['value'] == 1 && $users['is_activation'] == 0) { $this->error('管理员审核中,请稍等!', null, ['status' => 2]); } } } // 会员users_id存入session model('EyouUsers')->loginAfter($users); $referurl = input('param.referurl/s', null, 'htmlspecialchars_decode,urldecode'); if (empty($referurl)) { if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) { $referurl = $_SERVER['HTTP_REFERER']; } else { $referurl = url("user/Users/centre"); } } $referurl = strip_tags($referurl); session('eyou_referurl', $referurl); $users_config = getUsersConfigData('users'); if (!empty($users_config['users_login_jump_type']) && 1 == $users_config['users_login_jump_type']){ $referurl = ROOT_DIR."/";//跳到首页 }elseif (!empty($users_config['users_login_jump_type']) && 3 == $users_config['users_login_jump_type']){ $referurl = url('user/Users/centre');//跳到会员中心 }elseif (!empty($users_config['users_login_jump_type']) && 4 == $users_config['users_login_jump_type']){ $referurl = htmlspecialchars_decode($users_config['users_login_jump_url']);//跳到自定义URL $referurl = strip_tags($referurl); } // 是否绑定了微站点,否则自动绑定 auto_bind_wechatlogin($users, $referurl); $this->success('登录成功', $referurl); } else { $this->error('该用户名不存在,请注册!', null, ['status' => 'vertify']); } } $this->error('请求错误', null, ['status' => 'vertify']); } // 会员注册 public function reg() { if ($this->users_id > 0) { $url = url('user/Users/centre'); $this->redirect($url); exit; } $is_vertify = 1; // 默认开启验证码 $users_reg_captcha = config('captcha.users_reg'); if (!function_exists('imagettftext') || empty($users_reg_captcha['is_on'])) { $is_vertify = 0; // 函数不存在,不符合开启的条件 } $this->assign('is_vertify', $is_vertify); if (IS_AJAX_POST) { $post = input('post.'); if (isset($post['username'])) { $post['username'] = trim($post['username']); $users_reg_notallow = explode(',', getUsersConfigData('users.users_reg_notallow')); if (!empty($users_reg_notallow)) { if (in_array($post['username'], $users_reg_notallow)) { $this->error('用户名为系统禁止注册!', null, ['status' => 1]); } } if (empty($post['username'])) { $this->error('用户名不能为空!', null, ['status' => 1]); } else if (!preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $post['username'])) { $this->error('请输入2-30位的汉字、英文、数字、下划线等组合', null, ['status' => 1]); } } if (isset($post['password'])) { if (empty($post['password']) || !trim($post['password'])) { $this->error('登录密码不能为空!', null, ['status' => 1]); } if (empty($post['password2']) || !trim($post['password2'])) { $this->error('重复密码不能为空!', null, ['status' => 1]); } /*等保密码复杂度验证 start*/ if (is_dir('./weapp/Equal/')) { $equalLogic = new \weapp\Equal\logic\EqualLogic; $eqData = $equalLogic->pwdValidate($post['password']); if (isset($eqData['code']) && empty($eqData['code'])) { $this->error($eqData['msg']); } } /*等保密码复杂度验证 end*/ } if (1 == $is_vertify) { if (empty($post['vertify'])) { $this->error('图片验证码不能为空!', null, ['status' => 1]); } } if (isset($post['username'])) { $count = $this->users_db->where([ 'username' => $post['username'], ])->count(); if (!empty($count)) { $this->error('用户名已存在!', null, ['status' => 1]); } } if (isset($post['password'])) { $post['password'] = trim($post['password']); $post['password2'] = trim($post['password2']); if (empty($post['password']) && empty($post['password2'])) { $this->error('登录密码不能为空!', null, ['status' => 1]); } else { if ($post['password'] != $post['password2']) { $this->error('两次密码输入不一致!', null, ['status' => 1]); } } } // 处理会员属性数据 $ParaData = []; if (isset($post['users_'])) { if (is_array($post['users_'])) { $ParaData = $post['users_']; } unset($post['users_']); } // 处理提交的会员属性中必填项是否为空 // 必须传入提交的会员属性数组 $EmptyData = model('Users')->isEmpty($ParaData, 'reg', 'array'); if (!empty($EmptyData)) { if (is_array($EmptyData)) { $this->error($EmptyData['msg'], null, ['status' => 1, 'field'=>$EmptyData['field']]); } else { $this->error($EmptyData, null, ['status' => 1]); } } // 处理提交的会员属性中邮箱和手机是否已存在 // IsRequired方法传入的参数有2个 // 第一个必须传入提交的会员属性数组 // 第二个users_id,注册时不需要传入,修改时需要传入。 $RequiredData = model('Users')->isRequired($ParaData, '', 'reg'); if (!empty($RequiredData) && !is_array($RequiredData)) { $this->error($RequiredData, null, ['status' => 1]); } // 处理判断验证码 if (1 == $is_vertify) { $verify = new Verify(); if (!$verify->check($post['vertify'], "users_reg")) { $this->error('图片验证码错误', null, ['status' => 'vertify']); } } if (is_dir('./weapp/UCenter/')) { $ucenter = new \weapp\UCenter\logic\UCenterLogic(); $ucenter->uc_reg_synlogin($post, $RequiredData); } if (!empty($RequiredData['email'])) { // 查询会员输入的邮箱并且为找回密码来源的所有验证码 $RecordWhere = [ 'source' => 2, 'email' => $RequiredData['email'], 'users_id' => 0, 'status' => 0, 'lang' => $this->home_lang, ]; $RecordData = [ 'status' => 1, 'update_time' => getTime(), ]; // 更新数据 $this->smtp_record_db->where($RecordWhere)->update($RecordData); } if (!empty($RequiredData['mobile'])) { // 查询会员输入的邮箱并且为找回密码来源的所有验证码 $RecordWhere = [ 'source' => 0, 'mobile' => $RequiredData['mobile'], 'is_use' => 0, 'lang' => $this->home_lang ]; $RecordData = [ 'is_use' => 1, 'update_time' => getTime() ]; // 更新数据 $this->sms_log_db->where($RecordWhere)->update($RecordData); } // 会员设置 $users_verification = !empty($this->usersConfig['users_verification']) ? $this->usersConfig['users_verification'] : 0; // 处理判断是否为后台审核,verification=1为后台审核。 if (1 == $users_verification) $data['is_activation'] = 0; // 添加会员到会员表 $data['username'] = !empty($post['username']) ? trim($post['username']) : 'yun'.getTime().rand(0,100); $data['nickname'] = !empty($post['nickname']) ? $post['nickname'] : $data['username']; if (0 == config('global.opencodetype')) { $data['password'] = func_encrypt($post['password'], false, pwd_encry_type('bcrypt')); } $data['is_mobile'] = !empty($ParaData['mobile_1']) ? 1 : 0; $data['is_email'] = !empty($ParaData['email_2']) ? 1 : 0; $data['head_pic'] = ROOT_DIR . '/public/static/common/images/dfboy.png'; $data['reg_time'] = getTime(); $data['last_login'] = getTime(); $data['last_ip'] = clientIP(); $data['register_place'] = 2; // 注册位置,后台注册不受注册验证影响,1为后台注册,2为前台注册。 $data['lang'] = $this->home_lang; //来源 if (isMobile()){ if (isWeixin()){ $data['source'] = 3;//1-PC端 2-H5 3-微信公众号/微站点 4-微信小程序 5-百度小程序 6-抖音小程序 }else{ $data['source'] = 2;//1-PC端 2-H5 3-微信公众号 4-微信小程序 5-百度小程序 6-抖音小程序 } } $level_id = $this->users_level_db->where([ 'is_system' => 1, ])->getField('level_id'); $data['level'] = $level_id; /*特定场景专用*/ $opencodetype = config('global.opencodetype'); if (1 == $opencodetype) { $origin_mid = cookie('origin_mid'); if (!empty($origin_mid)) { $data['origin_mid'] = intval($origin_mid); } $origin_type = cookie('origin_type'); if (!empty($origin_type)) { $data['origin_type'] = intval($origin_type); } } /*end*/ $users_id = $this->users_db->insertGetId($data); // 判断会员是否添加成功 if (!empty($users_id)) { $data['users_id'] = $users_id; // 批量添加会员属性到属性信息表 if (!empty($ParaData)) { $betchData = []; $usersparaRow = $this->users_parameter_db->where([ 'is_hidden' => 0, ])->getAllWithIndex('name'); foreach ($ParaData as $key => $value) { if (preg_match('/(_code|_vertify)$/i', $key)) { continue; }elseif ('imgs' == $usersparaRow[$key]['dtype']){ $value = array_filter($value); } // 若为数组,则拆分成字符串 if (is_array($value)) $value = implode(',', $value); $para_id = intval($usersparaRow[$key]['para_id']); $betchData[] = [ 'users_id' => $users_id, 'para_id' => $para_id, 'info' => $value, 'lang' => $this->home_lang, 'add_time' => getTime(), ]; } $this->users_list_db->insertAll($betchData); } // 查询属性表的手机号码和邮箱地址,拼装数组$UsersListData $UsersListData = model('Users')->getUsersListData('*', $users_id); $UsersListData['login_count'] = 1; $UsersListData['update_time'] = getTime(); if (2 == $users_verification) { // 若开启邮箱验证并且通过邮箱验证则绑定到会员 $UsersListData['is_email'] = 1; if (!isset($post['username'])) { $username = rand_username(); $UsersListData['username'] = $username; $UsersListData['nickname'] = $username; } } else if (3 == $users_verification) { // 若开启手机验证并且通过手机验证则绑定到会员 $UsersListData['is_mobile'] = 1; if (!isset($post['username'])) { $new_username = 'yun'.substr($UsersListData['mobile'], -6); $username = rand_username($new_username, 'yun', 2); $UsersListData['username'] = $username; $UsersListData['nickname'] = $username; } } // 同步修改会员信息 $this->users_db->where('users_id', $users_id)->update($UsersListData); // 回跳路径 $referurl = input('post.referurl/s', null, 'htmlspecialchars_decode,urldecode'); $referurl = strip_tags($referurl); if (1 == config('global.opencodetype')) { cookie('origin_type', null); cookie('origin_mid', null); } session('users_id', $users_id); if (session('users_id')) { cookie('users_id', $users_id); if (empty($users_verification)) { // 无需审核,直接登陆 $url = !empty($referurl) ? $referurl : url('user/Users/centre'); // 是否绑定了微站点,否则自动绑定 auto_bind_wechatlogin($data, $url); $this->success('注册成功,正在跳转中……', $url, ['status' => 3]); } else if (1 == $users_verification) { // 需要后台审核 session('users_id', null); $url = url('user/Users/login'); $this->success('注册成功,等管理员激活才能登录!', $url, ['status' => 2]); } else if (2 == $users_verification) { // 注册成功 $url = !empty($referurl) ? $referurl : url('user/Users/centre'); // 是否绑定了微站点,否则自动绑定 auto_bind_wechatlogin($data, $url); $this->success('注册成功,正在跳转中……', $url, ['status' => 0]); } else if (3 == $users_verification) { // 注册成功 $url = !empty($referurl) ? $referurl : url('user/Users/centre'); // 是否绑定了微站点,否则自动绑定 auto_bind_wechatlogin($data, $url); $this->success('注册成功,正在跳转中……', $url, ['status' => 0]); } } else { $url = url('user/Users/login'); $this->success('注册成功,请登录!', $url, ['status' => 2]); } } $this->error('注册失败', null, ['status' => 4]); } // 会员属性资料信息 $users_para = model('Users')->getDataPara('reg'); $this->assign('users_para', $users_para); // 跳转链接 $referurl = input('param.referurl/s'); if (empty($referurl)) { if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) { $referurl = $_SERVER['HTTP_REFERER']; } else { $referurl = url("user/Users/centre"); } } else { $referurl = urldecode($referurl); } $referurl = strip_tags($referurl); cookie('referurl', $referurl); $this->assign('referurl', $referurl); /*微信登录插件 - 判断是否显示微信登录按钮*/ $weapp_wxlogin = 0; if (is_dir('./weapp/WxLogin/')) { $wx = Db::name('weapp')->field('data,status,config')->where(['code' => 'WxLogin'])->find(); $wx['data'] = unserialize($wx['data']); if ($wx['status'] == 1 && $wx['data']['login_show'] == 1) { $weapp_wxlogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $wx['config'] = json_decode($wx['config'], true); if (isMobile() && !in_array($wx['config']['scene'], [0,1])) { $weapp_wxlogin = 0; } else if (!isMobile() && !in_array($wx['config']['scene'], [0,2])) { $weapp_wxlogin = 0; } } $this->assign('weapp_wxlogin', $weapp_wxlogin); /*end*/ /*QQ登录插件 - 判断是否显示QQ登录按钮*/ $weapp_qqlogin = 0; if (is_dir('./weapp/QqLogin/')) { $qq = Db::name('weapp')->field('data,status,config')->where(['code' => 'QqLogin'])->find(); $qq['data'] = unserialize($qq['data']); if ($qq['status'] == 1 && $qq['data']['login_show'] == 1) { $weapp_qqlogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $qq['config'] = json_decode($qq['config'], true); if (isMobile() && !in_array($qq['config']['scene'], [0,1])) { $weapp_qqlogin = 0; } else if (!isMobile() && !in_array($qq['config']['scene'], [0,2])) { $weapp_qqlogin = 0; } } $this->assign('weapp_qqlogin', $weapp_qqlogin); /*end*/ /*微博插件 - 判断是否显示微博按钮*/ $weapp_wblogin = 0; if (is_dir('./weapp/Wblogin/')) { $wb = Db::name('weapp')->field('data,status,config')->where(['code' => 'Wblogin'])->find(); $wb['data'] = unserialize($wb['data']); if ($wb['status'] == 1 && $wb['data']['login_show'] == 1) { $weapp_wblogin = 1; } // 使用场景 0 PC+手机 1 手机 2 PC $wb['config'] = json_decode($wb['config'], true); if (isMobile() && !in_array($wb['config']['scene'], [0,1])) { $weapp_wblogin = 0; } else if (!isMobile() && !in_array($wb['config']['scene'], [0,2])) { $weapp_wblogin = 0; } } $this->assign('weapp_wblogin', $weapp_wblogin); /*end*/ /*等保密码复杂度验证 start*/ $pwdJsCode = ''; if (is_dir('./weapp/Equal/')) { $equalLogic = new \weapp\Equal\logic\EqualLogic; $pwdJsCode = $equalLogic->pwdJsCode(); } if ('close' == $pwdJsCode) { $pwdJsCode = ''; } $this->assign('pwdJsCode', $pwdJsCode); /*等保密码复杂度验证 end*/ $html = $this->fetch('users_reg'); if (!empty($pwdJsCode) && !stristr($html, "var password_value = $.trim(password.val());")) { $str = <<