public function store()
 {
     if (Auth::guest()) {
         return redirect('auth/login');
     } else {
         $containers = array();
         $container = array();
         $cart = Cart::content();
         $order = new Order();
         $order->user_id = Auth::user()->id;
         $order->date = Carbon::now();
         $order->money = Cart::total();
         $order->save();
         foreach ($cart as $item) {
             $orderline = new Orderline();
             $orderline->order_id = $order->id;
             $orderline->quantity = $item->qty;
             $orderline->book_id = $item->id;
             $orderline->price = $item->subtotal;
             $orderline->save();
         }
         Cart::destroy();
         return redirect("order/{$order->id}");
     }
 }
示例#2
0
 public function noDone(Request $request)
 {
     if (Auth::user()->role !== 1) {
         return redirect('/');
     }
     $order = Order::find((int) $request->input('order_id'));
     $order->status = 0;
     $order->save();
 }
示例#3
0
 public function store()
 {
     $error = array();
     $error['qtys'] = array();
     $error['deleted'] = array();
     $count = 0;
     if (Auth::guest()) {
         return redirect('auth/login');
     } else {
         if (Cart::total() > 1000) {
             $error['money'] = "<li>Tổng số tiền phải < 1 triệu</li>";
             $count++;
         }
         $containers = array();
         $container = array();
         $cart = Cart::content();
         foreach ($cart as $item) {
             $book = Book::find($item->id);
             if ($book->quantity < $item->qty) {
                 array_push($error['qtys'], "<li>Số lượng hiện tại nhiều hơn số sách '{$book->title}' đang có</li>");
                 $count++;
             }
             if ($book->deleted == 1) {
                 array_push($error['deleted'], "<li>Sách '{$book->title}' đã bị xóa</li>");
                 $count++;
             }
         }
         if ($count > 0) {
             $error['error'] = "true";
             return json_encode($error);
         }
         $order = new Order();
         $order->user_id = Auth::user()->id;
         $order->date = Carbon::now();
         $order->money = Cart::total();
         $order->save();
         foreach ($cart as $item) {
             $orderline = new Orderline();
             $orderline->order_id = $order->id;
             $orderline->quantity = $item->qty;
             $orderline->book_id = $item->id;
             $orderline->price = $item->subtotal;
             $orderline->save();
         }
         $error["error"] = "false";
         $error["order_id"] = $order->id;
         Cart::destroy();
         return json_encode($error);
     }
 }