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', ''));
     $up = new UploadPic();
     $question_pics = json_encode($up->questionPic());
     if ($questionId > 0 && !empty($question_content)) {
         // 查询最大楼层
         $floor = QuestionAnswer::maximum(["column" => "answer_floor", "conditions" => "question_id = :qid:", "bind" => ["qid" => $questionId]]);
         $qa = new QuestionAnswer();
         $qa->user_id = $this->getUserAuth()->userId;
         $qa->question_id = $questionId;
         //关键字替换
         $keyword = CosQKeyword::query()->execute()->toArray();
         foreach ($keyword as $k => $v) {
             $question_content = str_replace($v['keyword'], '***', $question_content);
         }
         $question_content = base64_encode(serialize($question_content));
         $qa->answer_content = $question_content;
         $qa->answer_floor = ($floor ? $floor : 0) + 1;
         $qa->answer_pics = $question_pics;
         if ($qa->save()) {
             $this->id = $qa->answer_id;
             $this->success = 1;
             // 记录回答数
             Question::updateAnswerNum($questionId);
         } else {
             return $this->databaseErrorLog($qa);
         }
     } 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)]);
     }
 }
 /**
  * 删除回答
  * @date: 2016年1月19日 
  * @author: futao
  */
 public function setAnswerStateAction()
 {
     $req = $this->request;
     if ($req->isPost()) {
         $id = intval($req->getPost('id', null, 0));
         $state = intval($req->getPost('state', null, -10000));
         if (!in_array($state, [-1, 0, 1])) {
             return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常');
         }
         $info = QuestionAnswer::findFirst('answer_id=' . $id);
         if ($info) {
             $info->update(['answer_state' => $state]);
             // 记录回答数
             Question::updateAnswerNum($info->question_id);
         }
         return (new ResponseResult())->sendResult('ok');
     } else {
         return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常');
     }
 }
Example #3
0
 /**
  * 回答问题
  */
 public function answerAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $id = intval($req->getQuery('id', null, 0));
         // 查询他匹配的用户
         $data = OmQuestionAnswerUser::query()->columns(['qau_id', 'ub.user_id', 'ub.user_account', 'ub.user_nickname'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\OmQuestionAnswerUser.user_id', 'ub')->where('op_id = :opId:', ['opId' => $this->operator->id])->execute();
         $this->view->setVar('userList', $data);
         $this->view->setVar('id', $id);
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('question_id', null, 0));
     if ($id <= 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数问题!');
         return $response;
     }
     $content = Keyword::Filter($req->getPost('answer_content', null, ''));
     $userId = intval($req->getPost('answer_user', null, 0));
     // 判断空数据
     if (empty($content) || $userId < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     $up = new UploadPic();
     $questionPics = json_encode($up->questionPic());
     // 查询最大楼层
     $floor = QuestionAnswer::maximum(["column" => "answer_floor", "conditions" => "question_id = :qid:", "bind" => ["qid" => $id]]);
     $qa = new QuestionAnswer();
     $qa->user_id = $userId;
     $qa->question_id = $id;
     $qa->answer_content = $content;
     $qa->answer_floor = ($floor ? $floor : 0) + 1;
     $qa->answer_pics = $questionPics;
     if ($qa->save()) {
         // 记录回答数
         Question::updateAnswerNum($id);
         $response->sendResult($qa->answer_id);
     } else {
         $this->databaseErrorLog($qa);
         $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
     }
     return $response;
 }