Пример #1
0
 /**
  * 搜索.
  * 
  * @access public
  * @return void
  */
 public function searchAction()
 {
     $type = (int) I('post.type', 0);
     // 搜索类型: 0分类, 1社区资讯.
     $catId = I('post.catId', NULL);
     // 搜索的栏目 ID, 为 NULL, 根据类型全站搜索.
     $keyword = I('post.keyword', '');
     // 关键字为空, 返回空.
     $pageConfig = C('page');
     // 分页参数变量名配置项.
     $page = (int) I('post.' . $pageConfig['var_page'], 1);
     // page.
     $pageSize = (int) I('post.' . $pageConfig['var_page_size'], 10);
     // rows.
     $allowType = [0, 1];
     $catId = empty($catId) || !is_numeric($catId) ? NULL : (int) $catId;
     unset($pageConfig);
     if (!isset($allowType[$type])) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $model = NULL;
     switch ($type) {
         case 0:
             $model = new CtgDataModel();
             break;
         default:
             $model = new SqDataModel();
     }
     $result = ['totalRows' => 0, 'lists' => []];
     if (!empty($keyword)) {
         $result = $model->search($keyword, $catId, $page, $pageSize);
     }
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $result)->myAjaxReturn();
 }
Пример #2
0
 /**
  * (non-PHPdoc)
  * @see \Api\Controller\BaseController::_initialize()
  */
 protected function _initialize()
 {
     // 调用父类初始化.
     parent::_initialize();
     // 未登录且不在过滤列表中的方法不允许访问.
     if (!in_array(ACTION_NAME, $this->filterNoLoginActions, TRUE) && !$this->isLogined()) {
         $this->setAjaxData(Message::ACCESS_DENEID, Message::get(Message::ACCESS_DENEID))->myAjaxReturn();
     }
 }
Пример #3
0
 /**
  * 获取 token.
  * 
  * @access public
  * @return void
  */
 public function getToken()
 {
     // 生成 token 并写入缓存.
     $token = Token::generate(C('var_app_id'));
     $value = [C('var_locate_city') => C('default_locate_city')];
     // 写入默认定位城市.
     $this->setRequestToken($token);
     $this->setTokenData($value, NULL);
     $value[C('var_app_token')] = $token;
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $value)->myAjaxReturn();
 }
Пример #4
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();
 }
Пример #5
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();
 }
Пример #6
0
 /**
  * 获取国家的栏目列表.
  * 
  * @access public
  * @return void
  */
 public function getListByCountry()
 {
     $intParentId = I('post.pid', NULL);
     // 上级栏目 ID, 默认 NULL, 表示获取国家的全部栏目列表.
     if (NULL !== $intParentId && (int) $intParentId < 1) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $arrLocateCountry = $this->getLocateCountry();
     // 获取当前请求的定位国家.
     $countryId = (int) $arrLocateCountry['id'];
     // 国家 ID.
     unset($arrLocateCountry);
     $modelCtgClass = new CtgClassModel();
     // 实例化 CtgClass 模型.
     if (NULL === $intParentId) {
         // 获取国家的全部栏目, 要格式化.
         $categoryList = $modelCtgClass->formatList($modelCtgClass->fetchListByCountry($countryId, $intParentId));
     } else {
         // 获取子栏目时, 不用格式化.
         $categoryList = $modelCtgClass->fetchListByCountry($countryId, (int) $intParentId);
     }
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $categoryList)->myAjaxReturn();
 }
