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 function insertData() { $gifts = json_decode(file_get_contents(app_path() . '/storage/gifts.txt')); $topics = json_decode(file_get_contents(app_path() . '/storage/topics.txt')); $gift_posters = json_decode(file_get_contents(app_path() . '/storage/gift_posters.txt')); $gift_photo_intros = json_decode(file_get_contents(app_path() . '/storage/gift_photo_intros.txt')); foreach ($topics as $topic) { $t = new Topic(); $t->id = $topic->id; $t->title = $topic->title; $t->content = $topic->content; $t->topic_url = $topic->topic_url; if (!$t->save()) { return 'topic_false'; } } foreach ($gifts as $gift) { $g = new Gift(); $g->id = $gift->id; $g->topic_id = $gift->topic_id; $g->title = $gift->title; $g->price = $gift->price; $g->content = $gift->content; if (!$g->save()) { return 'gift_false'; } } foreach ($gift_posters as $gift_poster) { $tp = new GiftPoster(); $tp->gift_id = $gift_poster->gift_id; $tp->url = $gift_poster->url; if (!$tp->save()) { return 'gift_poster_false'; } } foreach ($gift_photo_intros as $gift_photo_intro) { $gpi = new GiftPhotoIntro(); $gpi->gift_id = $gift_photo_intro->gift_id; $gpi->url = $gift_photo_intro->url; if (!$gpi->save()) { return 'gift_photo_intro_false'; } } return Response::json(array('errCode' => 0, 'message' => '插入成功')); }
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)); }
public function run() { $i = 0; for ($i = 0; $i < 200; $i++) { GiftPoster::create(['gift_id' => $i + 1, 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg']); } // GiftPoster::create([ // 'gift_id' => 1, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 2, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/35-7.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 3, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 4, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]);GiftPoster::create([ // 'gift_id' => 5, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/35-7.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 6, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/36-3.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 7, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/44-10.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 8, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 9, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/36-3.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 10, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 11, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/36-3.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 12, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 13, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/36-3.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 14, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 15, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPoster::create([ // 'gift_id' => 16, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/44-10.jpg' // ]); }