Ejemplo n.º 1
0
 public function collection()
 {
     if (!Sentry::check()) {
         return Response::json(array('errCode' => 10, 'message' => '请登录'));
     }
     $gift_id = Input::get('gift_id');
     /* 2015-09-16 hyy 改 start */
     $gift_focus = GiftFocus::where('user_id', '=', Sentry::getUser()->id)->where('gift_id', '=', $gift_id)->first();
     if (isset($gift_focus)) {
         try {
             DB::transaction(function () use($gift_id, $gift_focus) {
                 //礼品收藏人数减1
                 $gift = Gift::find($gift_id);
                 $gift->focus_num = $gift->focus_num - 1;
                 $gift->save();
                 $gift_focus->delete();
             });
         } catch (\Exception $e) {
             return Response::json(array('errCode' => 11, 'message' => '操作失败'));
         }
         /* 2015-09-16 hyy 改 end */
         return Response::json(array('errCode' => 0, 'message' => 'cancel'));
     } else {
         try {
             DB::transaction(function () use($gift_id) {
                 //礼品收藏人数加1
                 $gift = Gift::find($gift_id);
                 $gift->focus_num = $gift->focus_num + 1;
                 $gift->save();
                 $gift_focus = new GiftFocus();
                 $gift_focus->user_id = Sentry::getUser()->id;
                 $gift_focus->gift_id = $gift_id;
                 $gift_focus->save();
             });
         } catch (\Exception $e) {
             return Response::json(array('errCode' => 11, 'message' => '操作失败'));
         }
         return Response::json(array('errCode' => 0, 'message' => 'collect'));
     }
 }
Ejemplo n.º 2
0
 public function home()
 {
     $scroll_imgs = ScrollImg::all();
     //话题
     $topics = Topic::where('topic_url', '!=', '')->orderBy('created_at', 'desc')->get();
     $topics = StaticController::page(12, 1, $topics);
     //每日推荐
     $daily = Poster::where('daily_id', '=', 1)->get();
     //每日推
     $daily = StaticController::page(16, 1, $daily);
     // $user = Sentry::findUserById(4);
     // Sentry::login($user,false);
     // Sentry::logout();
     if (Sentry::check()) {
         foreach ($daily as $recommend) {
             $gift = Gift::find($recommend->info_url);
             $recommend->title = $gift->title;
             $recommend->price = $gift->price;
             $recommend->taobao_url = $gift->taobao_url;
             $gift_focus = GiftFocus::where('gift_id', '=', $recommend->info_url)->where('user_id', '=', Sentry::getUser()->id)->first();
             /* 2015-09-16 hyy fix */
             if (isset($gift_focus)) {
                 $recommend->focus = 1;
             } else {
                 $recommend->focus = 0;
             }
         }
     } else {
         foreach ($daily as $recommend) {
             $gift = Gift::find($recommend->info_url);
             $recommend->title = $gift->title;
             $recommend->price = $gift->price;
             $recommend->taobao_url = $gift->taobao_url;
             $recommend->focus = 0;
         }
     }
     //精选话题
     $articles = DB::table('articles')->orderBy('focus_num', 'desc')->get();
     $articles = StaticController::page(12, 1, $articles);
     if ($articles) {
         foreach ($articles as $article) {
             $article_url = ArticlePart::where('article_id', '=', $article->id)->where('type', '=', 'url')->first();
             // dd($article_url->content);
             if (isset($article)) {
                 $article->url = $article_url->content;
             } else {
                 $article->url = null;
             }
         }
     }
     return View::make('pc.home')->with(array('topics' => $topics, 'gifts' => $daily, 'articles' => $articles, 'scroll_imgs' => $scroll_imgs));
 }
Ejemplo n.º 3
0
 public function isGiftLike($gifts)
 {
     foreach ($gifts as $gift) {
         if (Sentry::check()) {
             /* 2015-09-16 hyy 改 start */
             $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;
             }
             /* 2015-09-16 hyy 改 end */
         }
     }
     return $gifts;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 public function run()
 {
     $i = 0;
     for ($i = 0; $i < 200; $i++) {
         GiftFocus::create(['gift_id' => $i + 1, 'user_id' => 1]);
     }
     // GiftFocus::create([
     // 	'gift_id'=>2,
     // 	'user_id' =>2
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>3,
     // 	'user_id' =>3
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>4,
     // 	'user_id' =>4
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>5,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>6,
     // 	'user_id' =>2
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>7,
     // 	'user_id' =>3
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>8,
     // 	'user_id' =>4
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>9,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>10,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>11,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>12,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>13,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>14,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>15,
     // 	'user_id' =>1
     // ]);
     // GiftFocus::create([
     // 	'gift_id'=>16,
     // 	'user_id' =>1
     // ]);
 }