public function finishAction() { $totalprice = $this->getRequest()->getParam('totalprice'); session_start(); $userid = $_SESSION['userid']; $orderdate = time(); $this->orders_data = array('userid' => $userid, 'totalprice' => $totalprice, 'orderdate' => $orderdate); $order = new Orders(); $this->orderid = $order->insert($this->orders_data); //取得mycart的资料 $mycart = new Mycart(); $where = "userid=" . $userid; $res = $mycart->fetchAll($where)->toArray(); $i = 0; foreach ($res as $val) { $this->arr[$i++] = array('orderid' => $this->orderid, 'bookid' => $val['bookid'], 'nums' => $val['nums']); } $orderitem = new Orderitem(); for ($i = 0; $i < count($this->arr); $i++) { $itemid = $orderitem->insert($this->arr[$i]); } if ($itemid > 0) { $mycart->delete($where); $this->view->info = "购买成功"; $this->view->goto = "/finish/done?orderid=" . $this->orderid . "&totalprice=" . $totalprice; $this->_forward("ok", "globals"); } else { $this->view->info = "购买失败"; $this->view->goto = "/cart/cart"; $this->_forward("error", "globals"); } }
function search($email) { $user = Order::where('email_id', $email)->first(); if (!empty($user)) { $orderitem = new Orderitem(); $data = $orderitem->getOrderbyemail($email); } else { $data['message'] = "no data found"; } return Response::json($data, 400); }
public function getItems($id) { $order = Order::find($id); if ($order) { $Orderitem = Orderitem::where('order_id', $id)->get(); return View::make('items')->with('Orderitem', $Orderitem); } }
public function postDeletefromcart() { $id = Input::get('id'); $orderitem = Orderitem::find($id); if ($orderitem) { $orderitem->delete(); return Redirect::to('/cart')->with('message', 'Item successfully deleted from the cart.'); } return Redirect::back()->with('message', 'Could not delete the item from your cart. Please Try again. '); }
public function success() { if (Input::get("token") && Input::get("PayerID")) { $token = Input::get('token'); $update = Order::where('token', '=', $token)->update(array("status" => 1)); $order = Order::where('token', '=', $token)->first(); $items = Orderitem::where('order_id', '=', $order->id)->get(); foreach ($items as $item) { $qt = $item->item_qt; Product::where('id', '=', $item->item_id)->decrement('stock', $qt); } return Redirect::to('product/all')->with('message', 'Votre commande a été passé !'); } }
public function show() { $addresses = Useradd::where('user_id', '=', Auth::user()->id)->get(); $orders = Order::where('orders.user_id', '=', Auth::user()->id)->leftJoin('user_adds as shipadd', 'orders.add_id', '=', 'shipadd.id')->leftJoin('user_adds as rcpadd', 'orders.rcp_id', '=', 'rcpadd.id')->select('orders.*', 'shipadd.title AS ship_title', 'shipadd.address AS ship_add', 'shipadd.address2 AS ship_add2', 'shipadd.postal AS ship_post', 'shipadd.city AS ship_city', 'shipadd.first_name AS ship_first', 'shipadd.last_name AS ship_last', 'rcpadd.title AS rcp_title', 'rcpadd.address AS rcp_add', 'rcpadd.address2 AS rcp_add2', 'rcpadd.postal AS rcp_post', 'rcpadd.city AS rcp_city', 'rcpadd.first_name AS rcp_first', 'rcpadd.last_name AS rcp_last')->orderBy('orders.date', 'DESC')->get(); // on va récupérer les produits de chaque commande // commence par récupérer l'id de chaque commande $orders_id = Order::where('orders.user_id', '=', Auth::user()->id)->select('orders.id')->orderBy('orders.date', 'DESC')->get(); $items = array(); // rangés par commandes foreach ($orders_id->toArray() as $row => $ord) { $i = Orderitem::where('order_id', '=', $ord['id'])->leftJoin('products', 'order_items.item_id', '=', 'products.id')->select('order_items.*', 'products.name', 'products.picture')->get(); $items[$ord['id']] = $i->toArray(); } return View::make('user/show', array('addresses' => $addresses, 'orders' => $orders, 'items' => $items)); }
public function dashboard() { if (!Auth::user()->is_admin) { return Redirect::to('/'); } //produits de la boutique $products = Product::all(); // récupérer les dates ou il y a eu des commandes donc achats $cmds = DB::select(DB::raw('SELECT DATE(orders.date) AS date FROM orders GROUP BY DATE(orders.date) ORDER BY orders.date DESC')); //récupérer les achats par date $cmdsByDate = array(); foreach ($cmds as $key => $cmd) { $cmdsByDate[$cmd->date] = Orderitem::whereRaw('DATE(orders.date) = \'' . $cmd->date . '\'')->leftJoin('orders', 'order_items.order_id', '=', 'orders.id')->leftJoin('users', 'orders.user_id', '=', 'users.id')->leftJoin('products', 'order_items.item_id', '=', 'products.id')->select('order_items.*', 'orders.date AS date', 'users.email AS user_email', 'users.first_name AS user_first', 'users.last_name AS user_last', 'products.name AS item_name')->orderBy('orders.date', 'DESC')->get(); } //list des commandes par mois return View::make('admin/show', array('products' => $products, 'cmdsbydate' => $cmdsByDate)); }
public function postAddress() { $v = Validator::make(Input::all(), ['address' => 'required|min:10']); if ($v->passes()) { $uid = Auth::user()->id; $orders = Orderitem::where('user_id', $uid)->where('status', 0)->get(); $neworder = new Order(); $neworder->address = Input::get('address'); $neworder->user_id = $uid; $neworder->save(); foreach ($orders as $order) { $order->status = 1; $order->order_id = $neworder->id; $order->save(); } return Redirect::to('/checkout/confirm'); } return Redirect::to('/checkout/address')->withInput()->withErrors($v)->with('message', 'There has been a problem while submitting your address'); }
public function __construct() { if (Auth::check()) { $this->beforeFilter(function () { $userid = Auth::user()->id; $orders = Orderitem::where('user_id', $userid)->where('status', 0); $total = 0; $items = $orders->get(); foreach ($items as $item) { $temp = $item->quantity * $item->price; $total = $total + $temp; } View::share('count', $orders->count()); View::share('orders', $orders->get()); View::share('total', $total); }); } $this->beforeFilter(function () { View::share('catnav', Category::all()); }); }
public function add($listings) { foreach ($listings as $idx => $listing) { Orderitem::create(['listing_id' => $listing->id, 'order_id' => $this->id]); } }
/** * Remove the specified orderitem from storage. * * @param int $id * @return Response */ public function destroy($id) { Orderitem::destroy($id); return Redirect::route('orderitems.index'); }