render(); } public function getCommentsCategoryList() { $search = request()->input('search'); $commentsList = Comment::uniacid(); if (isset($search['video_title'])) { $commentsList = $commentsList->whereHas('video', function ($query) use ($search) { $query->where('title', 'like', '%' . $search['video_title'] . '%'); }); } if (isset($search['member_id'])) { $commentsList = $commentsList->where('uid', 'like', '%' . $search['member_id'] . '%'); } if (isset($search['member_msg'])) { $commentsList = $commentsList->whereHas('member', function ($query) use ($search) { $query->where('mobile', 'like', '%' . $search['member_msg'] . '%') ->orwhere('nickname', 'like', '%' . $search['member_msg'] . '%') ->orwhere('realname', 'like', '%' . $search['member_msg'] . '%'); }); } if (isset($search['time'])) { $commentsList = $commentsList->whereBetween('created_at', [$search['time']['start'], $search['time']['end']]); } $commentsList = $commentsList->orderBy('created_at', 'desc')->paginate(); $commentsList->getCollection()->transform(function ($model) { return [ 'id' => $model->id, 'uid' => $model->uid, 'nick_name' => $model->nick_name, 'head_img_url' => $model->head_img_url, 'content' => $model->content, 'video' => [ 'video_title' => $model->video->title, 'video_url' => yz_tomedia($model->video->video), "cover" => yz_tomedia($model->video->cover) ], 'created_at' => $model->created_at->format('Y-m-d H:i:s'), ]; }); return $this->successJson('ok', $commentsList); } public function displayComments() { $id = \YunShop::request()->id; $finder = VideoShareGoods::uniacid()->find($id); if (!$finder) { throw new AppException('不存在的视频'); } return view('Yunshop\VideoShare::comments.view-comments')->render(); } public function getDisplayCommentsList() { $id = \YunShop::request()->id; $num = Comment::uniacid() ->where('video_id', $id) ->count(); $finder = VideoShareGoods::uniacid()->find($id); if (!$finder) { throw new AppException('不存在的视频'); } $commentsList = Comment::uniacid() ->with(['hasManyReply', 'hasManySupport' => function ($q) { $q->where(['member_id' => \YunShop::app()->getMemberId(), 'status' => 1]); }]) ->where(['video_id' => $id, 'comment_id' => 0]) ->orderBy('created_at', 'desc') ->orderBy('id', 'desc') ->paginate(); $commentsList->getCollection()->transform(function ($model) { return [ 'id' => $model->id, 'uid' => $model->uid, 'nick_name' => $model->nick_name, 'head_img_url' => $model->head_img_url, 'content' => $model->content, 'created_at' => $model->created_at->format('Y-m-d H:i:s'), 'children_comment' => $model->hasManyReply->transform(function ($model) { return [ 'id' => $model->id, 'nick_name' => $model->nick_name, 'head_img_url' => $model->head_img_url, 'content' => $model->content, 'created_at' => $model->created_at->format('Y-m-d H:i:s'), 'reply_name' => $model->reply_name, ]; }) ]; }); return $this->successJson('ok', [ 'commentsList' => $commentsList, 'num' => $num ]); } public function del() { $id = \YunShop::request()->id; $comment = Comment::uniacid() ->where('id', $id) ->first(); if (!$comment) { return $this->errorJson('评论不存在'); } if ($comment->comment_id != 0) { $comment->delete(); return $this->successJson('评论删除成功'); } if ($comment->comment_id == 0) { DB::beginTransaction(); try { Comment::where('comment_id', $id)->delete(); $comment->delete(); DB::commit(); return $this->successJson('评论删除成功'); } catch (\Exception $e) { DB::rollBack(); return $this->errorJson('评论删除失败'); } }; } }