public function delete_book(Request $request)
 {
     $book = Book::find($id);
     $book->delete();
     Session::flash('flash_message', 'Xóa thành công!');
     return redirect('/admin_books');
 }
示例#2
0
 public function undo_delete(Request $request)
 {
     if (Auth::user()->role !== 1) {
         return redirect('/');
     }
     $book = Book::find((int) $request->input('book_id'));
     $book->deleted = 0;
     $book->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);
     }
 }
示例#4
0
 public function show()
 {
     if (Auth::guest()) {
         return redirect('auth/login');
     } else {
         $containers = array();
         $container = array();
         $cart = Cart::content();
         foreach ($cart as $item) {
             $containers["{$item->id}"] = ['quantity' => $item->qty, 'book' => Book::find($item->id), 'subtotal' => $item->subtotal];
         }
         return Controller::myView('cart.show')->with('containers', $containers);
     }
 }
 public function order_one(Request $request)
 {
     $order = new Order();
     $book = Book::find((int) $request->input('book_id'));
     if ($this->checkQuantity(1, $book)) {
         $orderline = new Orderline();
         $order->user_id = Auth::user()->id;
         $order->date = Carbon::now();
         $order->money = $book->price;
         $order->save();
         $orderline->order_id = $order->id;
         $orderline->book_id = $book->id;
         $orderline->quantity = 1;
         $orderline->price = $book->price;
         $orderline->save();
         $book->update(['quantity' => $book->quantity - 1]);
         return redirect("order/{$order->id}");
     } else {
         echo "k du";
     }
 }
示例#6
0
 public function actionUpdate($request)
 {
     $this->book = Book::find((int) $request->input('book_id'));
     return $this->changeUpdate($this->book, $request);
 }