Exemple #1
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', 'u.user_gender', 'answer_id', 'answer_content', 'original_content', 'support_count', 'answer_addtime', 'answer_pics'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\QuestionAnswer.user_id', 'u')->where("answer_state = 1 and type = 1 and question_id = {$questionId}")->orderBy('answer_addtime DESC')->limit($limit, $offset)->execute()->toArray();
     $QuestionAnswerFollow = new QuestionAnswerFollow();
     foreach ($expertReplyList as $k => $val) {
         $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;
     }
     $this->setResult($expertReplyList);
 }
Exemple #2
0
 /**
  * @var string
  */
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $user = $this->getUserAuth();
     /**
      * 获取关注次数
      */
     $answerId = intval($this->getDataItem('answer_id', 0));
     if ($answerId <= 0) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "答案ID必须大于0.");
     }
     $follow = QuestionAnswerFollow::count(["conditions" => "user_id = :uid: AND answer_id = :aid: ", "bind" => ['uid' => $user->userId, 'aid' => $answerId]]);
     /**
      * 有权限且未关注则执行关注
      */
     if ($follow == 0) {
         /**
          * 记录关注动作
          */
         $qaf = new QuestionAnswerFollow();
         $qaf->user_id = $user->userId;
         $qaf->answer_id = $answerId;
         if ($qaf->save()) {
             //                QuestionAnswer::updateFollows($answerId); // 不要以前的
             QuestionAnswer::setSupportCount($answerId, 1);
             $this->success = 1;
         } else {
             return $this->databaseErrorLog($qaf);
         }
     } else {
         $this->success = 2;
     }
     $this->setResult(["success" => $this->success]);
 }
 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);
 }