public function dUserNotice() { if (!Sentry::check()) { return Response::json(array('errCode' => 10, 'message' => '请登录')); } $user = Sentry::getUser(); $join_coms = ArticleJoinCom::where('receiver_id', '=', $user->id)->where('is_delete', '=', 0)->get(); $replys = ArticleJoinReply::where('receiver_id', '=', $user->id)->where('is_delete', '=', 0)->get(); try { DB::transaction(function () use($replys, $join_coms) { if (count($join_coms) != 0) { foreach ($join_coms as $com) { $com->is_delete = 1; $com->save(); } } if (count($replys) != 0) { foreach ($replys as $reply) { $reply->is_delete = 1; $reply->save(); } } }); } catch (\Exception $e) { return Response::json(array('errCode' => 11, 'message' => '操作失败')); } return Response::json(array('errCode' => 0, 'message' => '删除成功')); }
public function brefUser() { if (!Sentry::check()) { return Response::json(array('errCode' => 10, 'message' => '请登录')); } $user = Sentry::getUser(); // $user = User::find(5); // Auth::login(); // dd($user); $per_page = Input::get('per_page'); $page = Input::get('page'); $join_coms = ArticleJoinCom::where('receiver_id', '=', $user->id)->where('is_delete', '=', 0)->orderBy('created_at', 'desc')->get(); if (count($join_coms) != 0) { foreach ($join_coms as $com) { $com_sender = User::find($com->sender_id); $com->avatar = $com_sender->avatar; $com->username = $com_sender->username; $com->type = "comment"; } } $replys = ArticleJoinReply::where('receiver_id', '=', $user->id)->where('status', '=', 0)->where('is_delete', '=', 0)->orderBy('created_at', 'desc')->get(); if (count($replys) != 0) { foreach ($replys as $reply) { $reply->join_id = ArticleJoinCom::where('id', '=', $reply->com_id)->first()->join_id; $reply_sender = User::find($reply->sender_id); $reply->avatar = $reply_sender->avatar; $reply->username = $reply_sender->username; $reply->type = "reply"; } } $notices = array_merge($join_coms->toArray(), $replys->toArray()); //总页数 $total = ceil(count($notices) / $per_page); //排序 $notices = StaticController::arraySortByCreatedAt($notices); //分页 $notices = StaticController::page($per_page, $page, $notices); // dd(count($notices)); return Response::json(array('errCode' => 0, 'message' => '返回回复者头像和名字', 'notices' => $notices, 'total' => $total)); }
public function involve() { //参与话题内容 $join_id = Input::get('join_id'); $article_join = ArticleJoin::find($join_id); if (!isset($article_join)) { return Response::json(array('errCode' => 1, 'message' => '没有该参与话题内容!')); } $article_join_parts = ArticleJoinPart::where('join_id', '=', $join_id)->orderBy('id', 'asc')->get(); foreach ($article_join_parts as $part) { if ($part->type == 'url') { $part->img = StaticController::imageWH($part->content); } } //评论内容 $per_page = Input::get('per_page'); $page = Input::get('page'); $join_coms = ArticleJoinCom::where('join_id', '=', $join_id)->with(['replies' => function ($query) { $query->select('com_id', 'content', 'sender_id')->orderBy('id', 'asc'); }, 'sender' => function ($query) { $query->select('id', 'username', 'avatar'); }, 'replies.sender' => function ($query) { $query->select('id', 'username'); }])->get(); foreach ($join_coms as $join_com) { $user = $join_com->sender; $join_com->username = $user->username; $join_com->avatar = $user->avatar; $join_com->replys = $join_com->replies; if (count($join_com->replys) != 0) { foreach ($join_com->replys as $reply) { // dd($reply); $reply->reply_name = $reply->sender->username; unset($reply->sender); } } unset($join_com->replies); unset($join_com->sender); } // //总页数 $total = ceil(count($join_coms) / $per_page); // //文章 $join_coms = StaticController::page($per_page, $page, $join_coms); // $join_coms = DB::table('article_join_coms')->where('join_id', '=', $join_id)->get(); // //总页数 // $total = ceil(count($join_coms)/$per_page); // //文章 // $join_coms = StaticController::page($per_page,$page,$join_coms); // if( $join_coms ) // { // foreach($join_coms as $join_com) // { // $join_com->username = User::find($join_com->sender_id)->username; // $join_com->avatar = User::find($join_com->sender_id)->avatar; // $join_com->replys = ArticleJoinReply::where('com_id', '=', $join_com->id)->orderBy('id','asc')->get(); // if(count($join_com->replys)!=0) // { // foreach($join_com->replys as $reply) // { // $reply->reply_name = User::find($reply->sender_id)->username; // } // } // } // } //是否喜欢 $type = $this->isJoinLike($join_id); if ($page == 1) { return Response::json(array('errCode' => 0, 'message' => '返回参与话题详情', 'article_join' => $article_join, 'article_join_parts' => $article_join_parts, 'join_coms' => $join_coms, 'total' => $total, 'type' => $type)); } else { return Response::json(array('errCode' => 0, 'message' => '返回参与话题详情', 'join_coms' => $join_coms, 'total' => $total, 'type' => $type)); } }