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); }
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); }
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); }