public static function gifts() { $gifts = Gift::orderBy('created_at', 'desc')->get(); foreach ($gifts as $gift) { $url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url; $gift->img = StaticController::imageWH($url); } return $gifts; }
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)); }