示例#1
0
 public function destroy(Request $request)
 {
     $this->validate($request, ['list' => 'required']);
     $result = DB::table('listfavs')->where('user_id', $request->user()->id)->where('list_id', $request->input('list'))->delete();
     if ($result) {
         Dramalist::where('id', $request->input('list'))->decrement('favorites');
     }
     return redirect()->back();
 }
示例#2
0
 public function destroy(Request $request, $id)
 {
     $list = Dramalist::find($id);
     $favorite = Listfav::select('user_id')->where('list_id', $id)->first();
     if ($favorite) {
         return '抱歉, 已有人收藏剧单,不能删除> <';
     }
     if ($list->user_id == $request->user()->id) {
         $list->delete();
     }
     return redirect()->route('user.lists', [$request->user()->id]);
 }
示例#3
0
 public function index(Request $request)
 {
     //判断url中是否有性向参数,若没有就默认性向为耽美type=0
     if ($request->has('type')) {
         $type = $request->input('type');
     } else {
         $type = 0;
     }
     //若type为-1,则查询全部新剧,否则按性向即type值查询
     if ($type < 0) {
         $episodes = Episode::join('dramas', function ($join) {
             $join->on('episodes.drama_id', '=', 'dramas.id')->where('episodes.release_date', '>=', date("Y-m-d", strtotime("-7 day")));
         })->select('dramas.title as drama_title', 'dramas.type as type', 'dramas.original as original', 'episodes.id as episode_id', 'episodes.title as episode_title', 'episodes.reviews as reviews', 'episodes.release_date as release_date', 'dramas.sc as sc', 'episodes.alias as alias', 'episodes.poster_url as poster_url', 'dramas.era as era', 'dramas.genre as genre', 'dramas.state as state', 'episodes.duration as duration')->orderBy('episode_id', 'desc')->get();
     } else {
         $episodes = Episode::join('dramas', function ($join) use($type) {
             $join->on('episodes.drama_id', '=', 'dramas.id')->where('dramas.type', '=', $type)->where('episodes.release_date', '>=', date("Y-m-d", strtotime("-7 day")));
         })->select('dramas.title as drama_title', 'dramas.type as type', 'dramas.original as original', 'episodes.id as episode_id', 'episodes.title as episode_title', 'episodes.reviews as reviews', 'episodes.release_date as release_date', 'dramas.sc as sc', 'episodes.alias as alias', 'episodes.poster_url as poster_url', 'dramas.era as era', 'dramas.genre as genre', 'dramas.state as state', 'episodes.duration as duration')->orderBy('episode_id', 'desc')->get();
     }
     $top10 = $episodes->take(10);
     //将一周新剧按发剧日期分组
     $episodes = $episodes->groupBy('release_date');
     //查询60天收藏数前10的剧单
     $lists = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select(DB::raw('count(*) as favorite_count, list_id'))->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-60 day")))->groupBy('list_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //最新剧单
     $newlists = Dramalist::select('id', 'title')->orderBy('id', 'desc')->take(10)->get();
     //查询30天评论数前10的剧集id
     $hotDramas = Review::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, drama_id'))->groupBy('drama_id')->orderBy('review_count', 'desc')->take(10)->get();
     //查询30天收藏前10的剧集id
     $hotFavorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, drama_id'))->groupBy('drama_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //查询最新10条新剧的添加历史
     $versions = Dramaver::select('user_id', 'drama_id', 'created_at')->where('first', 1)->orderBy('drama_id', 'desc')->take(10)->get();
     $versions->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $versions->load(['drama' => function ($query) {
         $query->select('id', 'title', 'sc');
     }]);
     $versions = $versions->filter(function ($version) {
         return isset($version->drama->id);
     });
     return view('index', ['type' => $type, 'episodes' => $episodes, 'top10' => $top10, 'lists' => $lists, 'newlists' => $newlists, 'hotDramas' => $hotDramas, 'hotFavorites' => $hotFavorites, 'versions' => $versions]);
 }
示例#4
0
 public function lists()
 {
     //最新剧单
     $newLists = Dramalist::select('id', 'title')->orderBy('id', 'desc')->take(10)->get();
     //查询60天收藏数前10的剧单
     $hotLists = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select(DB::raw('count(*) as favorite_count, list_id'))->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-60 day")))->groupBy('list_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //查询30天评论数前10的剧集id
     $hotDramas = Review::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, drama_id'))->groupBy('drama_id')->orderBy('review_count', 'desc')->take(10)->get();
     //查询30天收藏前10的剧集id
     $hotFavorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, drama_id'))->groupBy('drama_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     return ['newLists' => $newLists, 'hotLists' => $hotLists, 'hotDramas' => $hotDramas, 'hotFavorites' => $hotFavorites];
 }
示例#5
0
 public function lists($id)
 {
     $episode = Episode::find($id, ['id', 'drama_id', 'title']);
     $drama = Drama::find($episode->drama_id, ['id', 'title']);
     $items = Item::select('list_id', 'created_at')->where('episode_id', $id)->orderBy('id', 'desc')->paginate(50);
     $listids = $items->pluck('list_id');
     $lists = Dramalist::with(['user' => function ($query) {
         $query->select('id', 'name');
     }])->select('id', 'title', 'user_id')->whereIn('id', $listids)->get();
     return view('episode.lists', ['episode' => $episode, 'drama' => $drama, 'items' => $items, 'lists' => $lists]);
 }
示例#6
0
 public function destroy(Request $request, $id)
 {
     $item = Item::find($id);
     $list = Dramalist::find($item->list_id, ['user_id']);
     if ($list->user_id == $request->user()->id) {
         if ($item->delete()) {
             Item::where('list_id', $item->list_id)->where('no', '>', $item->no)->decrement('no');
             Dramalist::where('id', $item->list_id)->update(['updated_at' => $item->deleted_at]);
         }
     }
     return redirect()->back();
 }
示例#7
0
 public function lists($id)
 {
     $lists = Dramalist::select('id', 'title', 'created_at', 'updated_at')->where('user_id', $id)->paginate(50);
     $user = User::find($id, ['id', 'name']);
     return view('user.lists', ['user' => $user, 'lists' => $lists]);
 }