Example #1
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $questionId = intval($this->getDataItem('question_id', 0));
     $question_content = Keyword::Filter($this->getDataItem('content', ''));
     $city_code = $this->getDataItem('city_code', '0');
     $original_content = $this->getDataItem('original_content', '');
     if (!($question_content = trim($question_content))) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "回复内容不能为空!");
     }
     if ($questionId > 0 && !empty($question_content)) {
         if (mb_strlen($question_content) > 300) {
             return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '回复内容长度不能超过300字符');
         }
         //关键字替换
         $keyword = CosQKeyword::query()->execute()->toArray();
         foreach ($keyword as $k => $v) {
             $question_content = str_replace($v['keyword'], '***', $question_content);
         }
         $up = new UploadPic();
         $user_id = $this->getUserAuth()->userId;
         $type = (new UserBase())->is_expert($user_id) ? 2 : 1;
         // 用户类型(1=》普通,2=》专家)
         $data = ['question_id' => $questionId, 'user_id' => $user_id, 'answer_content' => $question_content, 'answer_pics' => json_encode($up->questionPic()), 'answer_addtime' => date('Y-m-d H:i:s'), 'city_code' => $city_code, 'type' => $type];
         if ($original_content) {
             $data['original_content'] = $original_content;
         }
         $QuestionAnswer = new QuestionAnswer();
         if ($QuestionAnswer->save($data)) {
             $this->success = 1;
             $Question = new Question();
             $Question->setAnswerNum($questionId, 1, true);
             if ($type == 2) {
                 // 修改问答为专家已回复状态
                 $Question->getReadConnection()->query('UPDATE question SET is_expert_reply = 1 WHERE question_id = ' . $questionId);
             }
         } else {
             return $this->databaseErrorLog($QuestionAnswer);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "缺少必传参数!");
     }
     //回答成功,推送消息
     $num = Question::query()->columns(['b.user_account'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=b.user_id', 'b')->where('Apps\\Common\\Models\\Question.question_id = ' . $questionId)->execute()->toArray();
     $phoneNum = $num[0]['user_account'];
     $param['type'] = 6;
     $param['ispushservice'] = 0;
     $param['phone'] = $phoneNum;
     $param['content'] = '您的问题有人回答了,快去看看吧!';
     $param['shop_id'] = 0;
     $push = new Jpush();
     $rs = $push->setval($param);
     if (!empty($rs) || empty($phoneNum)) {
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     } else {
         $rs = $push->push();
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     }
 }