/** * 搜索. * * @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(); }
/** * 获取资讯详情. * * @access public * @return void */ public function getDetail() { $id = I('get.id', 0); $modelSqData = new SqDataModel(); $sqInfo = $modelSqData->fetchInfo($id); $this->assign('sqInfo', $sqInfo)->display(); }
/** * 获取资讯详情. * * @access public * @return void */ public function getDetail() { $id = I('get.id', 0); $modelSqData = new SqDataModel(); $sqInfo = $modelSqData->fetchInfo($id); // 更新浏览量. $modelSqData->updateTimes($id, SqDataModel::TIMES_TYPE_VISITS); $sqInfo['content'] = preg_replace('#<a.*?>(.*?)</a>#', '<span>$1</span>', $sqInfo['content']); $this->assign('sqInfo', $sqInfo)->display(); }
/** * 删除我的发帖. * * @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(); } }