public function topicDetail() { $topic_id = Input::get('topic_id'); $topic = Topic::find($topic_id); if (!isset($topic)) { return Response::view('errors.missing'); } //预载入 $gifts = Gift::where('topic_id', $topic->id)->with(['giftPosters' => function ($query) { $query->orderBy('created_at', 'asc'); }])->get(); $number = 1; foreach ($gifts as $gift) { $gift->img = $gift->giftPosters[0]->url; $gift->number = $number++; } // $gifts = Gift::where('topic_id', '=', $topic->id)->get(); // if(isset($gifts)) // { $number = 1; // foreach($gifts as $gift) // { // $url = GiftPoster::where('gift_id','=',$gift->id)->first()->url; // // $gift->img = StaticController::imageWH($url); // $gift->img = $url; // $gift->number = $number++; // } // } $gifts = $this->isGiftLike($gifts); $type = $this->isTopicLike($topic_id); return View::make('pc.subject')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type)); }
public function selectByLabel() { $inputs = array('char_id' => Input::get('_char'), 'scene_id' => Input::get('scene'), 'object_id' => Input::get('object'), 'price_id' => Input::get('price')); // dd($inputs['object_id']); $per_page = Input::get('per_page'); $page = Input::get('page'); $inputs = array_filter($inputs); // dd(count($inputs)); $query = null; // dd($inputs['price_id']); foreach ($inputs as $key => $value) { if ($query != null) { $query = $query->where($key, $value); } else { $query = Gift::where($key, $value); } } if ($query == null) { // dd(count($gifts)); //标签没有的情况 // $gifts = StaticController::gifts(); $gifts = Gift::orderBy('created_at', 'desc')->get(); $total = ceil(count($gifts) / $per_page); $gifts = StaticController::page($per_page, $page, $gifts); $gifts = $this->addGiftImg($gifts); return Response::json(array('errCode' => 0, 'message' => '没有筛选礼品,返回全部', 'gifts' => $gifts, 'total' => $total)); } $gifts = $query->get(); if (count($gifts) == 0) { // $gifts = StaticController::gifts(); $gifts = Gift::orderBy('created_at', 'desc')->get(); $total = ceil(count($gifts) / $per_page); $gifts = StaticController::page($per_page, $page, $gifts); $gifts = $this->addGiftImg($gifts); return Response::json(array('errCode' => 0, 'message' => '没有筛选礼品,返回全部', 'gifts' => $gifts, 'total' => $total)); } $total = ceil(count($gifts) / $per_page); $gifts = StaticController::page($per_page, $page, $gifts); $gifts = $this->addGiftImg($gifts); return Response::json(array('errCode' => 0, 'message' => '返回搜索数据', 'gifts' => $gifts, 'total' => $total)); }
public function topic() { $topic_id = Input::get('topic_id'); $topic = Topic::find($topic_id); if (!isset($topic)) { if (Request::wantsJson()) { return Response::json(array('errCode' => 1, 'message' => 该专题不存在)); } else { return Response::view('errors.missing'); } } $gifts = Gift::where('topic_id', '=', $topic->id)->get(); if (isset($gifts)) { $number = 1; foreach ($gifts as $gift) { $url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url; $gift->img = StaticController::imageWH($url); $gift->number = $number++; } } $gifts = $this->isGiftLike($gifts); $type = $this->isTopicLike($topic_id); if (Request::wantsJson()) { return Response::json(array('errCode' => 0, 'message' => '返回专题页数据', 'topic' => $topic, 'gifts' => $gifts, 'type' => $type)); } return View::make('index/goodsList')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type)); }