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)); }