Example #1
0
 /**
  * 获取定位城市列表.
  * 
  * @access public
  * @return mixed $innerCall 为 TRUE 有返回值.
  */
 public function getPositionList()
 {
     $countryId = (int) I('post.countryId', '');
     if ($countryId < 1) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $model = new CityModel();
     $hotCitys = $model->fetchHotList($countryId);
     $cityLists = $model->formatList($model->fetchListByCountry($countryId));
     $data = ['hotCitys' => $hotCitys, 'cityList' => $cityLists];
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $data)->myAjaxReturn();
 }
Example #2
0
 /**
  * 检查发布的城市是否有效.
  * 
  * @access private
  * @param string $cityName 城市名称.
  * @return array 无效时抛异常.
  */
 private function _checkCity($cityName)
 {
     $cityName = (string) $cityName;
     if (empty($cityName)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     $modelCity = new CityModel();
     // 城市模型.
     $cityInfo = $modelCity->fetchNameByName($cityName);
     unset($modelCity);
     if (NULL === $cityInfo) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     return $cityInfo;
 }
Example #3
0
 /**
  * 获取定位国家列表.
  * 
  * @access public
  * @return void
  */
 public function getPositionList()
 {
     // 默认国家 id.
     $defaultCountryId = C('select_city_default_country');
     $model = new CountryModel();
     // 定位国家列表.
     $lists = $model->fetchPositionList();
     $modelCity = new CityModel();
     // 热门城市列表.
     $hotCitys = $modelCity->fetchHotList($defaultCountryId);
     // 城市列表.
     $cityLists = $modelCity->formatList($modelCity->fetchListByCountry($defaultCountryId));
     $data = ['defaultCountry' => $defaultCountryId, 'countryList' => $lists, 'hotCitys' => $hotCitys, 'cityList' => $cityLists];
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $data)->myAjaxReturn();
 }
Example #4
0
 /**
  * 初始化.
  * 检查是否有 appid 的参数.
  * 
  * @access protected
  * @return void
  */
 protected function _initialize()
 {
     $ip = get_client_ip();
     $controllerName = CONTROLLER_NAME;
     $acname = ACTION_NAME;
     $modname = MODULE_NAME;
     if (!in_array(ACTION_NAME, $this->noCheckTokenActions, TRUE)) {
         //$url = $_SERVER['REQUEST_URI'];
         //$get = $_GET;
         $appid = I('get.' . C('var_app_id'), '');
         $token = I('get.' . C('var_app_token'), '');
         $locateCity = I('get.' . C('var_locate_city'), '');
         // 默认城市信息.
         $defaultCity = [];
         $modelAppClient = new AppClientModel();
         // 实例化 AppClient 模型
         $appClientInfo = $modelAppClient->checkAppId($appid);
         // 请求的参数不包含 appid 或 appid 无效.
         if (empty($appid) || FALSE === $appClientInfo) {
             $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
         }
         $this->_appId = $appid;
         // 保存 appid.
         $this->_appKey = $appClientInfo['app_key'];
         // 保存 appkey.
         $this->_appName = $appClientInfo['app_name'];
         // 保存 appname.
         // 请求的方法名不是 getToken 必须带有 token 标记 和 定位城市标记.
         if ('gettoken' !== strtolower(ACTION_NAME)) {
             // 检测 token 和 定位城市标记.
             if (empty($token) || empty($locateCity)) {
                 $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
             }
             // 校验 token 若无效, 重新生成 token, 并把传过来的城市写入该 token 缓存.
             $modelCity = new CityModel();
             $defaultCity = $modelCity->fetchNameById($locateCity);
             $defaultCity = NULL === $defaultCity ? C('default_locate_city') : $defaultCity;
             $modelCountry = new CountryModel();
             $defaultCountry = $modelCountry->fetchNameById($defaultCity['countryID']);
             $defaultCountry = NULL === $defaultCountry ? C('default_locate_country') : $defaultCountry;
             $defaultCountry['unit'] = C('default_monetary_unit')[$defaultCountry['id']];
             // 取货币单位.
             if (!Token::check($token)) {
                 $newToken = $this->reNewToken([C('var_locate_city') => $defaultCity], $token);
                 // 将默认城市写入缓存.
                 $data = [C('var_locate_city') => $defaultCity, C('var_refresh_token') => $newToken];
                 $this->_token = $newToken;
                 // 保存 token 为新 token.
                 $this->setAjaxData(Message::TOKEN_INVALID, Message::get(Message::TOKEN_INVALID), $data)->myAjaxReturn();
             } else {
                 $this->_token = $token;
                 // 保存有效的 token.
             }
             $this->_locateCity = $defaultCity;
             // 保存定位城市信息.
             $this->_locateCountry = $defaultCountry;
             // 保存定位城市所属国家信息.
             unset($defaultCity, $defaultCountry);
         }
     }
     // 校验签名.
     if (in_array(ACTION_NAME, $this->needSignActions, TRUE)) {
         $oriSign = I('get.' . C('var_app_sign'), '');
         $sign = $this->makeSignature($_POST);
         if (!$this->checkSignature($sign, $oriSign)) {
             $this->setAjaxData(Message::SIGN_ERROR, Message::get(Message::SIGN_ERROR))->myAjaxReturn();
         }
     }
 }
