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 run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $question_tag = intval($this->getDataItem('tag_id', 0)); $question_content = Keyword::Filter($this->getDataItem('content', '')); $up = new UploadPic(); $question_pics = json_encode($up->questionPic()); if (!empty($question_content)) { $q = new Question(); $q->user_id = $this->getUserAuth()->userId; // $q->user_id = 1; $q->question_tag = $question_tag; //关键字替换 $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)); $q->question_content = $question_content; $q->question_pics = $question_pics; if ($q->save()) { $this->id = $q->question_id; $this->success = 1; SearchASync::Instance()->noticeSync($q->question_id, SearchDataType::Question); //推送消息 $phoneNum = ['15823522906', '13883156314', '18725873971', '15086691064', '18996156384', '13752904126', '18523066564', '15723278358', '18523989994', '15111992368', '18123640250', '18323868684']; foreach ($phoneNum as $k => $v) { $param = array('type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:' . mb_substr($question_content, 0, 10, 'utf-8') . ',快去回答吧!', 'shop_id' => 0); $push = new Jpush(); $rs = $push->setval($param); if (empty($rs)) { $push->push(); } continue; } } else { return $this->databaseErrorLog($q); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } $this->setResult(['id' => $this->id, 'success' => $this->success]); }
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() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $question_tag = $this->getDataItem('tag', ''); $custom_tag = $this->getDataItem('custom_tag', ''); $question_content = Keyword::Filter($this->getDataItem('content', '')); $city_code = (string) $this->getDataItem('city_code', '0'); $up = new UploadPic(); if ($question_pics = $up->questionPic()) { // $question_pics = json_encode(array_slice($question_pics, 0, 3)); $question_pics = json_encode($question_pics); } else { $question_pics = json_encode([]); } if (!empty($question_content) && $city_code != '0') { $q = new Question(); $q->user_id = $this->getUserAuth()->userId; //关键字替换 $keyword = CosQKeyword::query()->execute()->toArray(); foreach ($keyword as $k => $v) { $question_content = str_replace($v['keyword'], '***', $question_content); } if ($question_tag) { $tag_id = ''; $tagList = []; foreach ($question_tag as $k => $val) { $tagList[] = $val['name']; $tag_id .= $val['id'] . ','; } $tagLists = BeautyParlorTagInfo::query()->where('tag_id in(' . trim($tag_id, ',') . ')')->execute()->toArray(); foreach ($tagLists as $val) { if ($val['parent_id'] == 0) { return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '不能选择一级标签!'); } } if ($custom_tag) { $tagList[] = $custom_tag; } $q->question_tag = json_encode($tagList); } $q->question_content = $question_content; $q->question_pics = $question_pics; $date = date('Y-m-d H:i:s'); $q->last_reply_time = $date; $q->question_addtime = $date; $q->city_code = $city_code; if ($q->save()) { if ($question_tag) { // 保存问答的标签 $tagData = ''; foreach ($question_tag as $k => $val) { $tagData .= "({$val['id']}, '{$val["name"]}', {$q->question_id}),"; } $tagData = trim($tagData, ','); $q->getReadConnection()->query("INSERT INTO question_tag (tag_id, tag_name, question_id) VALUES {$tagData}"); } $this->id = $q->question_id; $this->success = 1; // SearchASync::Instance()->noticeSync($q->question_id, SearchDataType::Question); //推送消息 /*$phoneNum = [ '15823522906', '13883156314', '18725873971', '15086691064', '18996156384', '13752904126', '18523066564', '15723278358', '18523989994', '15111992368', '18123640250', '18323868684', ]; $push = new Jpush(); foreach($phoneNum as $k => $v){ $param = array( 'type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:'.mb_substr($question_content,0,10,'utf-8').',快去回答吧!', 'shop_id' => 0 ); $rs = $push -> setval($param); if(empty($rs)){ $push -> push(); } continue; }*/ // 推送测试(测试用的) $phoneNum = ['18723568681', '17790274639', '18225097233', '18723793180']; $push = new Jpush(); foreach ($phoneNum as $k => $v) { $param = array('type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:' . mb_substr($question_content, 0, 10, 'utf-8') . ',快去回答吧!', 'shop_id' => 0); $rs = $push->setval($param); if (empty($rs)) { $push->push(); } continue; } } else { return $this->databaseErrorLog($q); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } $this->setResult(['id' => $this->id, 'success' => $this->success]); }
/** * 敏感词删除 * @date: 2016-1-15 * @author: futao */ public function keyworddeleteAction() { $req = $this->request; $keywordId = $req->getQuery('id', null, 0); $echo = function ($msg, $state = false) { echo '<script type="text/javascript">'; echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')'; echo '</script>'; }; if ($keywordId > 0) { $keywordModel = CosQKeyword::findFirst($keywordId); if ($keywordModel) { if ($keywordModel->delete()) { echo "<script>window.parent.location.href='keywordlist'</script>"; } } else { $echo("删除失败!"); } } else { $echo("删除失败!"); } }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $bp_id = intval($this->getDataItem('beauty_parlor_id', 0)); $comment_info = Keyword::Filter($this->getDataItem('content', '')); $comment_info = trim($comment_info); //关键字替换 $keyword = CosQKeyword::query()->execute()->toArray(); foreach ($keyword as $k => $v) { $comment_info = str_replace($v['keyword'], '***', $comment_info); } //$type = intval($this -> getDataItem('type')); $type = $this->getDataItem('type', 0); //评论图片 $up = new UploadPic(); $comment_photos = json_encode($up->beautyParlorComment()); if ($bp_id > 0 && !empty($comment_info)) { // 查询最大楼层 $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "beauty_parlor_id = :id: and type = 0", "bind" => ["id" => $bp_id]]); $comment_info = base64_encode(serialize($comment_info)); $bpc = new BeautyParlorComment(); $bpc->user_id = $this->getUserAuth()->userId; $bpc->comment_floor = ($floor ? $floor : 0) + 1; $bpc->beauty_parlor_id = $bp_id; $bpc->comment_info = $comment_info; $bpc->comment_photos = $comment_photos; $bpc->type = $type; if ($bpc->save()) { $this->id = $bpc->comment_id; $this->success = 1; return $this->setResult(['id' => $this->id, 'success' => $this->success]); } else { return $this->databaseErrorLog($bpc); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } /* //评论成功,推送消息 $branch = BeautyParlor::findFirst("bp_id = $bp_id") -> toArray(); $branchId = $branch['branch_id']; if(empty($branchId)){//没有分店,不推送 return $this->setResult([ 'id'=>$this->id, 'success'=>$this->success ]); }else{ $num = Branch::query() ->columns('s.shop_uid') -> leftJoin('Apps\Common\Models\CosShop','Apps\Common\Models\Branch.shop_id = s.shop_id','s') -> where('Apps\Common\Models\Branch.branch_id = '.$branchId) -> execute()->toArray(); $phoneNum = $num[0]['shop_uid']; $param = array( 'type' => 7, 'ispushservice' => 0, 'phone' => $phoneNum, 'content' => '有人对您的美容院进行了评论,快去看看吧!', 'shop_id' => 0 ); $push = new Jpush(); $rs = $push -> setval($param); if(!empty($rs)){ $data = json_decode($rs,true); $status = $data['status']; if($status == 400){//数据错误 return $this->setResult([ 'id'=>$this->id, 'success'=>$this->success ]); } }else{ $rs = $push -> push(); } } */ }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $bp_id = intval($this->getDataItem('beauty_parlor_id', 0)); $appoint_id = intval($this->getDataItem('appoint_id', 0)); $comment_info = Keyword::Filter($this->getDataItem('content', '')); //关键字替换 $keyword = CosQKeyword::query()->execute()->toArray(); foreach ($keyword as $k => $v) { $comment_info = str_replace($v['keyword'], '***', $comment_info); } $comment_info = base64_encode(serialize($comment_info)); //$type = intval($this -> getDataItem('type')); $type = $this->getDataItem('type'); //评论图片 $up = new UploadPic(); $comment_photos = json_encode($up->beautyParlorComment()); if ($type !== null && $type >= 0 && in_array($type, array(0, 1))) { if ($type == 0) { //添加美容院评论 if ($bp_id > 0 && !empty($comment_info)) { // 查询最大楼层 $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "beauty_parlor_id = :id: and type = 0", "bind" => ["id" => $bp_id]]); $bpc = new BeautyParlorComment(); $bpc->user_id = $this->getUserAuth()->userId; $bpc->comment_floor = ($floor ? $floor : 0) + 1; $bpc->beauty_parlor_id = $bp_id; $bpc->comment_info = $comment_info; $bpc->comment_photos = $comment_photos; $bpc->type = $type; if ($bpc->save()) { $this->id = $bpc->comment_id; $this->success = 1; } else { return $this->databaseErrorLog($bpc); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } //评论成功,推送消息 $branch = BeautyParlor::findFirst("bp_id = {$bp_id}")->toArray(); $branchId = $branch['branch_id']; if (empty($branchId)) { //没有分店,不推送 return $this->setResult(['id' => $this->id, 'success' => $this->success]); } else { $num = Branch::query()->columns('s.shop_uid')->leftJoin('Apps\\Common\\Models\\CosShop', 'Apps\\Common\\Models\\Branch.shop_id = s.shop_id', 's')->where('Apps\\Common\\Models\\Branch.branch_id = ' . $branchId)->execute()->toArray(); $phoneNum = $num[0]['shop_uid']; $param = array('type' => 7, 'ispushservice' => 0, 'phone' => $phoneNum, 'content' => '有人对您的美容院进行了评论,快去看看吧!', 'shop_id' => 0); $push = new Jpush(); $rs = $push->setval($param); if (!empty($rs)) { $data = json_decode($rs, true); $status = $data['status']; if ($status == 400) { //数据错误 return $this->setResult(['id' => $this->id, 'success' => $this->success]); } } else { $rs = $push->push(); return $this->setResult(['id' => $this->id, 'success' => $this->success]); } } } if ($type == 1) { //添加预约评论 if ($bp_id > 0 && $appoint_id > 0 && !empty($comment_info)) { //判断预约是否已被当前用户评论 $is_comment = BeautyParlorComment::count(["conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id: and user_id = :user_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id, "user_id" => $this->getUserAuth()->userId]]); if ($is_comment > 0) { //已评论 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "预约已评论"); } else { //查询最大楼层 $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id]]); $bpc = new BeautyParlorComment(); $query = new CosOnlineAppointment(); $appoint = $query->findFirst("id = {$appoint_id}"); if ($appoint) { $data['state'] = 1; $rs = $appoint->update($data); } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "当前预约不存在"); } $bpc->user_id = $this->getUserAuth()->userId; $bpc->comment_floor = ($floor ? $floor : 0) + 1; $bpc->beauty_parlor_id = $bp_id; $bpc->comment_info = $comment_info; $bpc->comment_photos = $comment_photos; $bpc->type = $type; $bpc->appointment_id = $appoint_id; if ($bpc->save() && $rs) { $this->id = $bpc->comment_id; $this->success = 1; } else { return $this->databaseErrorLog($bpc); } } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } return $this->setResult(['id' => $this->id, 'success' => $this->success]); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "评论类型错误"); } /* $bp_id = intval($this->getDataItem('beauty_parlor_id',0)); $comment_info = Keyword::Filter($this->getDataItem('content','')); $up = new UploadPic(); $comment_photos = json_encode($up->beautyParlorComment()); if($bp_id > 0 && !empty($comment_info)) { // 查询最大楼层 $floor = BeautyParlorComment::maximum([ "column" => "comment_floor", "conditions" => "beauty_parlor_id = :id:", "bind" => [ "id" => $bp_id ] ]); //关键字替换 $keyword = CosQKeyword::query() -> execute() -> toArray(); foreach ($keyword as $k => $v){ $comment_info = str_replace($v['keyword'], '***', $comment_info); //$comment_info = str_replace($v['keyword'], str_repeat('*', strlen($v['keyword'])/3), $comment_info); } $bpc = new BeautyParlorComment(); $bpc->user_id = $this->getUserAuth()->userId; $bpc->comment_floor = ($floor ? $floor : 0) + 1; $bpc->beauty_parlor_id=$bp_id; $bpc->comment_info=$comment_info; $bpc->comment_photos=$comment_photos; if($bpc->save()){ $this->id = $bpc->comment_id; $this->success = 1; }else{ return $this->databaseErrorLog($bpc); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } $this->setResult([ 'id'=>$this->id, 'success'=>$this->success ]); */ }
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)]); } }