Ejemplo n.º 1
0
 /**
  * 问答
  */
 public function questionAction()
 {
     $id = $this->request->getQuery('id');
     if (empty($id)) {
         echo '问题不存在!';
         $this->view->disable();
         return;
     }
     $limit = 20;
     $page = 1;
     $this->tag->setTitle($this->appName . ' - 问答详情');
     $question = Question::query()->columns(['u.user_id', 'u.user_nickname', 'u.user_cover', 'Apps\\Common\\Models\\Question.question_id as question_id', 'Apps\\Common\\Models\\Question.question_content as question_content', 'Apps\\Common\\Models\\Question.question_pics as question_pics', 'Apps\\Common\\Models\\Question.question_browsers as answer_num', 'Apps\\Common\\Models\\Question.question_follows as follow_num', '0 user_is_follow', 'Apps\\Common\\Models\\Question.question_addtime as addtime'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=u.user_id', 'u')->where('question_state>0 and question_id=:id:')->bind(['id' => $id])->execute()->getFirst();
     if ($question) {
         $question->question_pics = PicUrl::Question(json_decode($question->question_pics), $this->di);
         $question->addtime = \Apps\Common\Libs\DateTime::FriendlyDate($question->addtime, 'mohu');
         $question->user_cover = PicUrl::UserCover($question->user_cover, $this->di);
         if (unserialize(base64_decode($question->question_content))) {
             $question->question_content = unserialize(base64_decode($question->question_content));
         }
     } else {
         echo '问题不存在!';
         $this->view->disable();
         return;
     }
     $this->view->setVar('question', $question);
     $answers = QuestionAnswer::listByQuestionId($id, $limit, 0, 0)->toArray();
     $answers = $answers ? $answers : [];
     $answersData = [];
     $dataBest = null;
     foreach ($answers as $arr) {
         if (unserialize(base64_decode($arr['answer_content']))) {
             $arr['answer_content'] = unserialize(base64_decode($arr['answer_content']));
         }
         $arr['user_cover'] = PicUrl::UserCover($arr['user_cover'], $this->di);
         $arr['answer_pics'] = PicUrl::Question(json_decode($arr['answer_pics']), $this->di);
         $arr['addtime'] = \Apps\Common\Libs\DateTime::FriendlyDate($arr['addtime'], 'mohu');
         // 处理最佳答案
         $best = $arr['answer_best'];
         if ($best > 5 && $page == 1) {
             if ($dataBest == null) {
                 $dataBest = $arr;
                 continue;
             } elseif ($dataBest['answer_best'] < $best) {
                 $dataBest = $arr;
                 continue;
             }
         }
         $arr['answer_best'] = 0;
         $answersData[] = $arr;
     }
     if ($dataBest != null) {
         $dataBest['answer_best'] = 1;
         array_splice($answersData, 0, 0, [$dataBest]);
     }
     $this->view->setVar('answers', $answersData);
 }
Ejemplo n.º 2
0
 public function run()
 {
     /* $jpush=new Jpush();
       	$param['type'] =1;
       	$param['ispushservice']=1;
       	$param['phone'] ='18623640927';
       	$param['content'] ="HAHHA";
       	$jpush->setval($param);
       	$a=$jpush->push();
       	var_dump($a);
       	exit; */
     $questionId = intval($this->getDataItem('question_id', 0));
     $page = intval($this->getDataItem('page', 1));
     $limit = $this->getConfig()->limit;
     $offset = ($page - 1) * $limit;
     $this->verifyUserAuth(false);
     $userId = $this->getUserAuth() ? $this->getUserAuth()->userId : 0;
     if (0 < $questionId) {
         $this->answers = QuestionAnswer::listByQuestionId($questionId, $limit, $offset, $userId)->toArray();
     } else {
         $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'question id');
     }
     $this->answers = $this->answers ? $this->answers : [];
     $data = [];
     $dataBest = null;
     foreach ($this->answers as $arr) {
         $arr['user_cover'] = PicUrl::UserCover($arr['user_cover'], $this->getDi());
         $arr['answer_pics'] = PicUrl::Question(json_decode($arr['answer_pics']), $this->getDi());
         $arr['addtime'] = \Apps\Common\Libs\DateTime::Format($arr['addtime']);
         if (unserialize(base64_decode($arr['answer_content']))) {
             $arr['answer_content'] = unserialize(base64_decode($arr['answer_content']));
         }
         // 处理最佳答案
         $best = $arr['answer_best'];
         if ($best > 5 && $page == 1) {
             if ($dataBest == null) {
                 $dataBest = $arr;
                 continue;
             } elseif ($dataBest['answer_best'] < $best) {
                 $dataBest = $arr;
                 continue;
             }
         }
         $arr['answer_best'] = 0;
         $data[] = $arr;
     }
     if ($dataBest != null) {
         $dataBest['answer_best'] = 1;
         array_splice($data, 0, 0, [$dataBest]);
     }
     $this->setResult($data);
 }