/** * 按照层级获取地区列表 * * @request int $pid 地区ID * @param bool $notsort 是否不排序,默认排序 * @return array * @author Seven Du <*****@*****.**> **/ public function getArea() { $pid = intval($this->data['pid']); $pid or $pid = 0; isset($this->data['notsort']) or $notsort = false; $notsort = (bool) $this->data['notsort']; $list = model('Area')->getAreaList($pid); if ($notsort) { return $list; } $areas = array(); foreach ($list as $area) { $pre = getShortPinyin($area['title'], 'utf-8', '#'); /* 多音字处理 */ if ($area['title'] == '重庆') { $pre = 'C'; } if (!isset($areas[$pre]) or !is_array($areas[$pre])) { $areas[$pre] = array(); } array_push($areas[$pre], $area); } ksort($areas); return $areas; }
/** * 保存基本信息操作 * * @return json 返回操作后的JSON信息数据 */ public function doSaveProfile() { $res = true; // 保存用户表信息 if (!empty($_POST['sex'])) { $save['sex'] = 1 == intval($_POST['sex']) ? 1 : 2; // $save['lang'] = t($_POST['lang']); $save['intro'] = t($_POST['intro']); /* # 检查用户简介是否超出字数限制 */ if (get_str_length($save['intro']) > 150) { $this->ajaxReturn(null, '个人简介不得超过150字', 0); } // 添加地区信息 $save['location'] = t($_POST['city_names']); $cityIds = t($_POST['city_ids']); $cityIds = explode(',', $cityIds); /* if (! $cityIds [0] || ! $cityIds [1] || ! $cityIds [2]) $this->error ( '请选择完整地区' ); */ isset($cityIds[0]) && ($save['province'] = intval($cityIds[0])); if ($_POST['input_city'] != '') { $save['input_city'] = t($_POST['input_city']); $save['city'] = 0; $save['area'] = 0; } else { isset($cityIds[1]) && ($save['city'] = intval($cityIds[1])); isset($cityIds[2]) && ($save['area'] = intval($cityIds[2])); } // 修改用户昵称 $uname = t($_POST['uname']); $oldName = t($_POST['old_name']); $save['uname'] = filter_keyword($uname); $res = model('Register')->isValidName($uname, $oldName); if (!$res) { $error = model('Register')->getLastError(); return $this->ajaxReturn(null, model('Register')->getLastError(), $res); } // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } /* 用户首字母 */ $save['first_letter'] = getShortPinyin($save['uname']); $res = model('User')->where("`uid`={$this->mid}")->save($save); $res && model('User')->cleanCache($this->mid); $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } } // 保存用户资料配置字段 false !== $res && ($res = $this->_profile_model->saveUserProfile($this->mid, $_POST)); // 保存用户标签信息 $tagIds = t($_REQUEST['user_tags']); // 注册配置信息 $this->_config = model('Xdata')->get('admin_Config:register'); if (!empty($tagIds)) { $tagIds = explode(',', $tagIds); $rowId = intval($this->mid); if (!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if (count($tagIds) > $registerConfig['tag_num']) { return $this->ajaxReturn(null, '最多只能设置' . $registerConfig['tag_num'] . '个标签', false); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } } else { if (empty($tagIds) && isset($_REQUEST['user_tags'])) { return $this->ajaxReturn(null, '请至少选择一个标签', false); } } $result = $this->ajaxReturn(null, $this->_profile_model->getError(), $res); return $this->ajaxReturn(null, $this->_profile_model->getError(), $res); }
function getFirstLetter($s0) { /* 兼容以前 */ return getShortPinyin($s0, 'utf-8', '#'); }