コード例 #1
0
ファイル: IndexController.php プロジェクト: suowei/saoju
 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]);
 }
コード例 #2
0
ファイル: ItemController.php プロジェクト: suowei/saoju
 public function create(Request $request)
 {
     $lists = Dramalist::select('id', 'title')->where('user_id', $request->user()->id)->get();
     if ($request->has('drama')) {
         $drama = Drama::find($request->input('drama'), ['id', 'title']);
         return view('item.create', ['drama' => $drama, 'lists' => $lists]);
     } else {
         if ($request->has('episode')) {
             $episode = Episode::find($request->input('episode'), ['id', 'drama_id', 'title']);
             $drama = Drama::find($episode->drama_id, ['id', 'title']);
             return view('item.create', ['drama' => $drama, 'episode' => $episode, 'lists' => $lists]);
         } else {
             return redirect()->back();
         }
     }
 }
コード例 #3
0
ファイル: IndexController.php プロジェクト: suowei/saoju
 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];
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: suowei/saoju
 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]);
 }