/**
  * 问答详情
  * @date: 2016-1-16 
  * @author: futao
  */
 public function infoAction()
 {
     $this->setLeftNav("info");
     $req = $this->request;
     $questionId = intval($req->getQuery('id', null, 0));
     if ($questionId < 0) {
         echo "参数错误!";
         return;
     }
     $questionColumns = ['ub.user_id', 'ub.user_nickname', 'ub.user_cover', 'Apps\\Common\\Models\\Question.user_id', 'Apps\\Common\\Models\\Question.question_content', 'Apps\\Common\\Models\\Question.question_pics', 'Apps\\Common\\Models\\Question.question_addtime', 'Apps\\Common\\Models\\Question.question_browsers', 'Apps\\Common\\Models\\Question.question_id'];
     $info = Question::query()->columns($questionColumns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\Question.user_id', 'ub')->where("Apps\\Common\\Models\\Question.question_id = {$questionId} and Apps\\Common\\Models\\Question.question_state = 1")->execute()->getFirst();
     if (!$info) {
         echo "问题不存在!";
         exit;
     }
     $info->user_cover = PicUrl::UserCover($info->user_cover, $this->di);
     if (unserialize(base64_decode($info->question_content))) {
         $info->question_content = unserialize(base64_decode($info->question_content));
     }
     if (json_decode($info->question_pics)) {
         $info->question_pics = json_decode($info->question_pics);
     }
     $answerColumns = ['ub.user_nickname', 'ub.user_cover', 'Apps\\Common\\Models\\QuestionAnswer.answer_content', 'Apps\\Common\\Models\\QuestionAnswer.answer_addtime', 'Apps\\Common\\Models\\QuestionAnswer.answer_id', 'Apps\\Common\\Models\\QuestionAnswer.original_content', 'Apps\\Common\\Models\\QuestionAnswer.answer_pics', 'Apps\\Common\\Models\\QuestionAnswer.type', 'Apps\\Common\\Models\\QuestionAnswer.user_id'];
     $answerList = QuestionAnswer::query()->columns($answerColumns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionAnswer.user_id', 'ub')->where("Apps\\Common\\Models\\QuestionAnswer.question_id = {$questionId} and Apps\\Common\\Models\\QuestionAnswer.answer_state = 1")->orderBy("Apps\\Common\\Models\\QuestionAnswer.answer_floor asc")->execute()->toArray();
     foreach ($answerList as $k => $val) {
         if (unserialize(base64_decode($answerList[$k]['answer_content']))) {
             $answerList[$k]['answer_content'] = unserialize(base64_decode($answerList[$k]['answer_content']));
         }
         if (unserialize(base64_decode($answerList[$k]['original_content']))) {
             $answerList[$k]['original_content'] = unserialize(base64_decode($answerList[$k]['original_content']));
         }
         if (json_decode($answerList[$k]['answer_pics'])) {
             $answerList[$k]['answer_pics'] = json_decode($answerList[$k]['answer_pics']);
         }
         if ($answerList[$k]['type'] == 1) {
             $answerList[$k]['reply'] = QuestionAnswerComments::query()->columns(['ub.user_nickname', 'ub.user_cover', 'ub.user_id', 'content', 'add_time', 'id'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionAnswerComments.user_id', 'ub')->where("question_id = {$questionId} and answer_id = " . $answerList[$k]['answer_id'] . " and to_user_id = " . $answerList[$k]['user_id'])->orderBy("id desc")->execute()->toArray();
         }
         $answerList[$k]['user_cover'] = PicUrl::UserCover($answerList[$k]['user_cover'], $this->di);
     }
     $userList = UserBase::find("is_manage = 1");
     $seeList = QuestionViewsUser::query()->columns(['distinct ub.user_id', 'ub.user_cover'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionViewsUser.user_id', 'ub')->where("question_id = {$questionId}")->orderBy("id desc")->limit(7)->execute();
     $this->view->setVar('seelist', $seeList);
     $this->view->setVar('comment_count', QuestionAnswer::count('answer_state = 1 and question_id = ' . $questionId));
     $this->view->setVar('question_id', $questionId);
     $this->view->setVar('userlist', $userList);
     $this->view->setVar('questioninfo', $info);
     $this->view->setVar('answerlist', $answerList);
     $this->view->pick('question/info');
 }
Example #2
0
 public function run()
 {
     $questionId = intval($this->getDataItem('question_id', 0));
     $user_id = intval($this->getDataItem('user_id', 0));
     $page = intval($this->getDataItem('page', 1));
     //        $questionId = 194;
     if ($questionId < 1) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '参数不完整或者参数错误!');
     }
     $limit = $this->getConfig()->limit;
     $offset = ($page - 1) * $limit;
     $QuestionAnswer = new QuestionAnswer();
     $expertReplyList = $QuestionAnswer->query()->columns(['u.user_id', 'u.user_cover', 'u.user_nickname', 'answer_id', 'answer_content', 'support_count', 'answer_addtime', 'answer_pics', 'a.attr_value_json'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\QuestionAnswer.user_id', 'u')->leftJoin('\\Apps\\Common\\Models\\UserAttribute', 'a.user_id = \\Apps\\Common\\Models\\QuestionAnswer.user_id', 'a')->where("a.attr_type = 103 and a.attr_state = 1 and answer_state = 1 and type = 2 and question_id = {$questionId}")->orderBy('answer_addtime DESC')->limit($limit, $offset)->execute()->toArray();
     $QuestionAnswerComments = new QuestionAnswerComments();
     $UserBase = new UserBase();
     $QuestionAnswerFollow = new QuestionAnswerFollow();
     foreach ($expertReplyList as $k => $val) {
         if ($val['attr_value_json']) {
             $objAttrValueJoin = json_decode($val['attr_value_json']);
             $expertReplyList[$k]['experttitle'] = $objAttrValueJoin->experttitle;
             $expertReplyList[$k]['field'] = $objAttrValueJoin->field ?: [];
         } else {
             $expertReplyList[$k]['experttitle'] = [];
             $expertReplyList[$k]['field'] = [];
         }
         $expertReplyList[$k]['user_cover'] = PicUrl::UserCover($val['user_cover'], $this->getDi());
         $expertReplyList[$k]['answer_content'] = unserialize(base64_decode($val['answer_content'])) ?: $val['answer_content'];
         if ($user_id > 0) {
             $expertReplyList[$k]['is_support'] = $QuestionAnswerFollow->is_support($user_id, $val['answer_id']) ? '1' : '0';
         } else {
             $expertReplyList[$k]['is_support'] = '0';
         }
         $answer_pics = [];
         if ($answer_pics_list = json_decode($val['answer_pics'], true)) {
             foreach ($answer_pics_list as $value) {
                 $answer_pics[] = PicUrl::Question($value, $this->getDi());
             }
         }
         $expertReplyList[$k]['answer_pics'] = $answer_pics;
         unset($expertReplyList[$k]['attr_value_json']);
         if ($item = $QuestionAnswerComments->query()->where('answer_id = ' . $val['answer_id'])->limit(10, 0)->execute()->toArray()) {
             foreach ($item as $key => $v) {
                 $user_info = $UserBase->getOne($v['user_id']);
                 $to_user_info = $UserBase->getOne($v['to_user_id']);
                 $item[$key]['user_info'] = ['user_id' => $v['user_id'], 'user_nickname' => $user_info['user_nickname']];
                 $item[$key]['to_user_info'] = ['user_id' => $v['to_user_id'], 'user_nickname' => $to_user_info['user_nickname']];
                 $pics = [];
                 if ($pics_list = json_decode($v['pics'], true)) {
                     foreach ($pics_list as $values) {
                         $pics[] = PicUrl::Question($values, $this->getDi());
                     }
                 }
                 $item[$key]['pics'] = $pics;
                 unset($item[$key]['user_id'], $item[$key]['to_user_id']);
             }
             $expertReplyList[$k]['item'] = $item;
         } else {
             $expertReplyList[$k]['item'] = [];
         }
     }
     $this->setResult($expertReplyList);
 }