public function selectByWord() { $word = Input::get('word'); if (!isset($word)) { return Response::json(array('errCode' => 1, 'message' => '请输入关键字以搜索商品!')); } //TomLingham/Laravel-Searchy插件——模糊搜索 $gifts = Gift::where('title', 'like', '%' . $word . '%')->orderBy('created_at', 'desc')->get(); $per_page = Input::get('per_page'); $page = Input::get('page'); //筛选没有结果返回全部礼品 if (count($gifts) == 0) { $gifts = DB::table('gifts')->orderBy('created_at', 'desc')->get(); if (count($gifts)) { return Response::json(array('errCode' => 2, 'message' => '数据库没有数据')); } $total = $per_page == ceil(count($gifts) / $per_page); foreach ($gifts as $gift) { $url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url; $gift->img = StaitcController::imageWH($url); } $gifts = StaitcController::page($per_page, $page, $gifts); return Response::json(array('errCode' => 0, 'message' => '返回根据关键字筛选的商品', 'gifts' => $gifts)); } foreach ($gifts as $gift) { $url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url; $gift->img = StaitcController::imageWH($url); } $total = ceil(count($gifts) / $per_page); $gifts = StaitcController::page($per_page, $page, $gifts); return Response::json(array('errCode' => 0, 'message' => '返回根据关键字筛选的商品', 'gifts' => $gifts)); }
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 addGiftPhotoAndFocus($gifts) { foreach ($gifts as $gift) { $gift->url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url; if (Sentry::check()) { $gift_focus = GiftFocus::where('user_id', Sentry::getUser()->id)->where('gift_id', $gift->id)->first(); if (isset($gift_focus)) { $gift->type = 1; } else { $gift->type = 0; } } else { $gift->type = 0; } } return $gifts; }
public function giftAjax() { // if(!Sentry::check()) // return Response::json(array('errCode'=>1, 'message'=>'请登录')); // $user = Sentry::getUser(); $user = User::find(1); $per_page = Input::get('per_page'); $page = Input::get('page'); $gift_focus = DB::table('gift_focus')->where('user_id', '=', $user->id)->orderBy('created_at', 'desc')->get(); //总页数 $total = ceil(count($gift_focus) / $per_page); // dd($total); //喜欢的礼品 $focus = StaticController::page($per_page, $page, $gift_focus); // dd(count($focus)); $gifts = array(); if ($focus) { foreach ($focus as $gift) { array_push($gifts, Gift::find($gift->gift_id)); } foreach ($gifts as $candy) { $url = GiftPoster::where('gift_id', '=', $candy->id)->first()->url; $candy->img = StaticController::imageWH($url); } } 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)); }