Example #5
0
 /**
  * 更新个人信息.
  * 
  * @access public
  * @return void
  */
 public function updatePerInfoAction()
 {
     $gender = I('post.gender', '');
     $birthday = I('post.birthday', '');
     $livingCountry = I('post.livingCountry', '');
     // 国家名称.
     $livingCity = I('post.livingCity', '');
     // 城市名称.
     $qq = I('post.qq', '');
     $facebook = I('post.facebook', '');
     $livingProvince = 0;
     // 居住地省 ID.
     $arrGender = [0 => '', 1 => '男', 2 => '女'];
     $intGenderKey = array_search($gender, $arrGender);
     $gender = FALSE === $intGenderKey ? 0 : $intGenderKey;
     // 入库的性别值, 0: 未设置, 1: 男, 2: 女.
     unset($intGenderKey);
     // 校验国家.
     if (!empty($livingCountry)) {
         $modelCountry = new CountryModel();
         $countryInfo = $modelCountry->fetchNameByName($livingCountry);
         $livingCountry = NULL === $countryInfo ? 0 : $countryInfo['id'];
         // 国家 ID.
         unset($modelCountry, $countryInfo);
     }
     // 校验城市是否为有效的, 且国家与城市所对应的国家是否匹配; 不匹配用城市的的国家替代 $livingCounty.
     if (!empty($livingCity)) {
         $modelCity = new CityModel();
         $cityInfo = $modelCity->fetchNameByName($livingCity);
         if (NULL === $cityInfo) {
             $livingCity = 0;
         } else {
             $livingCountry = $cityInfo['countryID'];
             // 将国家设置为城市所在的国家.
             $livingProvince = $cityInfo['areaID'];
             // 城市所属的省份.
             $livingCity = $cityInfo['id'];
             // 城市 ID.
         }
         unset($modelCity, $cityInfo);
     }
     // 计算生日.
     $birthY = $birthM = $birthD = 0;
     if (!empty($birthday)) {
         $arrDate = date_parse($birthday);
         $birthY = $arrDate['year'];
         $birthM = $arrDate['month'];
         $birthD = $arrDate['day'];
         unset($arrDate);
     }
     // 准备入库.
     $data = ['sex' => $gender, 'birthYear' => (int) $birthY, 'birthMonth' => (int) $birthM, 'birthDay' => (int) $birthD, 'resideCountry' => (int) $livingCountry, 'resideProvince' => (int) $livingProvince, 'resideCity' => (int) $livingCity, 'qq' => $qq, 'facebook' => $facebook];
     unset($birthY, $birthM, $birthD);
     unset($gender, $arrGender, $birthday, $livingCountry, $livingProvince, $livingCity, $qq, $facebook);
     $modelMember = new MemberModel();
     if (FALSE === $modelMember->updatePerInfo($this->getLoginedUserInfo('uid'), $data)) {
         $this->setAjaxData(Message::FAILED, '修改失败')->myAjaxReturn();
     }
     $this->setAjaxData(Message::SUCCESS, '修改成功')->myAjaxReturn();
 }