Exemple #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)]);
     }
 }
Exemple #2
0
 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 testsAction()
 {
     $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;
 }
Exemple #4
0
 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]);
 }
Exemple #5
0
 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
             ]);   */
 }
Exemple #6
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)]);
     }
 }