Exemplo n.º 1
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $questionId = intval($this->getDataItem('question_id', 0));
     $answer_id = intval($this->getDataItem('answer_id', 0));
     $content = Keyword::Filter($this->getDataItem('content', ''));
     $user_id = intval($this->getDataItem('user_id', 0));
     $to_user_id = intval($this->getDataItem('to_user_id', 0));
     if ($questionId == 0 || empty($content) || $user_id == 0 || $to_user_id == 0 || $user_id == $to_user_id) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少参数或参数错误,请检查!');
     }
     if (mb_strlen($content) > 300) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '回复内容长度不能超过300字符');
     }
     // 身份检查
     if ($Question = Question::findFirst('question_id = ' . $questionId)) {
         $questionData = $Question->toArray();
     } else {
         $questionData = [];
     }
     $UserBase = new UserBase();
     if (!($questionData['user_id'] == $user_id || $UserBase->is_expert($user_id))) {
         return $this->errorLog(ResultStatus::QUERY_DATA_NOT_EXIST, '您没有权限评论!');
     }
     //关键字替换
     $keyword = CosQKeyword::query()->execute()->toArray();
     foreach ($keyword as $k => $v) {
         $content = str_replace($v['keyword'], '***', $content);
     }
     if (!$answer_id) {
         // 获取回复的id
         $QuestionAnswer = \Apps\Common\Models\QuestionAnswer::query()->where("question_id = {$questionId} and user_id = {$user_id}")->execute()->getFirst();
         $answer_id = $QuestionAnswer->answer_id ?: 0;
     }
     $up = new UploadPic();
     $data = ['question_id' => $questionId, 'answer_id' => $answer_id, 'content' => $content, 'pics' => json_encode($up->questionPic()), 'user_id' => $user_id, 'to_user_id' => $to_user_id, 'add_time' => date('Y-m-d H:i:s')];
     $QuestionAnswerComments = new QuestionAnswerComments();
     if ($QuestionAnswerComments->save($data)) {
         $this->setResult(['success' => 1, 'message' => '评论成功!']);
     } else {
         return $this->errorLog(ResultStatus::DATABASE_ERROR, '服务器异常!');
     }
 }
 /**
  * 删除楼主回复
  * @date: 2016-1-19 
  * @author: miaoyu
  */
 public function delAction()
 {
     $req = $this->request;
     $id = $req->getQuery('id', null, 0);
     $qid = $req->getQuery('qid', null, 0);
     if ($id < 0) {
         echo "ID不存在";
         exit;
     }
     $query = QuestionAnswerComments::findFirst($id);
     if (!$query) {
         echo "ID不存在";
         exit;
     }
     if ($query->delete()) {
         echo "<script>location.href='/manage/questionmanage/info?id=" . $qid . "'</script>";
     } else {
         echo "<script>alert('error'),location.href='/manage/questionmanage/info?id=" . $id . "'</script>";
     }
 }
Exemplo n.º 3
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', '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);
 }