コード例 #1
0
ファイル: CommentAdd.php プロジェクト: fu-tao/meelier_c2.0
 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();
     				
     			}
     		} */
 }
コード例 #2
0
ファイル: CommentAdd.php プロジェクト: fu-tao/meelier_c
 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
             ]);   */
 }