/** * 获取用户帐号信息 * * @access public * @param int $user_id 用户user_id * * @return void */ function get_profile($user_id) { /* 会员帐号信息 */ $info = array(); $infos = array(); $sql = "SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank," . " msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer " . "FROM " . $this->pre . "users WHERE user_id = '{$user_id}'"; $infos = $this->row($sql); $infos['user_name'] = addslashes($infos['user_name']); $row = ECTouch::user()->get_profile_by_name($infos['user_name']); //获取用户帐号信息 $_SESSION['email'] = $row['email']; //注册SESSION /* 会员等级 */ if ($infos['user_rank'] > 0) { $sql = "SELECT rank_id, rank_name, discount FROM " . $this->pre . "user_rank WHERE rank_id = '{$infos['user_rank']}'"; } else { $sql = "SELECT rank_id, rank_name, discount, min_points" . " FROM " . $this->pre . "user_rank WHERE min_points<= " . intval($infos['rank_points']) . " ORDER BY min_points DESC"; } if ($row = $this->row($sql)) { $info['rank_name'] = $row['rank_name']; } else { $info['rank_name'] = L('undifine_rank'); } $cur_date = date('Y-m-d H:i:s'); /* 会员红包 */ $bonus = array(); $sql = "SELECT type_name, type_money " . "FROM " . $this->pre . "bonus_type AS t1, " . $this->pre . "user_bonus AS t2 " . "WHERE t1.type_id = t2.bonus_type_id AND t2.user_id = '{$user_id}' AND t1.use_start_date <= '{$cur_date}' " . "AND t1.use_end_date > '{$cur_date}' AND t2.order_id = 0"; $bonus = $this->query($sql); if ($bonus) { for ($i = 0, $count = count($bonus); $i < $count; $i++) { $bonus[$i]['type_money'] = price_format($bonus[$i]['type_money'], false); } } $info['discount'] = $_SESSION['discount'] * 100 . "%"; $info['email'] = $_SESSION['email']; $info['user_name'] = $_SESSION['user_name']; $info['rank_points'] = isset($infos['rank_points']) ? $infos['rank_points'] : ''; $info['pay_points'] = isset($infos['pay_points']) ? $infos['pay_points'] : 0; $info['user_money'] = isset($infos['user_money']) ? $infos['user_money'] : 0; $info['sex'] = isset($infos['sex']) ? $infos['sex'] : 0; $info['birthday'] = isset($infos['birthday']) ? $infos['birthday'] : ''; $info['question'] = isset($infos['question']) ? htmlspecialchars($infos['question']) : ''; $info['user_money'] = price_format($info['user_money'], false); $info['pay_points'] = $info['pay_points'] . C('integral_name'); $info['bonus'] = $bonus; $info['qq'] = $infos['qq']; $info['msn'] = $infos['msn']; $info['office_phone'] = $infos['office_phone']; $info['home_phone'] = $infos['home_phone']; $info['mobile_phone'] = $infos['mobile_phone']; $info['passwd_question'] = $infos['passwd_question']; $info['passwd_answer'] = $infos['passwd_answer']; return $info; }
/** * 获取用户帐号信息 * * @access public * @param int $user_id 用户user_id * * @return void */ function get_profile($user_id) { /* 会员帐号信息 */ $info = array(); $infos = array(); $sql = "SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank," . " msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer " . "FROM " . $this->pre . "users WHERE user_id = '{$user_id}'"; $infos = $this->row($sql); $infos['user_name'] = addslashes($infos['user_name']); $row = ECTouch::user()->get_profile_by_name($infos['user_name']); //获取用户帐号信息 $_SESSION['email'] = $row['email']; //注册SESSION /* 会员等级 */ if ($infos['user_rank'] > 0) { $sql = "SELECT rank_id, rank_name, discount FROM " . $this->pre . "user_rank WHERE rank_id = '{$infos['user_rank']}'"; } else { $sql = "SELECT rank_id, rank_name, discount, min_points" . " FROM " . $this->pre . "user_rank WHERE min_points<= " . intval($infos['rank_points']) . " ORDER BY min_points DESC"; } if ($row = $this->row($sql)) { $info['rank_name'] = $row['rank_name']; } else { $info['rank_name'] = L('undifine_rank'); } $cur_date = date('Y-m-d H:i:s'); $info['discount'] = $_SESSION['discount'] * 100 . "%"; $info['email'] = $_SESSION['email']; $info['user_name'] = $_SESSION['user_name']; $info['rank_points'] = isset($infos['rank_points']) ? $infos['rank_points'] : ''; $info['pay_points'] = isset($infos['pay_points']) ? $infos['pay_points'] : 0; $info['user_money'] = isset($infos['user_money']) ? $infos['user_money'] : 0; $info['sex'] = isset($infos['sex']) ? $infos['sex'] : 0; $info['birthday'] = isset($infos['birthday']) ? $infos['birthday'] : ''; $info['question'] = isset($infos['question']) ? htmlspecialchars($infos['question']) : ''; $info['user_money'] = price_format($info['user_money'], false); $info['pay_points'] = $info['pay_points'] . C('integral_name'); $info['qq'] = $infos['qq']; $info['msn'] = $infos['msn']; $info['office_phone'] = $infos['office_phone']; $info['home_phone'] = $infos['home_phone']; $info['mobile_phone'] = $infos['mobile_phone']; $info['passwd_question'] = $infos['passwd_question']; $info['passwd_answer'] = $infos['passwd_answer']; return $info; }
/** * 会员找回密码时,对输入的用户名和邮件地址匹配 * * @access public * @param string $user_name 用户帐号 * @param string $email 用户Email * * @return boolen */ function check_userinfo($user_name, $email) { if (empty($user_name) || empty($email)) { ecs_header("Location: user.php?act=get_password\n"); exit; } /* 检测用户名和邮件地址是否匹配 */ $user_info = ECTouch::user()->check_pwd_info($user_name, $email); if (!empty($user_info)) { return $user_info; } else { return false; } }
/** * 更新微信用户信息 * * @param unknown $userinfo * @param unknown $wechat_id * @param unknown $weObj */ static function update_weixin_user($userinfo, $wechat_id, $weObj) { $time = time(); $ret = model('Base')->model->table('wechat_user')->field('openid, ect_uid')->where('openid = "' . $userinfo['openid'] . '"')->find(); if (empty($ret)) { // 获取用户所在分组ID $group_id = $weObj->getUserGroup($userinfo['openid']); $group_id = $group_id ? $group_id : 0; //微信用户绑定会员id $ect_uid = 0; //查看公众号是否绑定 if ($userinfo['unionid']) { $ect_uid = model('Base')->model->table('wechat_user')->field('ect_uid')->where(array('unionid' => $userinfo['unionid']))->getOne(); } //未绑定 if (empty($ect_uid)) { // 设置的用户注册信息 $register = model('Base')->model->table('wechat_extend')->field('config')->where('enable = 1 and command = "register_remind" and wechat_id = ' . $wechat_id)->find(); if (!empty($register)) { $reg_config = unserialize($register['config']); $username = msubstr($reg_config['user_pre'], 3, 0, 'utf-8', false) . time() . mt_rand(1, 99); // 密码随机数 $rs = array(); $arr = range(0, 9); $reg_config['pwd_rand'] = $reg_config['pwd_rand'] ? $reg_config['pwd_rand'] : 3; for ($i = 0; $i < $reg_config['pwd_rand']; $i++) { $rs[] = array_rand($arr); } $pwd_rand = implode('', $rs); // 密码 $password = $reg_config['pwd_pre'] . $pwd_rand; // 通知模版 $template = str_replace(array('[$username]', '[$password]'), array($username, $password), $reg_config['template']); } else { $username = '******' . time() . mt_rand(1, 99); $password = '******'; // 通知模版 $template = '默认用户名:' . $username . "\r\n" . '默认密码:' . $password; } // 会员注册 $domain = get_top_domain(); if (model('Users')->register($username, $password, $username . '@' . $domain) !== false) { $data['user_rank'] = 99; if (session('sale_id')) { $data['parent_id'] = session('sale_id'); } model('Base')->model->table('users')->data($data)->where('user_name = "' . $username . '"')->update(); } else { die('授权失败,如重试一次还未解决问题请联系管理员'); } $data1['ect_uid'] = $_SESSION['user_id']; } else { //已绑定 $username = model('Base')->model->table('users')->field('user_name')->where(array('user_id' => $ect_uid))->getOne(); $template = '您已拥有帐号,用户名为' . $username; $data1['ect_uid'] = $ect_uid; } $data1['wechat_id'] = $wechat_id; $data1['subscribe'] = 1; $data1['openid'] = $userinfo['openid']; $data1['nickname'] = $userinfo['nickname']; $data1['sex'] = $userinfo['sex']; $data1['city'] = $userinfo['city']; $data1['country'] = $userinfo['country']; $data1['province'] = $userinfo['province']; $data1['language'] = $userinfo['country']; $data1['headimgurl'] = $userinfo['headimgurl']; $data1['subscribe_time'] = $time; $data1['group_id'] = $group_id; $data1['unionid'] = $userinfo['unionid']; model('Base')->model->table('wechat_user')->data($data1)->insert(); // 微信端发送消息 $msg = array('touser' => $userinfo['openid'], 'msgtype' => 'text', 'text' => array('content' => $template)); $weObj->sendCustomMessage($msg); } else { //开放平台有privilege字段,公众平台没有 unset($userinfo['privilege']); $userinfo['subscribe'] = 1; model('Base')->model->table('wechat_user')->data($userinfo)->where('openid = "' . $userinfo['openid'] . '"')->update(); $new_user_name = model('Base')->model->table('users')->field('user_name')->where('user_id = "' . $ret['ect_uid'] . '"')->getOne(); ECTouch::user()->set_session($new_user_name); ECTouch::user()->set_cookie($new_user_name); model('Users')->update_user_info(); } // 推送量 model('Base')->model->table('wechat')->data('oauth_count = oauth_count + 1')->where('default_wx = 1 and status = 1')->update(); session('openid', $userinfo['openid']); }