public function getIndex()
 {
     $member_id = Auth::user()->id;
     $cart_books = Cart::with('Books')->where('member_id', '=', $member_id)->get();
     $cart_total = Cart::with('Books')->where('member_id', '=', $member_id)->sum('total');
     return View::make('cart')->with('cart_books', $cart_books)->with('cart_total', $cart_total);
 }
Ejemplo n.º 2
0
 public function getCart()
 {
     $member_id = Auth::user()->id;
     $cart_products = Cart::with('Product')->where('member_id', '=', $member_id)->get();
     $cart_total = Cart::with('Product')->where('member_id', '=', $member_id)->sum('quantity');
     // return View::make('cart')
     //       ->with('cart_books', $cart_books)
     //       ->with('cart_total',$cart_total);
     return View::make('store.cart')->with('cart_products', $cart_products)->with('cart_total', $cart_total);
     // return View::make('store.cart')
     //      ->with('products', Cart::contents());
 }
 public function postOrder()
 {
     $member_id = Auth::user()->id;
     $address = Input::get('address');
     $cart_books = Cart::with('Books')->where('member_id', '=', $member_id)->get();
     $cart_total = Cart::with('Books')->where('member_id', '=', $member_id)->sum('total');
     $order = Order::create(['member_id' => $member_id, 'address' => $address, 'total' => $cart_total]);
     foreach ($cart_books as $cart_book) {
         $order->orderItems()->attach($cart_book->book_id, ['amount' => $cart_book->amount, 'price' => $cart_book->books->price, 'total' => $cart_book->books->price * $cart_book->amount]);
         //for other fields
     }
     Cart::where('member_id', '=', $member_id)->delete();
     return Redirect::route('index')->with('message', 'Your order processed successfully..');
 }
Ejemplo n.º 4
0
 public function retriveStock()
 {
     $carts = Cart::with(['order'])->where('p_id', '=', $this->p_id)->where('c_type', '=', 2)->where(function ($q) {
         $q->where('c_status', '=', Cart::$STATUS_PENDDING_CONFIRM)->orWhere('c_status', '=', Cart::$STATUS_PENDDING_PAY);
     })->get();
     $orders = [];
     foreach ($carts as $key => $cart) {
         if (!empty($cart->order) && $cart->order->o_status == 1) {
             $orders[$cart->order->o_id] = $cart->order;
             $this->unloadProduct($cart->c_quantity);
             $cart->c_status = -1;
             $cart->save();
         }
     }
     if (!empty($orders)) {
         foreach ($orders as $key => $order) {
             $order->o_status = -1;
             $order->o_remark = '超时未支付, 自动回收订单';
             $order->save();
         }
     }
     $this->save();
     $remain = $this->p_max_quantity - $this->p_sold_quantity - $this->p_cart_quantity;
     return $remain;
 }
Ejemplo n.º 5
0
 public function listCarts()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $list = Cart::with(['product', 'booth'])->where('u_id', '=', $u_id)->whereIn('c_status', [0, 1])->get();
         $data = [];
         foreach ($list as $key => $cart) {
             $data[] = $cart->showInList();
         }
         $re = Tools::reTrue('获取购物车列表成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取购物车列表失败:' . $e->getMessage());
     }
     return Response::json($re);
 }