/** * 完善第三方登录用户信息 * @return [type] [description] */ public function ologinPrefect() { $post = I('post.'); // 验证手机号 $mobile = I('post.mobile'); if (strlen($mobile) != 11) { $this->return['code'] = 1001; $this->return['message'] = L('mobile_error'); $this->goJson($this->return); } if ($this->checkMobile($mobile)) { $this->return['code'] = 1002; $this->return['message'] = L('mobile_has'); $this->goJson($this->return); } // 验证昵称 if (!$post['uname']) { $this->return['code'] = 1003; $this->return['message'] = L('uname_null'); $this->goJson($this->return); } // 验证性别 if ($post['sex'] != 1 && $post['sex'] != 2) { $this->return['code'] = 1004; $this->return['message'] = L('sex_error'); $this->goJson($this->return); } load("@.user"); $post['first_letter'] = getFirstLetter($post['uname']); //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) { import("Common.Util.PinYin"); $pinyinClass = new \PinYin(); $pinyin = $pinyinClass->Pinyin($post['uname']); //昵称和呢称拼音保存到搜索字段 $post['search_key'] = $post['uname'] . ' ' . $pinyin; } else { $post['search_key'] = $post['uname']; } // 密码 if (!$post['password']) { $this->return['code'] = 1004; $this->return['message'] = L('pwd_null'); $this->goJson($this->return); } $post['login_salt'] = rand(11111, 99999); $post['password'] = md5(md5($post['password']) . $post['login_salt']); $post['ctime'] = time(); $post['level'] = $post['self_level']; $post['cur_language'] = $post['lid']; D('userinfo')->where('uid=' . $this->mid)->save($post); $language_info['uid'] = $this->mid; $language_info['lid'] = $post['lid']; $language_info['type'] = 4; $language_info['self_level'] = $post['self_level']; D('userLanguage')->add($language_info); $this->redis->Sadd('User:sex' . $post['sex'], $this->mid); $this->redis->SADD('Userinfo:online', $this->mid); //在线用户列表 $this->createSubAccount('yujia' . $this->mid, $this->mid); $res = D('userinfo')->getUserInfo($this->mid); $this->redis->HMSET('Userinfo:uid' . $this->mid, $res); $res['token'] = I('post.token'); $tmp['headimg'] = json_decode($this->redis->HGET('Userinfo:uid' . $this->mid, 'headimg'), true); $tmp['headimg'] = $tmp['headimg'][0]['url']; $return = array('uid' => $this->mid, 'token' => $res['token'], 'voipaccount' => $res['voipaccount'], 'voippwd' => $res['voippwd'], 'subaccountid' => $res['subaccountid'], 'subtoken' => $res['subtoken'], 'uname' => $res['uname'], 'mobile' => $res['mobile'], 'sex' => $res['sex'], 'headimg' => $tmp['headimg']); $this->return['data'] = $return; $this->goJson($this->return); }
public function pinyin() { $name = I('name'); $preg = '/^[\\x81-\\xfe][\\x40-\\xfe]+$/'; if (preg_match($preg, $name)) { import('Common/Org/Util/PinYin'); $pinyin = new \PinYin(); $name = $pinyin->Pinyin($name, 1); } echo $name; }
exit; } else { $data = array(); foreach ($user_list as &$value) { if (empty($value['email'])) { $value['email'] = 'ts_' . $value['uid'] . '@thinksns.com'; } $salt = rand(11111, 99999); $salt = mysql_escape_string($salt); $password = md5($value['password'] . $salt); $password = mysql_escape_string($password); $sex = $value['sex'] == 1 ? 1 : 2; $sex = mysql_escape_string($sex); $first_letter = getFirstLetter($value['uname']); $first_letter = mysql_escape_string($first_letter); $search_key = $value['uname'] . ' ' . $Py->Pinyin($value['uname']); $search_key = mysql_escape_string($search_key); $value = updateValue($value); $data[] = "('" . $value['uid'] . "','" . $value['email'] . "','" . $password . "','" . $salt . "','" . $value['uname'] . "','" . $value['email'] . "','" . $sex . "','" . $value['location'] . "','1','" . $value['is_active'] . "','" . $value['is_init'] . "','" . $value['ctime'] . "','1',null,'" . $value['domain'] . "','" . $value['province'] . "','" . $value['city'] . "','0', '127.0.0.1', 'zh-cn', 'PRC', '0', '" . $first_letter . "', '', null, null, '0', '" . $search_key . "', null, 0, 0)"; // 添加用户组信息 - todo $user_group_link_sql = 'SELECT * FROM `' . $old_db_conf['DB_PREFIX'] . 'user_group_link` WHERE `uid` = ' . $value['uid'] . ' LIMIT 1'; $user_group_info = $old_db->query($user_group_link_sql); // 获取管理用户组 $admin_group_sql = 'SELECT p.* FROM `' . $old_db_conf['DB_PREFIX'] . 'user_group_popedom` AS p LEFT JOIN `' . $old_db_conf['DB_PREFIX'] . 'node` AS n ON p.`node_id` = n.`node_id` WHERE n.`app_name` = \'admin\' AND n.`mod_name` = \'*\' AND n.`act_name` = \'*\''; $admin_group_info = $old_db->query($admin_group_sql); if (empty($user_group_info) || $user_group_info[0]['user_group_id'] != $admin_group_info[0]['user_group_id']) { $user_group_data[] = "(null, '" . $value['uid'] . "', '3')"; } else { if ($user_group_info[0]['user_group_id'] == $admin_group_info[0]['user_group_id']) { $user_group_data[] = "('" . $user_group_info[0]['id'] . "', '" . $user_group_info[0]['uid'] . "', '1')"; }
/** * 保存用户信息 * @return [type] [description] */ public function saveInfo() { $post = I('post.'); $o_info = $this->redis->HGETALL('Userinfo:uid' . $this->mid); $info = array(); //头像 $o_headimg = json_decode($o_info['headimg'], true) ? json_decode($o_info['headimg'], true) : array(); $o_headimg_ids = getSubByKey($o_headimg, 'rid'); $o_headimg_str = $o_headimg_ids ? implode(',', $o_headimg_ids) : ''; if ($o_headimg_str != trim($post['headimg'], ',') && isset($post['headimg'])) { $info['headimg'] = trim($post['headimg'], ','); $headimg_arr = explode(',', $info['headimg']); foreach ($headimg_arr as $v) { $photo_res = array(); $photo_res['rid'] = $v; $photo_res['url'] = C('WEBSITE_URL') . D('picture')->where('id=' . $v)->getField('path'); $photo[] = $photo_res; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'headimg', json_encode($photo, JSON_UNESCAPED_UNICODE)); $new_photo = explode(',', trim($post['headimg'], ',')) ? explode(',', trim($post['headimg'], ',')) : array(); $o_headimg_ids = $o_headimg_ids ? $o_headimg_ids : array(); $add_photo = array_diff($new_photo, $o_headimg_ids); if ($add_photo) { $sj_log['uid'] = $this->mid; $sj_log['type'] = 1; foreach ($add_photo as $v) { $sj_log['url'] = D('picture')->where('id=' . $v)->getField('path'); D('shunjian')->add($sj_log); } } } //昵称 if ($post['uname'] != $o_info['uname'] && isset($post['uname'])) { if ($post['uname'] == '') { $this->return['code'] == 1004; $this->return['message'] == L('uname_null'); $this->goJson($this->return); } $info['uname'] = $post['uname']; load("@.user"); $info['first_letter'] = getFirstLetter($post['uname']); //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) { import("Common.Util.PinYin"); $pinyinClass = new \PinYin(); $pinyin = $pinyinClass->Pinyin($post['uname']); //昵称和呢称拼音保存到搜索字段 $info['search_key'] = $post['uname'] . ' ' . $pinyin; } else { $info['search_key'] = $post['uname']; } } // 性别 if ($post['sex'] != $o_info['sex'] && isset($post['sex'])) { if ($post['sex'] != 1 && $post['sex'] != 2) { $this->return['code'] == 1003; $this->return['message'] == L('sex_error'); $this->goJson($this->return); } $info['sex'] = $post['sex']; $sex_flag = $post['sex'] == 1 ? 2 : 1; $this->redis->sRem('User:sex' . $sex_flag, $this->mid); $this->redis->sAdd('User:sex' . $info['sex'], $this->mid); } // 个性签名 if ($post['intro'] != $o_info['intro'] && isset($post['intro'])) { $info['intro'] = $post['intro']; } // 视频介绍 $o_info['video_profile'] = json_decode($o_info['video_profile'], true) ? json_decode($o_info['video_profile'], true) : array(); if ($post['video_profile'] != $o_info['video_profile']['rid'] && isset($post['video_profile'])) { $info['video_profile'] = $post['video_profile']; $video = D('file')->field('savepath, savename')->where('id=' . $post['video_profile'])->find(); $video_profile['rid'] = $post['video_profile']; $video_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $video['savepath'] . $video['savename']; $this->redis->HSET('Userinfo:uid' . $this->mid, 'video_profile', json_encode($video_profile, JSON_UNESCAPED_UNICODE)); $video_profile_data['type'] = 2; $video_profile_data['url'] = '/Uploads/File/' . $video['savepath'] . $video['savename']; $video_profile_data['uid'] = $this->mid; D('shunjian')->add($video_profile_data); unset($video_profile_data); } // 音频介绍 $o_info['audio_profile'] = json_decode($o_info['audio_profile'], true) ? json_decode($o_info['audio_profile'], true) : array(); if ($post['audio_profile'] != $o_info['audio_profile']['rid'] && $post['audio_profile']) { $info['audio_profile'] = $post['audio_profile']; $audio = D('file')->field('savepath, savename')->where('id=' . $post['audio_profile'])->find(); $audio_profile['rid'] = $post['audio_profile']; $audio_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $audio['savepath'] . $audio['savename']; $this->redis->HSET('Userinfo:uid' . $this->mid, 'audio_profile', json_encode($audio_profile, JSON_UNESCAPED_UNICODE)); } // 国家,省,城市信息 if (isset($post['country']) && $post['country'] != 0) { if ($post['country'] != $o_info['country']) { $info['country'] = $post['country']; $info['province'] = $post['province']; $info['city'] = $post['city']; $info['location'] = $post['location']; } elseif ($post['province'] != $o_info['province'] && isset($post['province'])) { $info['province'] = $post['province']; $info['city'] = $post['city']; $info['location'] = $post['location']; } elseif ($post['city'] != $o_info['city'] && isset($post['city'])) { $info['city'] = $post['city']; $info['location'] = $post['location']; } } //语言 更改 $o_language = json_decode($o_info['language'], true) ? json_decode($o_info['language'], true) : array(); if ($post['language']['lid'] != $o_language['lid'] && isset($post['language']['lid'])) { $info['cur_language'] = $language['lid'] = $post['language']['lid']; } if ($post['language']['self_level'] != $o_language['self_level'] && isset($post['language']['self_level'])) { $info['level'] = $language['self_level'] = $post['language']['self_level']; } if (count($language)) { D('userLanguage')->where('uid=' . $this->mid)->save($language); $language = D('userLanguage')->where('uid=' . $this->mid)->field('lid, type, sys_level, self_level')->select(); $allLanguage = D('language')->getAllLanguage(); foreach ($language as $k => $v) { $language[$k]['language_name'] = $allLanguage[$v['lid']]; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'language', json_encode($language, JSON_UNESCAPED_UNICODE)); } if (count($info)) { D('userinfo')->where('uid=' . $this->mid)->save($info); unset($info['video_profile'], $info['headimg'], $info['audio_profile']); foreach ($info as $k => $v) { $this->redis->HSET('Userinfo:uid' . $this->mid, $k, $v); } } //标签 if (isset($post['tags'])) { $o_tags = json_decode($o_info['tags']) ? json_decode($o_info['tags'], true) : array(); $o_tag_ids = getSubByKey($o_tags, 'tid'); $tags_post = explode(',', $post['tags']); if (!count($tags_post)) { D('userTags')->where('uid=' . $this->mid)->delete(); } else { $tags['uid'] = $this->mid; //有新增标签 $add_tags = array_diff($tags_post, $o_tag_ids); if (count($add_tags)) { foreach ($add_tags as $v) { $tags['tid'] = $v; D('userTags')->add($tags); } } //有删除标签 $delete_tags = array_diff($o_tag_ids, $tags_post); if (count($delete_tags)) { foreach ($delete_tags as $v) { D('userTags')->where('uid=' . $this->mid . ' and tid=' . $v)->delete(); } } //如果有变化,取出该用户全部标签进行缓存 if (count($delete_tags) || count($add_tags)) { $allTags = D('tags')->getAllTags(); $tags_res = D('userTags')->field('tid')->where('uid=' . $this->mid)->select(); foreach ($tags_res as $k => $val) { $tags_res[$k]['tag_name'] = $allTags[$val['tid']]; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'tags', json_encode($tags_res, JSON_UNESCAPED_UNICODE)); } } } //$this->return['data'] = $this->getUserinfoData($this->mid); $this->goJson($this->return); }