public function run() { if (!$this->verifyUserAuth()) { return false; } $id = intval($this->getDataItem('id', 0)); $user_id = intval($this->getDataItem('user_id', 0)); $content = $this->getDataItem('content', ''); if ($id == 0 || $user_id == 0) { $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'URL参数不全'); return false; } $contentLenth = $this->utf8_strlen($content); if ($contentLenth < 1 || $contentLenth > 100) { $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '评论字符应在1~100之间.'); return false; } $ActivityComment = new ActivityComment(); $date = date('Y-m-d H:i:s'); $data = ['comment_user_id' => $user_id, 'comment_content' => $content, 'addtime' => $date, 'activity_id' => $id]; if ($ActivityComment->save($data)) { $ActivityComment->getReadConnection()->query("UPDATE activity SET comments = comments + 1 WHERE activity_id = {$id}"); $userInfo = UserBase::getOne($user_id); $this->setResult(['comment_id' => $ActivityComment->comment_id, 'user_id' => $user_id, 'comment_content' => $content, 'addtime' => $date, 'user_gender' => $userInfo['user_gender'], 'user_cover' => PicUrl::ActivityCover($userInfo['user_cover'], $this->getDi())]); } else { $this->errorLog(ResultStatus::ERROR, '评论失败.'); } }
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); }