/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Orders(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Orders'])) { $model->attributes = $_POST['Orders']; $model->order_sn = F::get_order_sn(); $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0'; if ($model->save()) { $cart = Yii::app()->cart; $mycart = $cart->contents(); foreach ($mycart as $mc) { $orderGoods = new OrderGoods(); $orderGoods->order_id = $model->order_id; $orderGoods->product_id = $mc['id']; $orderGoods->product_name = $mc['product_name']; $orderGoods->product_image = serialize($mc['product_image']); $orderGoods->product_sn = $mc['product_sn']; $orderGoods->qty = $mc['qty']; $orderGoods->save(); } $cart->destroy(); $this->redirect(array('success')); } } // // $this->render('create', array( // 'model' => $model, // )); }
/** * 往购物车里面增加一个商品 * * @param int $goodsId 商品ID * @param int $buyCount 购买数量 * @param string $specStr 商品组合列表 比如 "白色,ML码,男款",用逗号分隔 * @param string $goodsSn 商品的 sn 号 */ public function addGoods($goodsId, $buyCount, $specStr = null, $goodsSn = null) { // 先删除旧的记录 $this->removeGoods($goodsId, $specStr); // 添加商品 $orderGoods = new OrderGoods(); $orderGoods->setValue('goods_id', $goodsId); $orderGoods->setValue('goods_number', $buyCount); $orderGoods->setValue('goods_attr', $specStr); if (!empty($goodsSn)) { $orderGoods->setValue('goods_sn', $goodsSn); } $this->orderGoodsArray[] = $orderGoods; // 对商品做排序 $orderIdMapArray = array(); foreach ($this->orderGoodsArray as $orderGoodsItem) { if (!isset($orderIdMapArray[$orderGoodsItem->getValue('goods_id')])) { $orderIdMapArray[$orderGoodsItem->getValue('goods_id')] = array(); } $orderIdMapArray[$orderGoodsItem->getValue('goods_id')][] = $orderGoodsItem; } $this->orderGoodsArray = array(); foreach ($orderIdMapArray as $array) { $this->orderGoodsArray = array_merge($this->orderGoodsArray, $array); } unset($orderIdMapArray); }
$_goods['g_id'] = $_SESSION['orderGoods']['g_id']; $_goods['g_code'] = $_SESSION['orderGoods']['g_code']; $_goods['o_name'] = $_SESSION['orderGoods']['c_name']; $_goods['o_price'] = $_SESSION['orderGoods']['c_price']; $_goods['o_number'] = $_SESSION['orderGoods']['c_number']; //往订单商品表添加商品 if ($order_goods->insertOrderGoods($_goods)) { $_SESSION['totalPrice'] = $totals; $_SESSION['orderNumber'] = $orderNumber; $_SESSION['orderId'] = $order_id; my_redirect("order.php?act=pay&orderId={$order_id}", '生成订单成功!', '正在为您跳转到支付页面!'); } } else { my_redirect('order.php', '生成订单失败!', '正在为您跳转到订单页面!'); } } elseif ($act == 'pay') { //$orderId = $_GET['orderId']; //加载支付模板 include_once YIMAI_TEMP . 'pay.html'; } elseif ($act == 'success') { //将订单里面的商品从购物车里面删除 $orderGoods = new OrderGoods(); $goods_id = $orderGoods->getOrderGoodsIdByOrderId($_SESSION['orderId']); foreach ($goods_id as $id) { $cart = new Cart(); $cart->deleteCartGoodsByUserIdAndGoodsId($id['g_id']); } $orderGoods->updateOrderGoodsByOrderId($_SESSION['orderId']); //加载成功模板 include_once YIMAI_TEMP . 'shopping-result.html'; }
public function doPay() { // 获得payment_id 获得相关参数 $payment_id = Filter::int(Req::args('payment_id')); $order_id = Filter::int(Req::args('order_id')); $recharge = Req::args('recharge'); $extendDatas = Req::args(); if ($payment_id) { $payment = new Payment($payment_id); $paymentPlugin = $payment->getPaymentPlugin(); //充值处理 if ($recharge != null) { $recharge = Filter::float($recharge); $paymentInfo = $payment->getPayment(); $data = array('account' => $recharge, 'paymentName' => $paymentInfo['name']); $packData = $payment->getPaymentInfo('recharge', $data); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { if ($order_id != null) { $order = Order::getOrder($order_id); $model = new Model("order_goods"); if ($order) { //获取订单可能延时时长,0不限制 $config = Config::getInstance(); $config_other = $config->get('other'); // todo 修改方法 order type 去掉 详情表中记录 order type switch ($order['type']) { case '1': $order_delay = isset($config_other['other_order_delay_group']) ? intval($config_other['other_order_delay_group']) : 120; break; case '2': $order_delay = isset($config_other['other_order_delay_flash']) ? intval($config_other['other_order_delay_flash']) : 120; break; case '3': $order_delay = isset($config_other['other_order_delay_bund']) ? intval($config_other['other_order_delay_bund']) : 0; break; default: $order_delay = isset($config_other['other_order_delay']) ? intval($config_other['other_order_delay']) : 0; break; } $time = strtotime("-" . $order_delay . " Minute"); $create_time = strtotime($order['create_time']); if ($create_time >= $time || $order_delay == 0) { //取得所有订单商品 //$order_goods = $model->table('order_goods')->fields("product_id,goods_nums, prom_type")->where('order_id='.$order_id)->findAll(); $order_goods_inst = new OrderGoods(); $order_goods = $order_goods_inst->getOrderGoods($order_id); $product_ids = array(); $order_products = array(); // todo 这里判断 prom_type 类型 foreach ($order_goods as $value) { // 套餐不在这里检查商品库存 考虑在别的地方检查 // 如果订单详细表中行是由于捆绑促销 if ($value['prom_type'] == 'bundling') { continue; } else { $product_ids[] = $value['product_id']; $order_products[$value['product_id']] = $value['goods_nums']; } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); /* 这里不需要验证库存量 提交订单时已经验证 if (!empty($product_ids)) { $product_ids = implode(',', $product_ids); $products = $model->table('products')->fields("id,store_nums")->where("id in ($product_ids)")->findAll(); $products_list = array(); foreach ($products as $value) { $products_list[$value['id']] = $value['store_nums']; } $flag = true; foreach ($order_goods as $value) { if ($order_products[$value['product_id']] > $products_list[$value['product_id']]) { $flag = false; break; } } //检测库存是否还能满足订单 if ($flag) { //团购订单 if ($order['type'] == 1 || $order['type'] == 2) { if ($order['type'] == 1) { $prom_name = '团购'; $prom_table = "groupbuy"; } else { $prom_name = '抢购'; $prom_table = "flash_sale"; } $prom = $model->table($prom_table)->where("id=" . $order['prom_id'])->find(); if ($prom) { if (time() > strtotime($prom['end_time']) || $prom['max_num'] <= $prom["goods_num"]) { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,' . $prom_name . "活动已结束。")); exit; } } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,库存已不足。')); exit; } } */ } else { $model->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '订单超出了规定时间内付款,已作废.')); exit; } } } } if (!empty($sendData)) { $this->assign("paymentPlugin", $paymentPlugin); $this->assign("sendData", $sendData); $this->redirect('pay_form', false); } else { $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '需要支付的订单已经不存在。')); } } else { echo "fail"; } }
public static function getOrderWithDetailByNo($orderNo) { $order = Order::getOrderByNo($orderNo); if ($order) { $order_id = $order['id']; $order_goods_inst = new OrderGoods(); $order['OrderGoods'] = $order_goods_inst->getOrderGoods($order_id); $ret = array('status' => 1, 'data' => $order, 'msg' => '获取订单及详情成功!'); return $ret; } else { $ret = array('status' => 0, 'msg' => '获取订单及详情失败!'); return $ret; } }