check()) { $userId = \Auth::guard('api')->user()->id; } $team_id = $request->team_id??'3867813594'; $is_rec = $request->is_rec; $teacher_id = $request->teacher_id; $result = Course::where('is_show',1)->where('type','fullink')->where('team_id',$team_id)->withCount('videos'); if($is_rec==1) $result = $result->where('is_rec',1); if($teacher_id) $result = $result->where('user_id',$teacher_id); $result= $result->orderBy('sort','desc')->Paginate(); foreach ($result as $key => $value) { //原价 $value->original_price = $value->charge; $value->discount_status = 0; if($value->end_time_discount>now()&&$value->start_time_discountdiscount_price){ $value->charge = $value->discount_price; $value->discount_status = 1; } $value->charge = floatval($value->charge); $value['videos_count'] = $value->videos_count; $value['paymentStatus'] = false; if(isset($userId)) $value['paymentStatus'] = UserCourses::where('course_id',$value->id)->where('user_id',$userId)->where('status',1)->count()?true:false; } return $this->success('ok', $result); } // 课程列表-商户 public function BusinessCourseList(Request $request) { $merchant_user_id = $request->merchant_user_id; $result = Course::where('is_show',1)->where('type','business')->where('merchant_id',$request->merchant_id)->withCount('videos'); $result= $result->orderBy('sort','desc')->Paginate(); foreach ($result as $key => $value) { //原价 $value->original_price = $value->charge; $value->discount_status = 0; if($value->end_time_discount>now()&&$value->start_time_discountdiscount_price){ $value->charge = $value->discount_price; $value->discount_status = 1; } $value->charge = floatval($value->charge); $value['videos_count'] = $value->videos_count; $value['paymentStatus'] = UserCourses::where('course_id',$value->id)->where('merchant_user_id',$merchant_user_id)->where('status',1)->count()?true:false; } return $this->success('ok', $result); } // 课程详情-商户 public function BusinessCourseDetail(Request $request) { $merchant_user_id = $request->merchant_user_id; $id = $request->id; $result = Course::where('id',$id)->withCount('videos')->where('is_show',1)->first(); //课程目录 if(!$result) return $this->failure('该课程不存在或已经下架~'); //原价 $result->original_price = $result->charge; $anchor = Anchor::where('m_id',$result->merchant_id)->first(); if($anchor){ $result->teacher_name = $anchor->name; } //折扣价 $result->discount_status = 0; if($result->end_time_discount>now()&&$result->start_time_discountdiscount_price){ $result->charge = $result->discount_price; $result->discount_status = 1; } //课程数量 $result->videos_count = $result->videos_count; //结业状态 $result->graduation = false; $paymentStatus = false; if($merchant_user_id){ $paymentStatus = UserCourses::where('course_id',$id)->where('merchant_user_id',$merchant_user_id)->where('status',1)->count()?true:false; //空对象的布尔值是true,此处需要转化为数组 $video = json_decode($result->videos,true); if($paymentStatus&&!empty($video)){ $result->videos[0]['can_watch']=1; } //查看心得数量 $comment_count = CourseComments::where('merchant_user_id',$request->merchant_user_id)->where('course_id',$id)->where('status',1)->where('is_show',1)->count(); if($comment_count>1&&$comment_count==$result->videos_count){ //是否结业 $result->graduation = true; } } //付款状态 $result->paymentStatus = $paymentStatus; //获取视频播放地址 getVodInfo foreach ( $result->videos as $k => $value) { $value->Viewing_status = 0; $value->duration = ceil($value->duration/60); if($merchant_user_id){ $key = $merchant_user_id.'course_record'.$id.'video_id'. $value->id; if (Cache::has($key)) $value->Viewing_status = 1; //如果已经有心得 $count = CourseComments::where('merchant_user_id',$request->merchant_user_id)->where('course_id',$id)->where('status',1)->where('video_id',$value->id)->first(); if($count){ $value->Viewing_status = 2; $value->can_watch = 1; //记录可观看状态 if(isset($result->videos[$k+1])){ $result->videos[$k+1]->can_watch = 1; } } } if(!$value->url){ $info = $this->getVodInfo($value->aliyun_video_id); $value->url = $info['Mezzanine']['FileURL']; } } //学员信息 foreach ($result->BusinessUserCourse as $key => $value) { $user = MerchantUsers::where('id',$value->merchant_user_id)->first(); $result->BusinessUserCourse[$key]['nickname'] = $user['nickname']??'该用户已隐藏'; $result->BusinessUserCourse[$key]['avatar'] = $user['pic']??User::DefaultAvatar; } $result->user_count = count($result->BusinessUserCourse); $result->pv = Redis::zincrby('coursepv', 1 ,$id); return $this->success('ok', $result); } //课程详情-福恋 public function CourseDetail(Request $request) { if (\Auth::guard('api')->check()) { $user = \Auth::guard('api')->user(); } $wechatUser = session('wechat.oauth_user.new'); if($wechatUser){ $openid = $wechatUser->getId(); }else{ $openid = $request->openid; } $id = $request->id; $result = Course::where('id',$id)->withCount('videos')->withCount(['member'=>function($sql){ $sql->where('status',1); }])->where('is_show',1)->first(); //课程目录 if(!$result) { return $this->failure('该课程不存在或已经下架~'); } //原价 $result->original_price = $result->charge; //折扣价 $result->discount_status = 0; if($result->end_time_discount>now()&&$result->start_time_discountdiscount_price){ $result->charge = $result->discount_price; $result->discount_status = 1; } //课程数量 $result->videos_count = $result->videos_count; $result->user_count = $result->member_count; //结业状态 $result->graduation = false; $love_pv = Redis::zincrby('love_course_pv', 1 ,$id); $pv = Redis::zscore('coursepv' ,$id); $result->pv = $love_pv+$pv; $paymentStatus = false; $merchant_user = MerchantUser::where('openid',$openid)->first(); if(isset($user)){ $paymentStatus = UserCourses::where('course_id',$id)->where('user_id',$user->id)->where('status',1)->count()?true:false; //空对象的布尔值是true,此处需要转化为数组 $video = json_decode($result->videos,true); if($paymentStatus&&!empty($video)){ $result->videos[0]['can_watch']=1; } //查看心得数量 $comment_count = CourseComments::where('user_id',$user->id)->where('course_id',$id)->where('status',1)->where('is_show',1)->count(); if($comment_count>1&&$comment_count==$result->videos_count){ //是否结业 $result->graduation = true; } } elseif($merchant_user) { $paymentStatus = UserCourses::where('course_id',$id)->Where('merchant_user_id', $merchant_user->id)->where('status',1)->count()?true:false; //空对象的布尔值是true,此处需要转化为数组 $video = json_decode($result->videos,true); if($paymentStatus&&!empty($video)){ $result->videos[0]['can_watch']=1; } //查看心得数量 $comment_count = CourseComments::Where('merchant_user_id', $merchant_user->id)->where('course_id',$id)->where('status',1)->where('is_show',1)->count(); if($comment_count>1&&$comment_count==$result->videos_count){ //是否结业 $result->graduation = true; } } if(!$merchant_user){ $rand_str = $this->randString(8); $merchantUser = new MerchantUser(); $merchantUser->openid = $openid; $merchantUser->rand_str = $rand_str; $merchantUser->pic = User::DefaultAvatar; $merchantUser->nickname = '用户'.$rand_str; $merchantUser->save(); } //付款状态 $result->paymentStatus = $paymentStatus; //获取视频播放地址 getVodInfo foreach ( $result->videos as $k => $value) { $value->Viewing_status = 0; $value->duration = ceil($value->duration/60); if(isset($user)){ $key = $user->id.'course_record'.$id.'video_id'. $value->id; if (Cache::has($key)) $value->Viewing_status = 1; //如果已经有心得 $count = CourseComments::where('user_id',$user->id)->where('course_id',$id)->where('status',1)->where('video_id',$value->id)->first(); if($count){ $value->Viewing_status = 2; $value->can_watch = 1; //记录可观看状态 if(isset($result->videos[$k+1])){ $result->videos[$k+1]->can_watch = 1; } } } if(!$value->url){ $info = $this->getVodInfo($value->aliyun_video_id); $value->url = $info['Mezzanine']['FileURL']; } } //学员信息 foreach ($result->UserCourse as $key => $value) { $user = User::select('id','nickname')->where('id',$value['user_id'])->first(); if(!$user) continue; $result->UserCourse[$key]['nickname'] = $user['nickname']; $result->UserCourse[$key]['avatar'] = $user['avatar']; } return $this->success('ok', $result); } //视频详情-福恋 public function videoDetail(Request $request) { if (\Auth::guard('api')->check()) { $user = \Auth::guard('api')->user(); } $video_id = $request->video_id; $video = CourseVideo::select('id','course_id','title','thumb','url','charge')->where('id',$video_id)->first(); $video->Viewing_status = 0; $video->duration = ceil($video->duration/60); $video->can_watch = 0; if(isset($user)){ $key = $user->id.'course_record'.$video->course_id.'video_id'. $video_id; if (Cache::has($key)) $video->Viewing_status = 1; //如果已经有心得 $count = CourseComments::where('user_id',$user->id)->where('course_id',$video->course_id)->where('status',1)->where('video_id',$video_id)->first(); if($count){ $video->Viewing_status = 2; $video->can_watch = 1; } }else{ $video->url = null; } return $this->success('ok', $video); } //视频详情-商户 public function BusinessVideoDetail(Request $request) { $merchant_user_id = $request->merchant_user_id; $video_id = $request->video_id; $video = CourseVideo::select('id','course_id','title','thumb','url','charge')->where('id',$video_id)->first(); $video->Viewing_status = 0; $video->duration = ceil($video->duration/60); $video->can_watch = 0; if($merchant_user_id){ $key = $merchant_user_id.'course_record'.$video->course_id.'video_id'. $video_id; if (Cache::has($key)) $video->Viewing_status = 1; //如果已经有心得 $count = CourseComments::where('merchant_user_id',$merchant_user_id)->where('course_id',$video->course_id)->where('status',1)->where('video_id',$video_id)->first(); if($count){ $video->Viewing_status = 2; $video->can_watch = 1; } }else{ $video->url = null; } return $this->success('ok', $video); } //我的课程订单-商户 public function BusinessMycourse(Request $request) { $merchant_user_id = $request->merchant_user_id; $anchor_openid = $request->anchor_openid; if(!$anchor_openid||$anchor_openid=='null') $anchor_openid = MerchantAccount::where('id',$request->merchant_id)->value('openid'); $result = UserCourses::where('merchant_user_id',$merchant_user_id)->where('status',1); $ids = []; if($anchor_openid){ $ids = TouristOrder::where('account_id',$merchant_user_id)->where('merchant_id',$request->merchant_id)->where('type','course')->whereIn('pay_status',[1,4])->pluck('type_id'); }else{ $ids = TouristOrder::where('account_id',$merchant_user_id)->where('from_openid',$anchor_openid)->where('type','course')->whereIn('pay_status',[1,4])->pluck('type_id'); } $result = $result->wherein('course_id',$ids); $result = $result->wherenotnull('trade_no')->simplePaginate(); foreach ($result as $key => $value) { $state = 0; $value->Course ; $value->video_count = CourseVideo::where('course_id',$value->Course->id)->count(); $value->learning = 0; $comment = CourseComments::where('merchant_user_id',$merchant_user_id)->where('course_id',$value->Course->id)->where('status',1)->orderby('video_id','desc')->first(); $value->title = '未知'; if(isset($comment->video)) $value->title = $comment->video->title; $comment_count = CourseComments::where('merchant_user_id',$merchant_user_id)->where('course_id',$value->Course->id)->where('status',1)->count(); if($comment_count>=1) $value->learning = 1; if($comment_count>=$value->video_count) $value->title = '已学完'; $order = TouristOrder::where('trade_no',$value->trade_no)->first(); if(!$order->Praise){ $state = 2; }else{ $state = 3; } $value->state = $state; } return $this->success('ok', $result); } //我的课程订单-福恋 public function mycourse(Request $request) { $user_id = auth()->user()->id; $result = UserCourses::where('user_id',$user_id)->where('status',1)->simplePaginate(); foreach ($result as $key => $value) { $value->Course ; $value->video_count = CourseVideo::where('course_id',$value->Course->id)->count(); $value->learning = 0; $comment = CourseComments::where('user_id',$user_id)->where('course_id',$value->Course->id)->where('status',1)->orderby('video_id','desc')->first(); $value->title = '学习中'; if(isset($comment->video)) $value->title = $comment->video->title; $comment_count = CourseComments::where('user_id',$user_id)->where('course_id',$value->Course->id)->where('status',1)->count(); if($comment_count>=1) $value->learning = 1; if($comment_count>=$value->video_count) $value->title = '已学完'; } return $result; } // 获取课程学员信息-商户 public function BusinessStudents(Request $request) { $course_id = $request->course_id??0; //获取群课程 if(!$course_id) return $this->failure('课程信息有误'); $UserCourses = UserCourses::select('merchant_user_id')->where('course_id',$course_id)->where('status',1)->groupby('merchant_user_id')->get(); $data = []; foreach ($UserCourses as $key => $value) { if($value->open_id){ $info = MerchantUsers::where('id',$value->merchant_user_id)->first(); // $user['id']= $value->user->id??0; $user['nickname'] = $info->nickname??'匿名用户'; $user['avatar'] = $info->pic??User::DefaultAvatar; array_push($data,$user); } unset($value->user); } $page = $request->page ?? 1; $perPage = 15; $offset = ($page * $perPage) - $perPage; $result = new LengthAwarePaginator( array_slice($data, $offset, $perPage), count($data), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()] ); return $this->success('ok', $result); } //获取课程学员信息-福恋 public function students(Request $request) { $course_id = $request->course_id??0; $team_id = $request->team_id??0; $UserCourses = UserCourses::select('user_id')->where('status',1)->groupby('user_id')->get(); //获取群课程 if($team_id){ $Courses_id = Course::where('team_id',$team_id)->pluck('id'); $UserCourses = UserCourses::select('user_id')->where('status',1)->wherein('course_id',$Courses_id)->groupby('user_id')->get(); } if($course_id) $UserCourses = UserCourses::select('user_id')->where('course_id',$course_id)->where('status',1)->groupby('user_id')->get(); $data = []; foreach ($UserCourses as $key => $value) { if($value->user){ $user['id']= $value->user->id??0; $user['nickname'] = $value->user->nickname??'匿名用户'; $user['avatar'] = $value->user->avatar??''; array_push($data,$user); } unset($value->user); } $page = $request->page ?? 1; $perPage = 15; $offset = ($page * $perPage) - $perPage; $result = new LengthAwarePaginator( array_slice($data, $offset, $perPage), count($data), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()] ); return $this->success('ok', $result); } //记录播放记录-商户 public function BusinessAddRecord(Request $request) { $courses_id = $request->courses_id; $video_id = $request->video_id; $key = $request->merchant_user_id.'course_record'.$courses_id.'video_id'. $video_id; CourseVideo::where('id',$video_id)->increment('view_num',1); Cache::forever($key,true); return $this->success('ok', '记录成功'); } //记录播放记录-福恋 public function addRecord(Request $request) { $user_id = auth()->user()->id; $courses_id = $request->courses_id; $video_id = $request->video_id; $key = $user_id.'course_record'.$courses_id.'video_id'. $video_id; CourseVideo::where('id',$video_id)->increment('view_num',1); Cache::forever($key,true); return $this->success('ok', '记录成功'); } //上传课程心得-商户 public function BusinessCourseExperience(Request $request) { $merchant_user_id = $request->merchant_user_id; $course_id = $request->course_id??0; $video_id = $request->video_id??0; $content = $request->content??''; $photos = $request->photos??''; //内容安全-图片 if($photos){ $result = \CommonUtilsService::imageContentCecurity($photos); if ($result && isset($result['result']) && $result['result']) { return $this->failure('图片' . $result['result'] . ',请换一张照片'); } } $photos = json_encode($photos); CourseComments::updateOrCreate(['merchant_user_id'=>$merchant_user_id,'course_id'=>$course_id,'video_id'=>$video_id],['content'=>$content,'photos'=>$photos,'status'=>1,'type'=>'business']); return $this->success('ok','提交成功'); } //上传课程心得 public function CourseExperience(Request $request) { $user = auth()->user(); $course_id = $request->course_id??0; $video_id = $request->video_id??0; $content = $request->content??''; $photos = $request->photos??''; //内容安全-图片 if($photos){ $result = \CommonUtilsService::imageContentCecurity($photos); if ($result && isset($result['result']) && $result['result']) { return $this->failure('图片' . $result['result'] . ',请换一张照片'); } } $photos = json_encode($photos); CourseComments::updateOrCreate(['user_id'=>$user->id,'course_id'=>$course_id,'video_id'=>$video_id],['content'=>$content,'photos'=>$photos,'status'=>1]); return $this->success('ok','提交成功'); } //获取课程心得-商户 public function BusinessGetCourseExperience(Request $request) { $course_id = $request->course_id; $video_id = $request->video_id; if($video_id){ $type = 'video_id'; $obj = $video_id; }else{ $type = 'course_id'; $obj = $course_id; } $result = CourseComments::select('id','course_id','user_id','content','photos','open_id','created_at','video_id')->withCount('BusinessComments') ->where($type,$obj) ->where('status',1) ->where('is_show',1) ->orderby('id','desc') ->simplePaginate(); $result = $this->ComMentInfoV2($result); return $this->success('ok',$result); } //获取课程心得 public function GetCourseExperience(Request $request) { $user = $this->authCheck(); $course_id = $request->course_id; $video_id = $request->video_id; if($video_id){ $type = 'video_id'; $obj = $video_id; }else{ $type = 'course_id'; $obj = $course_id; } $result = CourseComments::select('id','course_id','user_id','content','photos','created_at','video_id')->withCount('comments') ->where($type,$obj) ->where('status',1) ->where('is_show',1) ->orderby('id','desc') ->simplePaginate(); $result = $this->ComMentInfo($result,$user); return $this->success('ok',$result); } //我的课程心得-商户 public function BusinessMyComments(Request $request) { $merchant_user_id = $request->merchant_user_id; $id = $request->id; $type = $request->type; $result = CourseComments::select('id','course_id','user_id','content','photos','created_at','video_id','open_id')->withCount('BusinessComments') ->where('merchant_user_id',$merchant_user_id) ->where($type,$id) ->where('status',1) ->where('is_show',1) ->orderby('id','desc') ->simplePaginate(); $result = $this->ComMentInfoV2($result); return $this->success('ok',$result); } //我的课程心得 public function MyComments(Request $request) { $user = auth()->user(); $id = $request->id; $type = $request->type; $result = CourseComments::select('id','course_id','user_id','content','photos','created_at','video_id')->withCount('comments') ->where('user_id',$user->id) ->where($type,$id) ->where('status',1) ->where('is_show',1) ->orderby('id','desc') ->simplePaginate(); $result = $this->ComMentInfo($result,$user); return $this->success('ok',$result); } public function ComMentInfoV2($result) { foreach ($result as $key => $value) { $time = strtotime($value->created_at); $time = date('Y/m/d H:i:s',$time); $value->title =$value->video->title??''; $value->time = $time; unset($value->video); $value->photos = json_decode($value->photos,true); $user = MerchantUsers::where('id',$value->merchant_user_id)->first(); $value->nickname = $user->nickname??''; $value->avatar = $user->pic??User::DefaultAvatar; } return $result; } public function ComMentInfo($result,$user) { foreach ($result as $key => $value) { $time = strtotime($value->created_at); $time = date('Y/m/d H:i:s',$time); $value->likerCount =$value->likers->count(); $value->title =$value->video->title??''; $value->time = $time; $likers = $value->likers; $liker = []; foreach ($likers as $k => $v) { $liker[$k]['id'] = $v->id; $liker[$k]['nickname'] = $v->nickname; $liker[$k]['avatar'] = $v->avatar; } $value->liker = $liker; unset($value->likers); unset($value->video); $value->photos = json_decode($value->photos,true); $author = User::where('id',$value['user_id'])->first(); $value->nickname = $author->nickname??''; $value->avatar = $author->avatar??''; $value->isLker = false; if($user) $value->isLker = $user->hasLiked($value)?true:false; } return $result; } // 课程心得详情-商户 public function BusinessCourseExperienceDetail(Request $request) { $id = $request->id; $user = MerchantUsers::where('id',$request->merchant_user_id)->first(); $CourseComments = CourseComments::select('id','user_id','course_id','content','photos','video_id','created_at')->withCount('BusinessComments')->where('id',$id)->first(); if($CourseComments){ $CourseComments->comments = $CourseComments->BusinessComments; unset($CourseComments->BusinessComments); $CourseComments->nickname = $user->nickname??'匿名用户'; $CourseComments->avatar = $user->pic??User::DefaultAvatar; $CourseComments->title = $CourseComments->video->title??''; $CourseComments->photos = json_decode($CourseComments->photos,true); unset( $CourseComments->video); foreach ($CourseComments->comments as $key => $value) { $otherViewer = MerchantUsers::where('id',$value->commented_id)->first(); $value['nickname'] = $otherViewer['nickname']??'匿名用户'; $value['avatar'] = $otherViewer['pic']??User::DefaultAvatar; } return $this->success('ok',$CourseComments); } return $this->failure('获取数据失败~'); } // 课程心得详情-福恋 public function CourseExperienceDetail(Request $request) { $user = auth()->user(); $id = $request->id; $CourseComments = CourseComments::select('id','user_id','course_id','content','photos','video_id','created_at')->withCount('comments')->where('id',$id)->first(); if($CourseComments){ $CourseComments->isLker = $user->hasLiked($CourseComments) ?true:false; $CourseComments->comments = $CourseComments->comments; $CourseComments->nickname = $CourseComments->user->nickname??'匿名用户'; $CourseComments->avatar = $CourseComments->user->avatar; $CourseComments->title = $CourseComments->video->title??''; $CourseComments->photos = json_decode($CourseComments->photos,true); unset( $CourseComments->video); unset( $CourseComments->user); $likers = $CourseComments->likers; $liker = []; $CourseComments->likerCount =$CourseComments->likers->count(); foreach ($likers as $k => $v) { $liker[$k]['id'] = $v->id; $liker[$k]['nickname'] = $v->nickname; $liker[$k]['avatar'] = $v->avatar; } $CourseComments->liker = $liker; unset($CourseComments->likers); foreach ($CourseComments->comments as $key => $value) { $user = User::select('id','photo','app_avatar','circle_avatar','nickname')->where('id',$value['commented_id'])->first(); $value['nickname'] = $user['nickname']; $value['avatar'] = $user['avatar']; } return $this->success('ok',$CourseComments); } return $this->failure('获取数据失败~'); } // 生产二维码 public function get_qrcode(Request $request) { $url = $request->url; $type = $request->type??'mp'; $width = $request->input('width',200); $result = $this->getQrcode($url,$width,$type); return $this->success('ok',$result); } //心得点赞 public function likeCourse(Request $request) { $id = $request->id; $type = $request->type; $user = auth()->user(); if($type=='task'){ $result = VideoComments::where('id',$id)->first(); }elseif($type=='experience'){ $result = CourseComments::where('id',$id)->first(); } if ($user->hasLiked($result)) { //取消点赞 $user->unlike($result); return $this->success('ok',['isLker'=>false]); }else{ //点赞 $user->like($result); return $this->success('ok',['isLker'=>true]); } } // 商户-心得点赞 public function BusinessMomentCourse(Request $request) { $User = MerchantUsers::where('id',$request->merchant_user_id)->first(); $comment = $request->comment; $reply_id = $request->reply_id??0; $commented_type ='App\Models\User'; $commentable_id = $request->commentable_id; $commentable_type = 'App\Models\BesinessCourse'; $result = CourseComments::where('id',$commentable_id)->where('status',1)->first(); if(!$result) return $this->failure('未找到该记录~'); $Comment = new Comment(); $Comment->comment = $comment; $Comment->reply_id = $reply_id; $Comment->commented_id = $User->id; $Comment->commentable_id = $commentable_id; $Comment->commented_type = $commented_type; $Comment->commentable_type = $commentable_type; $Comment->save(); $data = []; $data['comment'] = $comment; $data['reply_id'] = $reply_id; $data['nickname']= $User['nickname']; $data['avatar']= $User['pic']; $data['created_at']= date('Y-m-d H:i:s'); return $this->success('ok',$data); } //评论- 福恋 public function MomentCourse(Request $request) { $user = auth()->user(); $comment = $request->comment; $reply_id = $request->reply_id??0; $commented_type ='App\Models\User'; $commentable_id = $request->commentable_id; $commentable_type = 'App\Models\Course'; $result = CourseComments::where('id',$commentable_id)->where('status',1)->first(); if(!$result) return $this->failure('未找到该记录~'); $Comment = new Comment(); $Comment->comment = $comment; $Comment->reply_id = $reply_id; $Comment->commented_id = $user->id; $Comment->commentable_id = $commentable_id; $Comment->commented_type = $commented_type; $Comment->commentable_type = $commentable_type; $Comment->save(); $data = []; $data['comment'] = $comment; $data['reply_id'] = $reply_id; $user = User::where('id',$user->id)->select('nickname')->first(); $data['nickname']= $user['nickname']; $data['avatar']= $user['avatar']; $data['created_at']= date('Y-m-d H:i:s'); return $this->success('ok',$data); } //购买课程 public function BuyingCourses(Request $request) { $user_id = auth()->user()->id; $trade_no = \CommonUtilsService::getTradeNO(); $course_id = $request->course_id; $pay_type = $request->pay_type; $cash = $request->cash; $openid = $request->openid; $user_coupons_id = $request->user_coupons_id; $from_user_id = $request->from_user_id; $from_openid = $request->from_openid??0; $course = Course::where('id',$course_id)->first(); if(!$course) return $this->failure('您购买的课程不存在或已下架~'); if($cash !=$course->charge&&!$course->discount_price) return $this->failure('金额错误'); $result = UserCourses::where('user_id',$user_id)->where('course_id',$course_id)->where('status',1)->first(); if($result) return $this->failure('您已经购买过该课程啦~'); //如果使用优惠券 $remark = ''; $price = $course->charge; $pay_status = 'UNPAID'; //查看用户是否有优惠券 $Course_status = 0; if($user_coupons_id){ $my_Coupon = UserCoupon::where('id',$user_coupons_id)->where(function ($query) use($openid,$user_id) { $query->where('openid', $openid) ->orWhere('user_id', $user_id); })->first(); if(!$my_Coupon) return $this->failure('未查询到您的优惠信息~'); if($my_Coupon->status==1) return $this->failure('该优惠券已使用~'); $Coupon = Coupon::where('id',$my_Coupon->coupons_id)->first(); if(!$Coupon) return $this->failure('未查询到该优惠券信息'); if($Coupon->expiration_time&&$Coupon->expiration_timefailure('该优惠券已过期'); if($Coupon->status==0) return $this->failure('该优惠券已下架'); //优惠后金额 $price = $price-$Coupon->preferential_amount??0; if($Coupon->payment_method=='free'){ $Coupon->preferential_amount = $cash; $pay_type = 'free'; $price = 0; $pay_status = 'PAID'; $Course_status = 1; UserCoupon::where('id',$user_coupons_id)->where(function ($query) use($openid,$user_id) { $query->where('openid', $openid) ->orWhere('user_id', $user_id); })->update(['status'=>1]); $key = 'mycoupon'.$user_id.'openId'.$openid.'course'; cache::forget($key); } $remark = '使用'.$Coupon->name.'-优惠金额'.$Coupon->preferential_amount.'元'; }else{ //指定时间内购买金额将有折扣 if($course->end_time_discount>now()&&$course->start_time_discountdiscount_price) $price = $course->discount_price??$price; } $pay_order = array( 'user_id' => $user_id, 'trade_no' => $trade_no, 'cash' => $price, 'pay_type'=>$pay_type, 'pay_status'=>$pay_status, ); $order = array( 'user_id'=>$user_id, 'type_id'=>$course_id, 'goods'=>'购买课程', 'price'=>$price, 'num'=>1, 'remark'=>$remark, 'type'=>'course', 'trade_no'=>$trade_no, 'pay_type'=>$pay_type, 'from_user_id'=>$from_user_id, 'from_openid'=>$from_openid, 'pay_status'=> $pay_status, ); $user_course = array( 'user_id'=>$user_id, 'course_id'=>(int)$course_id, 'trade_no'=>$trade_no, 'status'=>$Course_status, 'from_user_id'=>$from_user_id??0, ); try { //开启事务 \DB::beginTransaction(); PayOrder::create($pay_order); //支付订单 Order::create($order); UserCourses::create($user_course); \DB::commit(); } catch (\Exception $e) { //回滚事务 \DB::rollback(); return $this->failure('支付失败,请稍后再试~'); \Log::error($e->getMessage().';line-'.$e->getLine()); } if ($price>0) { $callback = config('app.url').'/api/app/callback/orders/'.$trade_no; $openid = Viewer::where('user_id', $user_id)->value('openid'); if(!$openid) $openid = Wechat::where('user_id', $user_id)->value('official_openid'); $attributes = array( 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... 'body' => $course->title, 'detail' => '购买课程', 'out_trade_no' => $pay_order['trade_no'], 'total_fee' => round($pay_order['cash']*100), 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'openid' => $openid, ); $result = \WechatService::officialPay($attributes); // $result = \WechatService::constructWXPay(['trade_no'=>$trade_no,'cash'=>$price], $user_id, '购买课程', $callback); // $result = \WechatService::constructWXH5Pay(['trade_no'=>$trade_no,'cash'=>$price], $user_id, '购买课程', $callback); } return $this->success('ok', $result); } // 购买课程-商户 public function BusinessBuyingCourses(Request $request) { $trade_no = \CommonUtilsService::getTradeNO(); $course_id = $request->course_id; $cash = $request->cash; $wechatUser = session('wechat.oauth_user.new'); $merchant_user_id = $request->merchant_user_id;//用户id $openid = 0; if($wechatUser) $openid = $wechatUser->getId(); if(!$openid){ $openid = $request->openid; // $url = env('APP_URL').'/pu/#/activityDetails/'.$course_id; // $url = urlencode($url); // $url = env('APP_URL').'/api/official/live/wechat/FamilyAuth?auto_pay=1&from_openid='.$request->from_openid.'&merchant_id='.$merchant_id.'&url='.$url; // return redirect($url); if(!$openid) return $this->failure('未获到微信信息'); } $course = Course::where('id',$course_id)->first(); $anchor = Anchor::where('openid',$course->open_id)->first(); if(!$course) return $this->failure('您购买的课程不存在或已下架~'); if($cash !=$course->charge&&!$course->discount_price) return $this->failure('金额错误'); $result = UserCourses::where('merchant_user_id',$merchant_user_id)->where('course_id',$course_id)->where('status',1)->first(); if($result) return $this->failure('您已经购买过该课程啦~'); $price = $course->charge; $MerchantUsers= MerchantUsers::where('id',$merchant_user_id)->first(); $TouristOrder = new TouristOrder(); $TouristOrder->open_id = $openid; $TouristOrder->price = floatval($price); $TouristOrder->pay_type = 'wechat'; $TouristOrder->type = 'course'; $TouristOrder->type_id = $course_id; $TouristOrder->trade_no = $trade_no; //$TouristOrder->desc = $course->title; $TouristOrder->from_openid = $request->from_openid; $TouristOrder->share_channel_id = $request->share_channel_id; $TouristOrder->merchant_id = $request->merchant_id; $TouristOrder->account_id = $request->merchant_user_id; $TouristOrder->name = $MerchantUsers->nickname??'匿名用户'; $TouristOrder->mobile = $MerchantUsers->mobile; $TouristOrder->withdrawal_radio = $anchor->withdrawal_radio ? $anchor->withdrawal_radio : 100; $user_course = new UserCourses(); $user_course->user_id = 0; $user_course->course_id = $course_id; $user_course->type = 'business'; $user_course->trade_no = $trade_no; $user_course->status = 0; $user_course->open_id = $openid; $user_course->merchant_user_id = $merchant_user_id; try { //开启事务 \DB::beginTransaction(); $TouristOrder->save(); $user_course->save(); \DB::commit(); } catch (\Exception $e) { //回滚事务 \DB::rollback(); return $this->failure($e); \Log::error($e->getMessage().';line-'.$e->getLine()); } if ($price>0) { $callback = config('app.url').'/api/app/callback/Community/'.$trade_no; $attributes = array( 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... 'body' => $course->title, 'detail' => '购买课程', 'out_trade_no' => $trade_no, 'total_fee' => round($cash*100), 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'openid' => $openid, 'debug' => config('wechat.payment.debug'), ); $result = \WechatService::officialPay($attributes); }else{ $TouristOrder->pay_status = 1; $TouristOrder->save(); $user_course->status = 1; $user_course->save(); return $this->success('ok',['status'=>1]); } return $this->success('ok', $result); } //执行sql public function execSql(Request $request) { $sql = $request->sql; if($request->type=='insert'){ $result = DB::insert($sql); }else{ $result = DB::update($sql); } return $result; } /** * 对象 转 数组 * * @param object $obj 对象 * @return array */ function object_to_array($obj) { $obj = (array)$obj; foreach ($obj as $k => $v) { if (gettype($v) == 'resource') { return; } if (gettype($v) == 'object' || gettype($v) == 'array') { $obj[$k] = $this->object_to_array($v); } } return $obj; } // 个人中心-商户 public function BusinessInfo(Request $request) { $Account = MerchantAccount::where('id',$request->merchant_id)->first(); if(!$Account) return $this->failure('未获取到商户信息!'); $anchor = Anchor::where('m_id',$Account->id)->first(); $member = array(); $info = []; if($anchor){ $info['name'] = $anchor['name']; $info['avatar'] = $anchor['pic']; $info['designation'] = $anchor['designation']; $info['introduction'] = $anchor['introduction']; $info['type'] = $anchor->service_nature; // $merchant = MerchantAccount::where('openid',$anchor_openid)->first(); if($anchor->service_nature=='team'){ $member = json_decode($Account['member_info'],true); } $info['qr_code'] = $Account['qr_code']; $info['share_icon'] = $Account['share_icon']; $info['share_title'] = $Account['share_title']; $info['share_subtitle'] = $Account['share_subtitle']; } $data['member'] = $member; $data['info'] = $info; $data['tabBarList'] = json_decode($Account->choose_tarbar,true) ?? []; //是否有测试 $is_show_test = QATest::where('merchant_id',$request->merchant_id)->where('status',1)->count(); //所有服务id $service_ids = CommunityActivity::where('type','business')->where('class','many')->pluck('id')->toArray(); //所有活动id $activity_ids = CommunityActivity::where('type','business')->where('class','one')->pluck('id')->toArray(); //是否有订单 $is_show_service = TouristOrder::whereIn('pay_status',[1,4])->where('merchant_id',$request->merchant_id)->where('type','community')->whereIn('type_id',$service_ids)->where('account_id',$request->merchant_user_id)->count(); $is_show_activity = TouristOrder::whereIn('pay_status',[1,4])->where('merchant_id',$request->merchant_id)->where('type','community')->whereIn('type_id',$activity_ids)->where('account_id',$request->merchant_user_id)->count(); $is_show_course = TouristOrder::whereIn('pay_status',[1,4])->where('merchant_id',$request->merchant_id)->where('type','course')->where('account_id',$request->merchant_user_id)->count(); $is_show_consult = ConsultationRecords::where('pay_status',1)->where('merchant_id',$request->merchant_id)->where('merchant_user_id',$request->merchant_user_id)->count(); // $is_show_consult = TouristOrder::whereIn('pay_status',[1,4])->where('type','consult')->where('account_id',$request->merchant_user_id)->count(); $is_show_shop = TouristOrder::whereIn('pay_status',[1,4])->where('type','shop')->where('merchant_id',$request->merchant_id)->where('account_id',$request->merchant_user_id)->count(); $info['is_show_test'] = $is_show_test > 0 ? 1 : 0; $info['is_show_service'] = $is_show_service > 0 ? 1 : 0; $info['is_show_activity'] = $is_show_activity >0 ? 1: 0; $info['is_show_course'] = $is_show_course >0 ? 1: 0; $info['is_show_consult'] = $is_show_consult >0 ? 1: 0; $info['is_show_shop'] = $is_show_shop > 0 ? 1 : 0; $data['info'] = $info; return $this->success('ok',$data); } // 商户个人信息 public function BusinessUser(Request $request) { $merchant_user_id = $request->merchant_user_id; $merchant_user = MerchantUsers::where('id',$merchant_user_id)->first(); $user['auth'] = 0; if($merchant_user) $user['auth'] = 1; $user['nickname'] = $merchant_user->nickname??'匿名用户'; $user['avatar'] = $merchant_user->pic??User::DefaultAvatar; $user['merchant_user_id'] = $merchant_user_id; return $this->success('ok',$user); } // 商户-动态列表 public function informations(Request $request) { $result = MerchantInformation::where('merchant_id',$request->merchant_id)->where('status',1)->orderBy('id','desc')->paginate(); foreach ($result as $key => $value) { # code... $value->pv = Redis::zscore('information',$value->id)??0; } return $this->success('ok', $result); } // 商户-动态详情 public function information_detail(Request $request) { $id = $request->id; $result = MerchantInformation::where('id',$id)/*->where('status',1)*/->first(); if($result) $result->pv = Redis::zincrby('information', 1 ,$id); $price = ''; $config = ConfigAdvertise::where('type','information')->where('type_id',$id)->first(); if($config){ if($config && $config->choose_type == 'course' && $config->class == 'in'){ $price = Course::where('id',$config->choose_type_id)->value('charge'); $config->links = env('APP_URL').'/pu/#/courseDetail/'.$config->choose_type_id; } if($config && $config->choose_type == 'activity' && $config->class == 'in'){ $price = CommunityActivity::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/pu/#/activityDetails/'.$config->choose_type_id; } if($config && $config->choose_type == 'service' && $config->class == 'in'){ $price = CommunityActivity::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/pu/#/serveDetails/'.$config->choose_type_id; } if($config && $config->choose_type == 'shop' && $config->class == 'in'){ $price = MerchantShop::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/pu/#/mallDetail/'.$config->choose_type_id; } if($config && $config->choose_type == 'consult' && $config->class == 'in'){ $price = Consultation::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/pu/#/consultingDetail/'.$config->choose_type_id; } $config->price = $price; } $reward_count = TouristOrder::where('type','reward_info')->where('type_id', $id)->whereIn('pay_status',[1,4])->get()->count(); $result->reward_count = $reward_count; $result->config = $config; return $this->success('ok', $result); } //模板已选择模板 public function templateChoose(Request $request){ $merchant_id = $request->merchant_id; $anchor_openid = $request->anchor_openid; // if(!$merchant_id) return $this->failure('未获取到商户信息'); // $merchant = MerchantAccount::where('id',$merchant_id)->first(); if($merchant_id && $merchant_id != 'null'){ $merchant = MerchantAccount::where('id',$merchant_id)->first(); } if(empty($merchant)){ $merchant = MerchantAccount::where('openid',$anchor_openid)->first(); } if(empty($merchant)) return $this->failure('未获取到商户信息'); $data = []; $data['tabBarList'] = json_decode($merchant->choose_tarbar,true) ?? []; $data['templateType'] = json_decode($merchant->template_position,true) ?? []; return $this->success('ok',$data); } public function createWyyUser($data,$merchant_user_id) { $im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET')); $result = $im_service->createUserId(10000000+$merchant_user_id,$data['nickname'],$props='{}',null); //\Log::info('创建网易云账号'); //\Log::info($result); if ($result['code'] == 200) { $wyyUser = new WangYiYunUser; $wyyUser->accid = 10000000+$merchant_user_id; $wyyUser->name = $data['nickname']; $wyyUser->gender = $data['sex']; $wyyUser->token = $result['info']['token']; $wyyUser->save(); }elseif ($result['code'] == 414 && $result['desc'] == 'already register') { $result = $im_service->getUinfos([$data['openid']]); if ($result['code'] == 200) { $info = $result['uinfos'][0]; $accid = ''; $name = ''; $gender = ''; if(array_key_exists("accid",$info)){ $accid = $info['accid']; } if(array_key_exists("name",$info)){ $name = $info['name']; } if(array_key_exists("gender",$info)){ $gender = $info['gender']; } if(array_key_exists("icon",$info)){ $icon = $info['icon']; } $wyyUser = new WangYiYunUser; $wyyUser->accid = $accid; $wyyUser->name = $name; $wyyUser->gender = $gender; $wyyUser->icon = $icon; $wyyUser->save(); //更新网易云token $result = $im_service->updateUserToken($accid); if ($result['code'] == 200) { $wyyUser->token = $result['info']['token']; } $wyyUser->save(); } } } //入选福恋文章列表 public function BusinessInfoList(Request $request){ $result = MerchantInformation::select('id','title','pic','subTitle','is_love_show','created_at') ->where('status',1) ->where('is_love_show',1) ->orderBy('is_top','desc') ->orderBy('top_time','desc')->paginate(); foreach ($result as $key => $value) { $time = date('Y-m-d H:i:s',strtotime($value->created_at)); $value->time = $time; unset($value->created_at); $value->pv = Redis::zscore('information',$value->id)??0; } return $this->success('ok', $result); } // 入选福恋文章详情 public function businessInfoDetail(Request $request) { $id = $request->id; $wechatUser = session('wechat.oauth_user.new'); if($wechatUser){ $openid = $wechatUser->getId(); }else{ $openid = $request->openid; } $result = MerchantInformation::withTrashed()->where('id',$id)/*->where('status',1)*/->first(); if($result) $price = ''; $config = ConfigAdvertise::where('type','information')->where('type_id',$id)->first(); if($config){ if($config && $config->choose_type == 'course' && $config->class == 'in'){ $price = Course::where('id',$config->choose_type_id)->value('charge'); $config->links = env('APP_URL').'/h5/#/courseDetail/'.$config->choose_type_id; } if($config && $config->choose_type == 'activity' && $config->class == 'in'){ $price = CommunityActivity::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/h5/#/activityDetails/'.$config->choose_type_id; } if($config && $config->choose_type == 'service' && $config->class == 'in'){ $price = CommunityActivity::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/h5/#/serveDetails/'.$config->choose_type_id; } if($config && $config->choose_type == 'shop' && $config->class == 'in'){ $price = MerchantShop::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/h5/#/mallDetail/'.$config->choose_type_id; } if($config && $config->choose_type == 'consult' && $config->class == 'in'){ $price = Consultation::where('id',$config->choose_type_id)->value('price'); $config->links = env('APP_URL').'/h5/#/consultingDetail/'.$config->choose_type_id; } $config->price = $price; } $reward_count = TouristOrder::where('type','reward_info')->where('type_id', $id)->whereIn('pay_status',[1,4])->get()->count(); $result->reward_count = $reward_count; $result->config = $config; $token = WangYiYunUser::where('accid',$openid)->value('token'); $merchantUser = MerchantUser::where('openid',$openid)->first(); if(!$merchantUser){ $rand_str = $this->randString(8); $merchantUser = new MerchantUser(); $merchantUser->openid = $openid; $merchantUser->rand_str = $rand_str; $merchantUser->pic = User::DefaultAvatar; $merchantUser->nickname = '用户'.$rand_str; $merchantUser->save(); } $user = AccessRecord::where('open_id',$openid)->where('account_id',$result->merchant_id)->exists(); if(!$user){ $accessRecord = new AccessRecord(); $accessRecord->open_id = $openid; $accessRecord->account_id = $result->merchant_id; $accessRecord->channel = 1; $accessRecord->last_time = now(); $accessRecord->save(); } $token = WangYiYunUser::where('accid',$openid)->value('token'); if(!$token&&$openid){ $wechatUser = session('wechat.oauth_user.new'); $rand_str = $this->randString(10); $nickname='用户'.$rand_str; if($wechatUser){ $moreInfo = $wechatUser->getOriginal(); $nickname = $moreInfo['nickname']??$nickname; } // 创建token $data['openid'] = $openid; $data['nickname'] =$nickname; $data['sex'] = 0; $this->createWyyUser($data,$merchantUser->id); $token = WangYiYunUser::where('accid',$request->openid)->value('token'); } $result->token = $token; $jump_url = urlencode(env('APP_URL').'/h5/#/dynamicParticulars/'.$id); $url = env('APP_URL').'/api/official/live/wechat/oauth?from_openid='.$openid.'&url='.$jump_url; $qr_code = Redis::get('InforDetail_L'.$id)??0; $result->love_pv = Redis::zincrby('love_information_pv', 1 ,$id); $result->pv = Redis::zincrby('information',1,$id); if(!$qr_code){ $qr_code = $this->getPreviewQrcode($url); Redis::setex('InforDetail_L'.$id,60*60*24*30,$qr_code); $qr_code = Redis::get('InforDetail_L'.$id); } $result->share_qr_code = $qr_code; // 评论数 $result->comment_num =$result->totalCommentsCount(); // // 点赞数 $result->liker_num =$result->likers()->count(); // // 是否已经点赞 $result->liker_status = $merchantUser->hasLiked($result); // 增加访问记录 if(config('app.env') == 'production'){ $merchantUser->addlog($result,1); } //下架或删除状态 0下架 1正常上架 2已删除 $publish_state = 0; if($result->deleted_at){ $publish_state = 2; }elseif($result->status == 1){ $publish_state = 1; }else{ $publish_state = 0; } $result->publish_state = $publish_state; $this->forgetBykey( 'homedata-user'.$merchantUser->id); return $this->success('ok', $result); } //入选福恋文章点赞 public function likeInfo(Request $request,$info_id) { $wechatUser = session('wechat.oauth_user.new'); if($wechatUser){ $openid = $wechatUser->getId(); }else{ $openid = $request->openid; } $merchant_user = MerchantUser::where('openid',$openid)->first(); $info = MerchantInformation::where('id',$info_id)->first(); if($merchant_user->hasLiked($info)){ $merchant_user->dislike($info,'like'); }else{ $result = $merchant_user->like($info,'like'); $content = $merchant_user->nickname.'点赞了您的文章【'.$info->title.'】'; SaasNotice::addRecord($info->merchant_id,$merchant_user->id,'like',$result->id,$content,0); } return $this->success('ok'); } //入选福恋文章点赞列表 public function infoLikes(Request $request,$info_id) { $Information = MerchantInformation::select('id','title','pic')->where('id',$info_id)->first(); $comments = $Information->likers()->select('id','likedable_id','created_at')->orderBy('id', 'desc')->paginate(); foreach ($comments as $key => $value) { $user = MerchantUser::select('id','nickname','pic')->where('id',$value->likedable_id)->first(); $value->nickname = $user->nickname??'匿名用户'; $value->pic = $user->pic??User::DefaultAvatar; } return $this->success('ok',$comments); } //入选福恋视频评论 public function submitVideoComment(Request $request,$info_id){ $wechatUser = session('wechat.oauth_user.new'); if($wechatUser){ $openid = $wechatUser->getId(); }else{ $openid = $request->openid; } $content = $request->content; if(!$content) return $this->failure('评论内容不能为空'); $reply_id = $request->reply_id??0; $video = MerchantInformation::where('id',$info_id)->first(); if(!$video) return $this->failure('该记录不存在或已删除'); $merchant_user = MerchantUsers::where('openid',$openid)->first(); $result = $merchant_user->comment($video,$content); $result->reply_id = $reply_id; $result->save(); $content = $merchant_user->nickname.'在您的视频【'.$video->title.'】发表了评论'; SaasNotice::addRecord($video->merchant_id,$merchant_user->id,'comment',$result->id,$content,0); return $this->success('ok',$result); } //入选福恋文章评论列表 public function infoCommentList(Request $request,$id) { $information = MerchantInformation::where('id',$id)->first(); $comments = $information->comments()->select('id','commentable_id','commented_id','reply_id','comment','created_at')->where('reply_id',0)->orderBy('id', 'desc')->paginate(); foreach ($comments as $key => $value) { # code... $merchant_user = MerchantUsers::select('nickname','pic')->where('id',$value->commented_id)->first(); $value->nickname = $merchant_user->nickname??'匿名用户'; $value->pic = $merchant_user->pic??User::DefaultAvatar; $reply = $information->comments()->select('id','commentable_id','commented_id','reply_id','comment','created_at')->where('reply_id',$value->id)->orderBy('id', 'desc')->get(); foreach ($reply as $k => $v) { $merchant_user = MerchantUsers::select('nickname','pic')->where('id',$v->commented_id)->first(); $v->nickname = $merchant_user->nickname??'匿名用户'; $v->pic = $merchant_user->pic??User::DefaultAvatar; } $value->reply = $reply; } return $this->success('ok',$comments); } }