public function question_recommend_listAction()
 {
     $this->setLeftNav('thumbs');
     $req = $this->request;
     $filterCity = intval($req->getQuery('filterCity', null, -1));
     $filterContent = $req->getQuery('qcontent', null, '');
     $page = intval($req->getQuery('page', null, 1));
     $page = $page > 0 ? $page : 1;
     $limit = $this->pageNavLimit;
     $offset = $limit * ($page - 1);
     if ($filterContent != '') {
         $where[] = "question_content like '%{$filterContent}%'";
     }
     if ($filterCity > -1) {
         $where[] = "addr = {$filterCity}";
     }
     $whereStr = implode(" and ", $where);
     $columns = ['id', 'q_id', 'img_url', 'addr', 'sort', 'question_content'];
     $count = CosPointquestion::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\Question', 'q_id = qa.question_id', 'qa')->where($whereStr)->execute()->count();
     $list = CosPointquestion::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\Question', 'q_id = qa.question_id', 'qa')->where($whereStr)->limit($limit, $offset)->execute()->toArray();
     foreach ($list as $k => $v) {
         if (!empty($list[$k]['addr']) && $list[$k]['addr'] != 0) {
             $tmp = SysOpenCity::findFirst("city_id = " . $list[$k]['addr'])->toArray();
             $list[$k]['city_name'] = $tmp['city_name'];
         } else {
             $list[$k]['city_name'] = '全国';
         }
     }
     $this->view->setVar("qcontent", $filterContent);
     $this->view->setVar("total", $count);
     $this->view->setVar("limit", $limit);
     $this->view->setVar("page", $page);
     $this->view->setVar("list", $list);
     $this->view->setVar('filterCity', $filterCity);
     $this->view->setVar('openCity', $this->openCityList());
     $this->view->pick("question_recommend/list");
 }
Beispiel #2
0
 /**
  * 根据开通城市id获取问答列表
  * @date: 2016年1月22日 
  * @author: 545
  */
 private function getQuestion($city_id, $limit, $userid = null, $order = null)
 {
     $questionlists = array();
     $columns = ['q.question_id', 'q.question_content', 'q.question_pics', 'q.question_tag', 'q.answer_num', 'q.question_browsers', 'q.is_expert_reply', 'q.question_addtime', 'u.user_id', 'u.user_nickname', 'u.user_cover', 'u.user_gender'];
     //获取问答列表
     $questionlist = CosPointquestion::query()->columns($columns)->join('\\Apps\\Common\\Models\\Question', 'q.question_id = \\Apps\\Common\\Models\\CosPointquestion.q_id', 'q')->join('\\Apps\\Common\\Models\\UserBase', 'u.user_id = q.user_id', 'u')->where('addr = :city_id:')->bind(['city_id' => $city_id])->limit($limit, 0)->orderBy($order)->execute()->toArray();
     $QuestionFollow = new QuestionFollow();
     foreach ($questionlist as $k => $val) {
         // 是否收藏过
         if ($userid) {
             $questionlists[$k]['is_collection'] = $QuestionFollow->is_follow($val['question_id'], $userid);
         } else {
             $questionlists[$k]['is_collection'] = '0';
         }
         $questionlists[$k]['question_id'] = $val['question_id'];
         $questionlists[$k]['question_content'] = unserialize(base64_decode($val['question_content'])) ?: $val['question_content'];
         $questionlists[$k]['question_pics'] = [];
         if ($val['question_pics']) {
             $question_pics = [];
             foreach (json_decode($val['question_pics'], true) as $key => $value) {
                 $question_pics[] = PicUrl::Question($value, $this->getDi());
             }
             $questionlists[$k]['question_pics'] = $question_pics;
         }
         $questionlists[$k]['question_tag'] = $val['question_tag'] ? json_decode($val['question_tag'], true) : [];
         $questionlists[$k]['answer_num'] = $val['answer_num'];
         $questionlists[$k]['question_browsers'] = $val['question_browsers'];
         $questionlists[$k]['is_expert_reply'] = $val['is_expert_reply'];
         $questionlists[$k]['question_addtime'] = $val['question_addtime'];
         $questionlists[$k]['user_id'] = $val['user_id'];
         $questionlists[$k]['user_nickname'] = $val['user_nickname'];
         $questionlists[$k]['user_cover'] = PicUrl::UserCover($val['user_cover'], $this->getDi());
         $questionlists[$k]['user_gender'] = $val['user_gender'];
     }
     return $questionlists;
 }
 public function question_recommend_addAction()
 {
     $this->setLeftNav('thumbs');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('openCity', $this->openCityList());
         $this->view->pick("question_recommend/add");
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->questionPic();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了2M!');
         } else {
             $response->sendError(ResponseResultStatus::DATABASE_ERROR, '封面必须上传!');
         }
         return $response;
     }
     $question_cover = $cover[0];
     $q_id = intval($req->getPost("question_id"));
     $addr = $req->getPost("filterCity");
     //判断参数问题
     if ($req->getPost("sort") > 12 || $q_id < 0 || $addr <= 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     //判断推荐的问题是否存在
     if (Question::count("question_id = " . $q_id) == 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '问题不存在!');
         return $response;
     }
     //判断推荐问题是否已经存在12个
     if (CosPointquestion::count("addr = {$addr}") >= 12) {
         $response->sendError(ResponseResultStatus::BUSINESS, '首页推荐问题只能添加12个!');
         return $response;
     }
     //判断问题是否已经推荐
     $list = CosPointquestion::query()->where("q_id = {$q_id} and addr = {$addr}")->execute()->toArray();
     if ($list) {
         $response->sendError(ResponseResultStatus::BUSINESS, '此问题已推荐!');
         return $response;
     }
     $list = CosPointquestion::query()->where("addr = " . $addr . " and sort = " . $req->getPost("sort"))->execute()->toArray();
     if ($list) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '排序已存在!');
         return $response;
     }
     $m = new CosPointquestion();
     $m->q_id = $req->getPost("question_id");
     $m->img_url = $question_cover;
     $m->addr = $req->getPost("filterCity");
     $m->sort = $req->getPost("sort");
     $m->title = $req->getPost("title");
     $id = $m->save();
     if ($id === false) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '添加失败!');
     } else {
         $response->sendResult($id);
     }
     return $response;
 }