Exemplo n.º 1
0
 public function create(Request $request)
 {
     $this->validate($request, ['list' => 'required']);
     if (Dramalist::find($request->input('list'), ['user_id'])->user_id == $request->user()->id) {
         return '抱歉,不能收藏自己创建的剧单> <';
     }
     $favorite = new Listfav();
     $favorite->list_id = $request->input('list');
     $favorite->user_id = $request->user()->id;
     $favorite->created_at = new Carbon();
     if ($favorite->save()) {
         Dramalist::where('id', $favorite->list_id)->increment('favorites');
     }
     return redirect()->route('list.show', [$favorite->list_id]);
 }
Exemplo n.º 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]);
 }
Exemplo n.º 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]);
 }
Exemplo n.º 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];
 }
Exemplo n.º 5
0
 public function listfavs(Request $request)
 {
     $listfavs = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select('list_id', 'created_at')->where('user_id', $request->user()->id)->orderBy('created_at', 'desc')->paginate(50);
     return view('user.listfavs', ['listfavs' => $listfavs]);
 }