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 function run() { $i = 0; for ($i = 0; $i < 200; $i++) { GiftPhotoIntro::create(['gift_id' => $i + 1, 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg']); GiftPhotoIntro::create(['gift_id' => $i + 1, 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg']); GiftPhotoIntro::create(['gift_id' => $i + 1, 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg']); GiftPhotoIntro::create(['gift_id' => $i + 1, 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg']); } // GiftPhotoIntro::create([ // 'gift_id' => 3, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 3, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 4, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 4, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 5, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 5, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 6, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 6, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 7, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 7, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 8, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 8, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 9, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 9, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 10, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 10, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 11, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 11, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 12, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 12, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 13, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 13, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 14, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 14, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 15, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 15, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 16, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); // GiftPhotoIntro::create([ // 'gift_id' => 16, // 'url' => 'http://7xl6gj.com1.z0.glb.clouddn.com/19.2.jpg' // ]); }
public function giftDetail() { $gift_id = Input::get('gift_id'); if (Request::wantsJson()) { if (!isset($gift_id)) { return Response::json(array('errCode' => 1, 'message' => '你查看的商品没有!')); } } else { if (!isset($gift_id)) { return Response::view('errors.missing'); } } $gift = Gift::find($gift_id); $gift_posters = GiftPoster::where('gift_id', '=', $gift_id)->get(); //做成数组传给移动端 if (count($gift_posters) != 0) { $gift_poster_array = array(); foreach ($gift_posters as $poster) { array_push($gift_poster_array, StaticController::imageWH($poster->url)); } } //收藏的人 $focus_users = Gift::find($gift_id)->users; //相似推荐 $gifts = DB::table('gifts')->where('scene_id', '=', $gift->scene_id)->where('object_id', '=', $gift->object_id)->where('char_id', '=', $gift->char_id)->get(); $gifts_like = array(); foreach ($gifts as $gift) { $gift_poster = GiftPoster::where('gift_id', '=', $gift->id)->first(); array_push($gifts_like, $gift_poster); } // dd(count($gifts_like) > 9); if (count($gifts_like) > 30) { $gifts_like = array_slice($gifts_like, 0, 30); } $gift_photo_intros = GiftPhotoIntro::where('gift_id', '=', $gift_id)->get(); // dd($gift->taobao_url); 变量名不要一样的,后面的会覆盖前面的 //做成数组传给移动端 if (count($gift_photo_intros) != 0) { $gift_intro_array = array(); foreach ($gift_photo_intros as $intro) { $url = StaticController::imageWH($intro->url); array_push($gift_intro_array, $url); } } $gift = Gift::find($gift_id); //是否喜欢 $type = $this->isLike($gift_id); if (Request::wantsJson()) { return Response::json(array('errCode' => 0, 'message' => '返回数据', 'gift' => $gift, 'gift_posters' => $gift_poster_array, 'focus_users' => $focus_users, 'gifts_like' => $gifts_like, 'gift_photo_intros' => $gift_intro_array, 'type' => $type)); } return View::make('index/goodDetails')->with(array('gift' => $gift, 'gift_posters' => $gift_posters, 'focus_users' => $focus_users, 'gifts_like' => $gifts_like, 'gift_photo_intros' => $gift_photo_intros, 'type' => $type)); }