Пример #7
0
 /**
  * 删除指定用户发布的社区资讯信息.
  * 
  * @access public
  * @param integer $userId 用户 ID.
  * @param array $ids 分类信息 ID.
  * @param boolean $deletedCollect 删除收藏, 默认 FALSE.
  * @return boolean 删除成功返回 TRUE, 删除失败返回 FALSE; 出错时抛异常.
  */
 public function remove($userId, array $ids, $deletedCollect = FALSE)
 {
     if (empty($ids) || empty($userId)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     // 查询出用户发布的社区资讯信息 ID.
     $map = ['userID' => $userId, 'id' => ['IN', $ids]];
     $ids = $this->field('id')->where($map)->select();
     $ids = NULL === $ids || FALSE === $ids ? [] : $ids;
     if (empty($ids)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     // 将待删除的 id 转换成一维数组.
     $deleteIds = [];
     foreach ($ids as $v) {
         $deleteIds[] = $v['id'];
     }
     unset($ids);
     $res1 = TRUE;
     $modelUserCollect = new UserCollectModel();
     $this->startTrans();
     $res1 = $this->where($map)->delete() !== FALSE ? TRUE : FALSE;
     // 删除社区资讯.
     $sql = $this->getLastSql();
     $resDetail = $resCollect = TRUE;
     // 删除副表数据.
     $tableName = $this->tablePrefix . 'sq_fdata';
     $resDetail = $this->table($tableName)->where(['dataID' => ['IN', $deleteIds]])->delete() === FALSE ? FALSE : TRUE;
     $sql1 = $this->getLastSql();
     // 删除收藏.
     $resCollect = $modelUserCollect->where(['type' => 1, 'dataID' => ['IN', $deleteIds]])->delete() === FALSE ? FALSE : TRUE;
     $sql2 = $this->getLastSql();
     if ($res1 && $resDetail && $resCollect) {
         $this->commit();
         return TRUE;
     } else {
         $this->rollback();
         return FALSE;
     }
 }
 /**
  * 收藏分类信息.
  * 
  * @access public
  * @return void
  */
 public function collectAction()
 {
     $id = (int) I('post.id', '');
     // 分类信息 ID.
     if ($id < 1) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     // 数据库检查该信息是否有效.
     $modelCtgData = new CtgDataModel();
     $resCheck = $modelCtgData->checkInfo($id);
     if (FALSE === $resCheck) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $loginedInfo = $this->getLoginedUserInfo();
     // 登录的用户信息.
     $modelUserCollect = new UserCollectModel();
     // 实例化 UserCollect 模型.
     $res = $modelUserCollect->checkIsCollected($id, $loginedInfo['uid'], 0);
     if ($res) {
         $this->setAjaxData(Message::FAILED, '您已收藏了该条信息, 请勿重复收藏!')->myAjaxReturn();
     }
     $data = ['userID' => $loginedInfo['uid'], 'dataID' => $id, 'type' => 0, 'createTime' => time()];
     $res = $modelUserCollect->addInfo($data);
     if ($res) {
         $this->setAjaxData(Message::SUCCESS, '收藏成功')->myAjaxReturn();
     }
     $this->setAjaxData(Message::FAILED, '收藏失败')->myAjaxReturn();
 }
Пример #9
0
 /**
  * 获取启动图片.
  * 
  * @access public
  * @return void
  */
 public function getBootAd()
 {
     $imgPath = C('site_domain') . './Uploads/bootAdImg/1.jpg';
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), ['adImg' => $imgPath])->myAjaxReturn();
 }
