public function action_order() { define("SECONDS_PER_DAY", 3600 * 24); $now = time(); $cart = Session::get('cart'); $user = Model_User::find($this->sessUser->id); $cart_info = []; $order = Model_Order::forge(); $order->user_id = $user->id; $order->created_at = $now; $order->save(); if (!is_null($cart)) { foreach ($cart as $product_id => $quantity) { $product = Model_Product::find($product_id); $order_product = Model_OrderProduct::forge(); $order_product->order_id = $order->id; $order_product->product_id = $product->id; $order_product->quantity = $quantity; $order_product->price = $product->price; $order_product->save(); } } Session::delete('cart'); return Response::redirect('/cart'); }
/** * 创建订单对象 * @return static */ public static function get_order() { $data = \Input::post(); if (!static::valid_data()) { return false; } $order = \Model_Order::forge($data); $order->order_no = static::get_order_on(); return $order; }
/** * 出价 * @param int $id 拍品ID */ public function action_bid($id = 0) { if (\Input::method() == 'POST') { $msg = ['status' => 'err', 'msg' => '', 'errcode' => 10]; $order_no = \Model_Order::get_order_on(); $data = ['order_no' => $order_no, 'order_type' => 'AUCTION', 'buyer_id' => \Auth::get_user()->id, 'from_id' => \Session::get('seller')->id, 'total_fee' => \Input::post('bid'), 'original_fee' => \Input::post('bid')]; $order = \Model_Order::forge($data); $order->details = [\Model_OrderDetail::forge(['goods_id' => $id, 'num' => 1, 'price' => \Input::post('bid')])]; if ($order->save()) { $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0]; } if (\Input::is_ajax()) { die(json_encode($msg)); } \Session::set_flash('msg', $msg); } }
/** * 添加优惠信息 */ protected function load_preferential($data) { if (!$this->order) { $this->order = \Model_Order::forge(); } $this->order->preferentials = []; $fee = 0; foreach ($data as $item) { array_push($this->order->preferentials, \Model_OrderPreferential::forge($item)); $fee += $item->fee; } $this->order->preferential_fee = $fee; }