Esempio n. 1
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $user = $this->getUserAuth();
     /**
      * 获取关注次数
      */
     $questionId = intval($this->getDataItem('question_id', 0));
     if ($questionId <= 0) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "问题ID必须大于0.");
     }
     $follow = QuestionFollow::count(["conditions" => "user_id = :uid: AND question_id = :qid: ", "bind" => ['uid' => $user->userId, 'qid' => $questionId]]);
     /**
      * 有权限且未关注则执行关注
      */
     if ($follow == 0) {
         $qf = new QuestionFollow();
         $qf->user_id = $user->userId;
         $qf->question_id = $questionId;
         if ($qf->save()) {
             Question::updateFollows($questionId);
             $this->success = 1;
         } else {
             return $this->databaseErrorLog($qf);
         }
     } else {
         $this->success = 2;
     }
     $this->setResult(["success" => $this->success]);
 }
Esempio n. 2
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);
 }