Пример #10
0
 /**
  * 删除指定用户发布的分类信息.
  * 
  * @access public
  * @param integer $userId 用户 ID.
  * @param array $ids 分类信息 ID.
  * @param boolean $deletedCollect 删除收藏, 默认 FALSE.
  * @return boolean 删除成功返回 TRUE, 删除失败返回 FALSE; 出错时抛异常.
  */
 public function remove($userId, array $ids, $deletedCollect = FALSE)
 {
     if (empty($ids) || empty($userId)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     // 查询出用户发布的分类信息 ID.
     $map = ['userID' => $userId, 'dataID' => ['IN', $ids]];
     $deleteIds = $this->field(['dataID' => 'id', 'modID' => 'module_id'])->where($map)->select();
     $deleteIds = NULL === $deleteIds || FALSE === $deleteIds ? [] : $deleteIds;
     if (empty($deleteIds)) {
         throw new \Exception(Message::get(Message::PARAM_ERROR), Message::PARAM_ERROR);
     }
     $res1 = TRUE;
     $modelUserCollect = new UserCollectModel();
     $this->startTrans();
     $res1 = $this->where($map)->delete() !== FALSE ? TRUE : FALSE;
     // 删除主表数据.
     $detailResult = $collectResult = [];
     foreach ($deleteIds as $r) {
         // 删除副表数据.
         $tableName = $this->tablePrefix . 'ctg_data' . $r['module_id'];
         if ($this->table($tableName)->where(['dataID' => $r['id']])->delete() === FALSE) {
             $detailResult[] = FALSE;
             break;
         }
         if ($deletedCollect) {
             // 删除收藏.
             if ($modelUserCollect->where(['type' => 0, 'dataID' => $r['id']])->delete() === FALSE) {
                 $collectResult[] = FALSE;
                 break;
             }
         }
     }
     if ($res1 && count($detailResult) < 1 && count($collectResult) < 1) {
         $this->commit();
         return TRUE;
     } else {
         $this->rollback();
         return FALSE;
     }
 }
Пример #11
0
 /**
  * 空操作方法.
  * 
  * @access public
  * @return void
  */
 public function _empty()
 {
     $this->setAjaxData(Message::PAGE_NOT_FOUND, Message::get(Message::PAGE_NOT_FOUND))->myAjaxReturn();
 }
Пример #12
0
 /**
  * 删除我的发帖.
  * 
  * @access public
  * @return void
  */
 public function deletePostAction()
 {
     $ids = I('post.ids', []);
     $ids = array_map(function ($id) {
         if ((int) $id > 0) {
             return (int) $id;
         }
     }, $ids);
     $postType = (int) I('post.postType', 0);
     // 发贴类型: 0: 分类, 1: 社区资讯.
     $allowType = [0, 1];
     if (empty($ids) || !in_array($postType, $allowType, TRUE)) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $loginedInfo = $this->getLoginedUserInfo();
     // 登录的用户信息.
     $model = NULL;
     switch ($postType) {
         case 0:
             $model = new CtgDataModel();
             break;
         case 1:
             $model = new SqDataModel();
             break;
         default:
     }
     try {
         $result = $model->remove($loginedInfo['uid'], $ids, TRUE);
         if ($result) {
             $this->setAjaxData(Message::SUCCESS, '删除成功')->myAjaxReturn();
         } else {
             $this->setAjaxData(Message::FAILED, '删除失败')->myAjaxReturn();
         }
     } catch (\Exception $e) {
         $this->setAjaxData($e->getCode(), $e->getMessage())->myAjaxReturn();
     }
 }
Пример #13
0
 /**
  * 获取社区分类栏目.
  * 
  * @access public
  * @return void
  */
 public function getList()
 {
     $modelSqClass = new SqClassModel();
     $result = $modelSqClass->fetchList(0);
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $result)->myAjaxReturn();
 }
Пример #14
0
 /**
  * 忘记密码处理.
  * 
  * @access public
  * @return void
  */
 public function forgotPwdAction()
 {
     $userName = I('post.username', '');
     $userEmail = I('post.useremail', '');
     $code = I('post.code', '');
     $userPwd = I('post.userpass', '');
     // 校验用户名与邮箱是否匹配.
     $res = $this->_checkForgotUserAndEmail($userName, $userEmail);
     if (9 !== $res['status']) {
         $this->setAjaxData(Message::USERNAME_OR_EMAIL_NOT_MATCH, Message::get(Message::USERNAME_OR_EMAIL_NOT_MATCH));
     }
     // 校验验证码是否正确.
     $res = $this->_checkEmailCode($userEmail, $code);
     if (9 !== $res['status']) {
         $this->setAjaxData(Message::VCODE_INVALID, $res['msg'])->myAjaxReturn();
     }
     // 校验密码格式是否正确.
     $modelUser = new UserModel();
     $res = $modelUser->validate($modelUser->ruleForgotPwdPwdItem)->create(['userPasswd' => $userPwd]);
     if (!$res) {
         $this->setAjaxData(Message::FAILED, $modelUser->getError())->myAjaxReturn();
     }
     // 都验证通过了, 进入重置密码.
     if ($modelUser->resetPwd($userName, $this->encryptMyPwd($userPwd))) {
         // 重置密码成功, 设置为登录状态.
         $loginUserInfo = $modelUser->checkLogin($userName, $this->encryptMyPwd($userPwd));
         $result = $this->_loginSuccess($loginUserInfo);
         $this->setAjaxData(Message::SUCCESS, '重置密码成功', $result)->myAjaxReturn();
     }
     $this->setAjaxData(Message::FAILED, '重置密码失败')->myAjaxReturn();
 }