Ejemplo n.º 1
0
 public function postReceive()
 {
     $code = Input::get('code');
     if ($code) {
         $coupon = AdminCoupon::where(['coupon_code' => $code])->first();
         if ($coupon) {
             $data = [];
             $data['coupon_id'] = $coupon->id;
             $data['user_id'] = Session::get('uid');
             $data['is_used'] = 0;
             $isCoupon = PhoneUserToCoupon::where($data)->first();
             if ($isCoupon) {
                 flash('亲,您已经领取过这个红包啦~');
                 return redirect()->back();
             }
             $couponToUser = new PhoneUserToCoupon();
             $couponToUser->coupon_id = $coupon->id;
             $couponToUser->user_id = Session::get('uid');
             if ($couponToUser->save()) {
                 $coupon->used += 1;
                 $coupon->save();
                 return redirect("coupon/success/{$coupon->coupon_price}");
             } else {
                 flash('亲~现在服务器压力山大~请稍后再试');
                 return redirect()->back();
             }
         } else {
             flash('亲~兑换码不对呦~请重试');
             return redirect()->back();
         }
     } else {
         flash('亲~兑换码不能为空哦~请重试');
         return redirect()->back();
     }
 }
Ejemplo n.º 2
0
 public function coupon()
 {
     return view('home.my.coupon')->withCoupons(PhoneUserToCoupon::where(['user_id' => Session::get('uid'), 'is_used' => 0])->get());
 }
Ejemplo n.º 3
0
 public function postDetails($id)
 {
     $skuId = Input::get('sku_id', 0);
     $couponId = Input::get('coupon_id', 0);
     if ($id and $skuId) {
         $sku = PhoneSku::find($skuId);
         if ($sku) {
             $shipping = VerifyUser::shipping(Session::get('uid'));
             $address = [];
             if ($shipping) {
                 if ($shipping->province) {
                     array_push($address, $shipping->province);
                 }
                 if ($shipping->city) {
                     array_push($address, $shipping->city);
                 }
                 if ($shipping->district) {
                     array_push($address, $shipping->district);
                 }
                 if ($shipping->address) {
                     array_push($address, $shipping->address);
                 }
             } else {
                 flash('亲~您还没有添加收货地址哦。');
                 return redirect('my/shipping/create');
             }
             $order = new PhoneOrder();
             $coupon = AdminCoupon::find($couponId);
             $totalFee = floatval($sku->price);
             if ($coupon) {
                 $order->coupon_id = $coupon->id;
                 $order->coupon_price = floatval($coupon->coupon_price);
                 $totalFee = floatval($sku->price) - floatval($coupon->coupon_price);
                 $userCouponData = ['coupon_id' => $couponId, 'user_id' => Session::get('uid')];
                 $userCoupon = PhoneUserToCoupon::where($userCouponData)->first();
                 if ($userCoupon) {
                     $userCoupon->is_used = 1;
                     $userCoupon->save();
                 }
             }
             if ($sku->product) {
                 $order->product_name = $sku->product->name;
                 $order->product_id = $sku->product->id;
             }
             $skuName = [];
             if ($sku->network) {
                 array_push($skuName, $sku->network->name);
             }
             if ($sku->memory) {
                 array_push($skuName, $sku->memory->name);
             }
             if ($sku->color) {
                 array_push($skuName, $sku->color->name);
             }
             if ($sku->storage) {
                 array_push($skuName, $sku->storage->name);
             }
             if ($sku->image) {
                 $order->product_image = $sku->image->image;
             }
             $order->sku_name = implode(' ', $skuName);
             $order->original_fee = floatval($sku->price);
             $order->total_fee = $totalFee;
             $order->user_id = Session::get('uid');
             $order->contacts_name = $shipping->name;
             $order->contacts_phone = $shipping->tel;
             $order->contacts_address = null;
             $order->contacts_zipcode = $shipping->zipcode;
             $order->contacts_address = implode(' ', $address);
             if ($order->save()) {
                 return redirect("order/success/{$order->id}");
             } else {
                 flash('亲~服务器繁忙,请稍后再试。');
                 return redirect()->back();
             }
         } else {
             flash('亲~服务器繁忙,请稍后再试。');
             return redirect()->back();
         }
     } else {
         flash('亲~服务器繁忙,请稍后再试。');
         return redirect()->back();
     }
 }