public function showWelcome() { $posters = Poster::where('daily_id', '=', 0)->get(); $topics = Topic::where('topic_url', '!=', '')->orderBy('created_at', 'desc')->get(); $daily = poster::where('daily_id', '=', 1)->get(); foreach ($daily as $recommend) { $gift = Gift::find($recommend->info_url); $recommend->content = $gift->content; $recommend->scan_num = $gift->scan_num; $recommend->focus_num = $gift->focus_num; } foreach ($posters as $poster) { $poster->photo_url = StaticController::imageWH($poster->photo_url); } foreach ($topics as $topic) { $topic->topic_url = StaticController::imageWH($topic->topic_url); } foreach ($daily as $day) { $day->photo_url = StaticController::imageWH($day->photo_url); } if (Request::wantsJson()) { return Response::json(array('errCode' => 0, 'message' => '返回首页首页数据', 'posters' => $posters, 'topics' => $topics, 'recommendations' => $daily)); } return View::make('index.home')->with(array('posters' => $posters, 'topics' => $topics, 'recommendations' => $daily)); }
public function home() { $scroll_imgs = ScrollImg::all(); //话题 $topics = Topic::where('topic_url', '!=', '')->orderBy('created_at', 'desc')->get(); $topics = StaticController::page(12, 1, $topics); //每日推荐 $daily = Poster::where('daily_id', '=', 1)->get(); //每日推 $daily = StaticController::page(16, 1, $daily); // $user = Sentry::findUserById(4); // Sentry::login($user,false); // Sentry::logout(); if (Sentry::check()) { foreach ($daily as $recommend) { $gift = Gift::find($recommend->info_url); $recommend->title = $gift->title; $recommend->price = $gift->price; $recommend->taobao_url = $gift->taobao_url; $gift_focus = GiftFocus::where('gift_id', '=', $recommend->info_url)->where('user_id', '=', Sentry::getUser()->id)->first(); /* 2015-09-16 hyy fix */ if (isset($gift_focus)) { $recommend->focus = 1; } else { $recommend->focus = 0; } } } else { foreach ($daily as $recommend) { $gift = Gift::find($recommend->info_url); $recommend->title = $gift->title; $recommend->price = $gift->price; $recommend->taobao_url = $gift->taobao_url; $recommend->focus = 0; } } //精选话题 $articles = DB::table('articles')->orderBy('focus_num', 'desc')->get(); $articles = StaticController::page(12, 1, $articles); if ($articles) { foreach ($articles as $article) { $article_url = ArticlePart::where('article_id', '=', $article->id)->where('type', '=', 'url')->first(); // dd($article_url->content); if (isset($article)) { $article->url = $article_url->content; } else { $article->url = null; } } } return View::make('pc.home')->with(array('topics' => $topics, 'gifts' => $daily, 'articles' => $articles, 'scroll_imgs' => $scroll_imgs)); }