コード例 #1
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;
 }
コード例 #2
0
ファイル: OmController.php プロジェクト: fu-tao/meelier_c2.0
 /**
  * 添加关联1.0
  */
 public function questionUserAddAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('opList', BackendOperator::find('operator_group = 2'));
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $opId = intval($req->getPost('op_id', null, 0));
     $userId = intval($req->getPost('user_id', null, 0));
     if ($opId < 1 || $userId < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数问题!');
         return $response;
     }
     // 操作员是否存在
     if (BackendOperator::count('operator_id = ' . $opId) == 0) {
         $response->sendError(ResponseResultStatus::BUSINESS, '操作员不存在!');
         return $response;
     }
     // 用户是否存在
     if (UserBase::count('user_id = ' . $userId) == 0) {
         $response->sendError(ResponseResultStatus::BUSINESS, '用户不存在!');
         return $response;
     }
     $info = new OmQuestionAnswerUser();
     $info->op_id = $opId;
     $info->user_id = $userId;
     if ($info->save() == false) {
         $this->databaseErrorLog($info);
         $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
     } else {
         $response->sendResult($info->qau_id);
     }
     return $response;
 }