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', 'u.user_gender', 'answer_id', 'answer_content', 'original_content', 'support_count', 'answer_addtime', 'answer_pics'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\QuestionAnswer.user_id', 'u')->where("answer_state = 1 and type = 1 and question_id = {$questionId}")->orderBy('answer_addtime DESC')->limit($limit, $offset)->execute()->toArray(); $QuestionAnswerFollow = new QuestionAnswerFollow(); foreach ($expertReplyList as $k => $val) { $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; } $this->setResult($expertReplyList); }
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)]); } }
/** * 问答 */ public function questionAction() { $id = $this->request->getQuery('id'); if (empty($id)) { echo '问题不存在!'; $this->view->disable(); return; } $limit = 20; $page = 1; $this->tag->setTitle($this->appName . ' - 问答详情'); $question = Question::query()->columns(['u.user_id', 'u.user_nickname', 'u.user_cover', 'Apps\\Common\\Models\\Question.question_id as question_id', 'Apps\\Common\\Models\\Question.question_content as question_content', 'Apps\\Common\\Models\\Question.question_pics as question_pics', 'Apps\\Common\\Models\\Question.question_browsers as answer_num', 'Apps\\Common\\Models\\Question.question_follows as follow_num', '0 user_is_follow', 'Apps\\Common\\Models\\Question.question_addtime as addtime'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=u.user_id', 'u')->where('question_state>0 and question_id=:id:')->bind(['id' => $id])->execute()->getFirst(); if ($question) { $question->question_pics = PicUrl::Question(json_decode($question->question_pics), $this->di); $question->addtime = \Apps\Common\Libs\DateTime::FriendlyDate($question->addtime, 'mohu'); $question->user_cover = PicUrl::UserCover($question->user_cover, $this->di); if (unserialize(base64_decode($question->question_content))) { $question->question_content = unserialize(base64_decode($question->question_content)); } } else { echo '问题不存在!'; $this->view->disable(); return; } $this->view->setVar('question', $question); $answers = QuestionAnswer::listByQuestionId($id, $limit, 0, 0)->toArray(); $answers = $answers ? $answers : []; $answersData = []; $dataBest = null; foreach ($answers as $arr) { if (unserialize(base64_decode($arr['answer_content']))) { $arr['answer_content'] = unserialize(base64_decode($arr['answer_content'])); } $arr['user_cover'] = PicUrl::UserCover($arr['user_cover'], $this->di); $arr['answer_pics'] = PicUrl::Question(json_decode($arr['answer_pics']), $this->di); $arr['addtime'] = \Apps\Common\Libs\DateTime::FriendlyDate($arr['addtime'], 'mohu'); // 处理最佳答案 $best = $arr['answer_best']; if ($best > 5 && $page == 1) { if ($dataBest == null) { $dataBest = $arr; continue; } elseif ($dataBest['answer_best'] < $best) { $dataBest = $arr; continue; } } $arr['answer_best'] = 0; $answersData[] = $arr; } if ($dataBest != null) { $dataBest['answer_best'] = 1; array_splice($answersData, 0, 0, [$dataBest]); } $this->view->setVar('answers', $answersData); }
public function run() { /* $jpush=new Jpush(); $param['type'] =1; $param['ispushservice']=1; $param['phone'] ='18623640927'; $param['content'] ="HAHHA"; $jpush->setval($param); $a=$jpush->push(); var_dump($a); exit; */ $questionId = intval($this->getDataItem('question_id', 0)); $page = intval($this->getDataItem('page', 1)); $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $this->verifyUserAuth(false); $userId = $this->getUserAuth() ? $this->getUserAuth()->userId : 0; if (0 < $questionId) { $this->answers = QuestionAnswer::listByQuestionId($questionId, $limit, $offset, $userId)->toArray(); } else { $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'question id'); } $this->answers = $this->answers ? $this->answers : []; $data = []; $dataBest = null; foreach ($this->answers as $arr) { $arr['user_cover'] = PicUrl::UserCover($arr['user_cover'], $this->getDi()); $arr['answer_pics'] = PicUrl::Question(json_decode($arr['answer_pics']), $this->getDi()); $arr['addtime'] = \Apps\Common\Libs\DateTime::Format($arr['addtime']); if (unserialize(base64_decode($arr['answer_content']))) { $arr['answer_content'] = unserialize(base64_decode($arr['answer_content'])); } // 处理最佳答案 $best = $arr['answer_best']; if ($best > 5 && $page == 1) { if ($dataBest == null) { $dataBest = $arr; continue; } elseif ($dataBest['answer_best'] < $best) { $dataBest = $arr; continue; } } $arr['answer_best'] = 0; $data[] = $arr; } if ($dataBest != null) { $dataBest['answer_best'] = 1; array_splice($data, 0, 0, [$dataBest]); } $this->setResult($data); }
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, '服务器异常!'); } }
public function run() { $user_id = intval($this->getDataItem('user_id', 0)); $expert_id = intval($this->getDataItem('expert_id', 0)); $page = intval($this->getDataItem('page', 1)); if ($expert_id < 1) { return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少必传参数!'); } $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $list = QuestionAnswer::query()->columns(['question_id'])->where('answer_state = 1 and user_id = ' . $expert_id)->groupBy('question_id')->orderBy('answer_id DESC')->limit($limit, $offset)->execute()->toArray(); if ($list) { $where = ''; foreach ($list as $val) { $where .= $val['question_id'] . ','; } $where = trim($where, ','); $result = Question::query()->columns(['question_id', 'question_tag', 'question_pics', 'question_content', 'question_addtime', 'u.user_id', 'u.user_nickname', 'u.user_cover', 'u.user_gender'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\Question.user_id', 'u')->where("question_state = 1 and question_id in({$where})")->execute()->toArray(); $QuestionFollow = new QuestionFollow(); foreach ($result as $k => $val) { $result[$k]['question_content'] = unserialize(base64_decode($val['question_content'])) ?: $val['question_content']; $result[$k]['user_cover'] = PicUrl::UserCover($val['user_cover'], $this->getDi()); if ($val['question_pics']) { $result[$k]['question_pics'] = PicUrl::Question(json_decode($val['question_pics']), $this->getDi()); } if (!is_numeric($val['question_tag'])) { $result[$k]['question_tag'] = $val['question_tag'] ? json_decode($val['question_tag'], true) : []; } else { $result[$k]['question_tag'] = []; } if ($user_id > 0) { $result[$k]['is_collection'] = $QuestionFollow->is_follow($val['question_id'], $user_id); } else { $result[$k]['is_collection'] = '0'; } } $this->setResult($result); } }
/** * @var string */ public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $user = $this->getUserAuth(); /** * 获取关注次数 */ $answerId = intval($this->getDataItem('answer_id', 0)); if ($answerId <= 0) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "答案ID必须大于0."); } $follow = QuestionAnswerFollow::count(["conditions" => "user_id = :uid: AND answer_id = :aid: ", "bind" => ['uid' => $user->userId, 'aid' => $answerId]]); /** * 有权限且未关注则执行关注 */ if ($follow == 0) { /** * 记录关注动作 */ $qaf = new QuestionAnswerFollow(); $qaf->user_id = $user->userId; $qaf->answer_id = $answerId; if ($qaf->save()) { // QuestionAnswer::updateFollows($answerId); // 不要以前的 QuestionAnswer::setSupportCount($answerId, 1); $this->success = 1; } else { return $this->databaseErrorLog($qaf); } } else { $this->success = 2; } $this->setResult(["success" => $this->success]); }
/** * 删除回答 * @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, '请求异常'); } }
private function getAnswer($userId, $limit, $offset) { $sql = <<<SQL SELECT \tu.user_id AS user_id, \tu.user_nickname AS user_nickname, \tu.user_cover AS user_cover, \tquestion.question_id AS question_id, \tquestion.question_content AS question_content, \tquestion.question_pics AS question_pics, \tquestion.answer_num AS answer_num, \tquestion.question_browsers AS browser_num, \tquestion.question_follows AS follow_num, \tquestion.question_addtime AS addtime FROM question_answer AS qa LEFT JOIN question ON question.question_id = qa.question_id LEFT JOIN user_base AS u ON question.user_id = u.user_id WHERE question.question_state > 0 AND qa.user_id = :uid GROUP BY question.question_id ORDER BY question_id DESC LIMIT {$limit} OFFSET {$offset} SQL; $model = new QuestionAnswer(); $result = new ResultSet(null, $model, $model->getReadConnection()->query($sql, ['uid' => $userId])); return $result->toArray(); }
/** * 回答问题 */ 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; }
/** * 问题预览 * @date: 2016年1月28日 * @author: chenxiaolin */ public function questionPreviewAction() { $id = $this->request->getQuery('id'); if (empty($id)) { echo "问题不存在!"; $this->view->disable(); return; } //问题内容 $question = Question::query()->columns(['u.user_id', 'u.user_nickname', 'u.user_cover', 'u.user_gender', 'Apps\\Common\\Models\\Question.question_id as question_id', 'Apps\\Common\\Models\\Question.question_addtime as addtime', 'Apps\\Common\\Models\\Question.question_content as question_content', 'Apps\\Common\\Models\\Question.question_tag as question_tag', 'Apps\\Common\\Models\\Question.question_pics as question_pics', 'Apps\\Common\\Models\\Question.question_browsers as question_browsers', 'Apps\\Common\\Models\\Question.answer_num as answer_num'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=u.user_id', 'u')->where('question_state>0 and question_id=:id:')->bind(['id' => $id])->execute()->getFirst(); if ($question) { $question->question_pics = PicUrl::Question(json_decode($question->question_pics), $this->di); $question->question_tag = json_decode($question->question_tag); //$question->addtime = \Apps\Common\Libs\DateTime::FriendlyDate($question->addtime, 'mohu'); $question->user_cover = PicUrl::UserCover($question->user_cover, $this->di); if (unserialize(base64_decode($question->question_content))) { $question->question_content = unserialize(base64_decode($question->question_content)); } } else { echo '问题不存在!'; $this->view->disable(); return; } //美人儿已阅处头像 $covers = QuestionAnswer::query()->columns(['distinct Apps\\Common\\Models\\QuestionAnswer.user_id', 'user.user_cover'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\QuestionAnswer.user_id = user.user_id', 'user')->where("Apps\\Common\\Models\\QuestionAnswer.question_id = {$id} \n and Apps\\Common\\Models\\QuestionAnswer.answer_state = 1 \n and Apps\\Common\\Models\\QuestionAnswer.type in (1,2)")->order('answer_addtime desc')->limit(7)->execute()->toArray(); foreach ($covers as $k => $v) { $covers[$k]['user_cover'] = PicUrl::UserCover($covers[$k]['user_cover'], $this->getDI()); } //专家回复 $expert = QuestionAnswer::query()->columns(['user.user_id', 'user.user_nickname', 'user.user_cover', 'userAttr.attr_value_json', 'Apps\\Common\\Models\\QuestionAnswer.answer_content'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\QuestionAnswer.user_id = user.user_id', 'user')->leftJoin('Apps\\Common\\Models\\UserAttribute', 'user.user_id = userAttr.user_id', 'userAttr')->where("Apps\\Common\\Models\\QuestionAnswer.question_id = {$id} \n and Apps\\Common\\Models\\QuestionAnswer.answer_state = 1 \n and Apps\\Common\\Models\\QuestionAnswer.type = 2\n and userAttr.attr_type = 103 ")->order('answer_addtime desc')->execute()->toArray(); foreach ($expert as $k => $v) { if (unserialize(base64_decode($expert[$k]['answer_content']))) { $expert[$k]['answer_content'] = unserialize(base64_decode($expert[$k]['answer_content'])); } $expert[$k]['user_cover'] = PicUrl::UserCover($expert[$k]['user_cover'], $this->getDI()); $expert[$k]['attr_value_json'] = json_decode($expert[$k]['attr_value_json'], true); $expert[$k]['attr_value_json']['field'] = implode('、', $expert[$k]['attr_value_json']['field']); } //网友回复 $answer = QuestionAnswer::query()->columns(['user.user_id', 'user.user_nickname', 'user.user_cover', 'user.user_gender', 'Apps\\Common\\Models\\QuestionAnswer.answer_content', 'Apps\\Common\\Models\\QuestionAnswer.answer_pics', 'Apps\\Common\\Models\\QuestionAnswer.answer_addtime'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\QuestionAnswer.user_id = user.user_id', 'user')->where("Apps\\Common\\Models\\QuestionAnswer.question_id = {$id}\n and Apps\\Common\\Models\\QuestionAnswer.answer_state = 1\n and Apps\\Common\\Models\\QuestionAnswer.type = 1")->order('answer_addtime desc')->execute()->toArray(); foreach ($answer as $k => $v) { if (unserialize(base64_decode($answer[$k]['answer_content']))) { $answer[$k]['answer_content'] = unserialize(base64_decode($answer[$k]['answer_content'])); } $answer[$k]['user_cover'] = PicUrl::UserCover($answer[$k]['user_cover'], $this->getDI()); $answer[$k]['answer_pics'] = PicUrl::Question(json_decode($answer[$k]['answer_pics']), $this->di); } $this->view->setVar('question', $question); $this->view->setVar('covers', $covers); $this->view->setVar('expert', $expert); $this->view->setVar('answer', $answer); }
/** * 删除回复 * @date: 2016-1-16 * @author: miaoyu */ public function deleteanswerAction() { $this->view->disable(); $echo = function ($msg, $state = false) { echo '<script type="text/javascript">'; echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')'; echo '</script>'; }; $req = $this->request; $answerId = intval($req->getQuery('id', null, 0)); if ($answerId < 0) { $echo("参数错误!"); return; } $answerInfo = QuestionAnswer::findFirst($answerId); if (!$answerInfo) { $echo('参数错误!'); return; } $answerInfo->answer_state = -1; if ($answerInfo->save()) { $echo("删除成功!", 1); } else { $echo("删除失败!"); } }
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)]); } }
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); }