Exemplo n.º 1
0
 public function run()
 {
     $id = intval($this->getDataItem('id', 0));
     if (0 < $id) {
         $this->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.answer_num 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('Apps\\Common\\Models\\Question.question_id= :id: and Apps\\Common\\Models\\Question.question_state > 0')->bind(['id' => $id])->execute()->getFirst();
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '参数异常');
     }
     if ($this->question) {
         if (unserialize(base64_decode($this->question->question_content))) {
             $this->question->question_content = unserialize(base64_decode($this->question->question_content));
         }
         $this->question->question_pics = PicUrl::Question(json_decode($this->question->question_pics), $this->getDi());
         $this->question->addtime = \Apps\Common\Libs\DateTime::Format($this->question->addtime);
         $this->question->user_cover = PicUrl::UserCover($this->question->user_cover, $this->getDi());
         $this->verifyUserAuth(false);
         $userId = $this->getUserAuth() ? $this->getUserAuth()->userId : 0;
         if ($userId > 0) {
             $count = QuestionFollow::count(['conditions' => 'question_id = :qid: AND user_id = :uid:', 'bind' => ['qid' => $id, 'uid' => $userId]]);
             $this->question->user_is_follow = $count > 0 ? 1 : 0;
         }
     } else {
         $this->question = null;
     }
     $this->setResult($this->question);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 public function run()
 {
     $tag_id = intval($this->getDataItem('tag_id', 0));
     $page = intval($this->getDataItem('page', 1));
     $limit = $this->getConfig()->limit;
     $offset = ($page - 1) * $limit;
     $columns = ['u.user_id', 'u.user_nickname', 'u.user_cover', 'question_id', 'question_content', 'question_pics', 'answer_num', 'question_browsers browser_num', 'question_follows follow_num', 'question_addtime addtime'];
     if (-2 == $tag_id) {
         //精华
         /*
         $this->questions = Question::query()
             ->columns($columns)
             ->leftJoin('Apps\Common\Models\UserBase',
                 'Apps\Common\Models\Question.user_id = u.user_id','u')
             ->where('question_state = 2')
             ->orderBy('question_id desc')
             ->limit($limit,$offset)
             ->execute()->toArray();
         */
         $this->questions = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id = u.user_id', 'u')->where('question_state > 0')->orderBy('answer_num desc')->limit($limit, $offset)->execute()->toArray();
     } else {
         if (-1 == $tag_id) {
             //最热
             $this->questions = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id = u.user_id', 'u')->where('question_state > 0')->orderBy('question_browsers desc,question_follows desc')->limit($limit, $offset)->execute()->toArray();
         } else {
             if (0 == $tag_id) {
                 //默认
                 $this->questions = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id = u.user_id', 'u')->where('question_state>0')->orderBy('question_id desc')->limit($limit, $offset)->execute()->toArray();
             } else {
                 //指定条件
                 $this->questions = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id = u.user_id', 'u')->where('question_state > 0 and question_tag = :question_tag:')->bind(['question_tag' => $tag_id])->orderBy('question_id desc')->limit($limit, $offset)->execute()->toArray();
             }
         }
     }
     $this->questions = $this->questions ? $this->questions : [];
     $data = [];
     foreach ($this->questions as $arr) {
         $arr['question_pics'] = PicUrl::Question(json_decode($arr['question_pics']), $this->getDi());
         if (is_string($arr['question_pics'])) {
             $arr['question_pics'] = $arr['question_pics'];
         }
         if (is_array($arr['question_pics']) && count($arr['question_pics']) > 2) {
             $arr['question_pics'] = array_slice($arr['question_pics'], 0, 2);
         }
         $arr['addtime'] = \Apps\Common\Libs\DateTime::Format($arr['addtime']);
         $arr['user_cover'] = PicUrl::UserCover($arr['user_cover'], $this->getDi());
         $arr['question_content'] = unserialize(base64_decode($arr['question_content']));
         $data[] = $arr;
     }
     $this->setResult($data);
 }