diff --git a/library/LibModels/Wap/Home/CartData.php b/library/LibModels/Wap/Home/CartData.php index 1c9771a..65b53ab 100644 --- a/library/LibModels/Wap/Home/CartData.php +++ b/library/LibModels/Wap/Home/CartData.php @@ -303,14 +303,15 @@ class CartData * @param int $paymentId 支付方式ID * @param int $paymentType 支付类型ID * @param string $remark 留言 + * @param string $couponCode 优惠券码 * @param mixed $yohoCoin 使用的YOHO币数量或为空 * @return array 接口返回的数据 */ - public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin) { $param = Yohobuy::param(); $param['method'] = 'app.Shopping.submit'; - $param['addressId'] = $addressId; + $param['address_id'] = $addressId; $param['cart_type'] = $cartType; $param['delivery_time'] = $deliveryTime; $param['delivery_way'] = $deliveryWay; @@ -324,6 +325,9 @@ class CartData $param['payment_id'] = $paymentId; $param['payment_type'] = $paymentType; $param['remark'] = $remark; + if (!empty($couponCode)) { + $param['coupon_code'] = $couponCode; + } if (!empty($yohoCoin)) { $param['use_yoho_coin'] = $yohoCoin; } diff --git a/static/js/shopping-cart/order-ensure.js b/static/js/shopping-cart/order-ensure.js index 9a665d0..1e753cf 100644 --- a/static/js/shopping-cart/order-ensure.js +++ b/static/js/shopping-cart/order-ensure.js @@ -15,6 +15,7 @@ var dispatchModeHammer, dispatchTimeHammer, $invoice = $('.invoice'), $price = $('.price-cal'), + payType, priceTmpl = Handlebars.compile($('#tmpl-price').html()); lazyLoad(); @@ -99,23 +100,33 @@ function submitOrder() { addressId: orderInfo('addressId'), cartType: orderInfo('cartType'), deliveryId: orderInfo('deliveryId') || 1, - deliveryTimeId: orderInfo('deliveryTimeId') || 1, - invoiceText: orderInfo('invoiceText'), - invoiceType: orderInfo('invoiceType'), - msg: orderInfo('msg'), + deliveryTimeId: orderInfo('deliveryTimeId') || 2, + invoiceText: $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'), + invoiceType: $invoice.find('.invoice-type').val() || orderInfo('invoiceType'), + msg: $('#msg').find('input').val() || orderInfo('msg'), paymentTypeId: orderInfo('paymentTypeId'), paymentType: orderInfo('paymentType'), //支付方式 couponCode: orderInfo('couponCode'), yohoCoin: orderInfo('yohoCoin') } }).then(function(res) { + var url; + if (!res) { tip.show('网络出错'); + return; } - if (res.code !== 200) { - tip.show(res.message || '网络出错'); + if (res.code === 200) { + if (payType === 2) { + + // 货到付款的进入订单页面 + url = '/home/orderDetail?order_code=' + res.data.order_code; + } else { + url = '/home/pay?order_code=' + res.data.order_code; + } + window.location.href = url; } else { - console.log(1); + tip.show(res.messege || '网络出错'); } }).fail(function() { tip.show('网络出错'); @@ -124,7 +135,7 @@ function submitOrder() { // 界面点击,状态存 cookie if (!orderInfo('addressId')) { - orderInfo('addressId', $('.address-wrap').data('address-id')); + orderInfo('addressId', $('.address-wrap').data('id')); } $('.dispatch-mode').on('touchend', 'li', function() { @@ -166,7 +177,10 @@ $('#msg').find('input').on('blur', function() { }); $('.pay-mode').on('click', 'li', function() { - orderInfo('paymentTypeId', $(this).data('pay-id')); - orderInfo('paymentType', $(this).data('pay-type')); + var $this = $(this); + + orderInfo('paymentTypeId', $this.data('pay-id')); + orderInfo('paymentType', $this.data('pay-type')); + payType = $this.data('pay-type'); submitOrder(); }); diff --git a/template/m.yohobuy.com/actions/index/shoppingCart/order-ensure.phtml b/template/m.yohobuy.com/actions/index/shoppingCart/order-ensure.phtml index 924bff2..c56b880 100644 --- a/template/m.yohobuy.com/actions/index/shoppingCart/order-ensure.phtml +++ b/template/m.yohobuy.com/actions/index/shoppingCart/order-ensure.phtml @@ -1,7 +1,7 @@ {{> layout/header}} <div class="order-ensure-page yoho-page"> {{# orderEnsure}} - <a class="address-wrap block" href="/shoppingCart/selectAddress" data-address-id="{{addressId}}"> + <a class="address-wrap block" data-id="{{addressId}}" href="/shoppingCart/selectAddress"> <p class="infos"> 收货地址 <span class="per-info">{{name}} {{phoneNum}}</span> @@ -67,16 +67,14 @@ </li> {{/if}} - {{# yohoCoin}} - <li class="coin" data-yoho-coin="{{.}}"> - <span class="title">YOHO币</span> - <span class="desc">可抵用¥{{.}}</span> - <span class="coin-check"> - <em>- ¥ {{.}}</em> - <i class="iconfont checkbox icon-cb-checked"></i> - </span> - </li> - {{/ yohoCoin}} + <li class="coin" data-yoho-coin="{{yohoCoin}}"> + <span class="title">YOHO币</span> + <span class="desc">可抵用¥{{yohoCoin}}</span> + <span class="coin-check"> + <em>- ¥ {{yohoCoin}}</em> + <i class="iconfont checkbox icon-cb-checked"></i> + </span> + </li> {{#if invoice}} <li class="invoice {{#if needInvoice}}focus{{/if}}"> diff --git a/yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php b/yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php index 045c25f..d29d2ab 100644 --- a/yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php +++ b/yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php @@ -314,8 +314,9 @@ class ShoppingCartController extends AbstractAction $paymentId = $this->post('paymentTypeId', 15); $paymentType = $this->post('paymentType', 1); // 默认在线支付 $remark = $this->post('msg', null); + $couponCode = $this->post('couponCode', null); $yohoCoin = $this->post('yohoCoin', 1); - $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin); + $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin); } if (empty($result)) { diff --git a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php index 96032b3..4037175 100644 --- a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php +++ b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php @@ -567,16 +567,28 @@ class CartModel * @param int $paymentId 支付方式ID * @param int $paymentType 支付类型ID * @param string $remark 留言 + * @param string $couponCode 优惠券码 * @param mixed $yohoCoin 使用的YOHO币数量或为空 * @return array 接口返回的数据 */ - public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin) { - $result = array(); - - $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin); - if ($orderSubRes && isset($orderSubRes['code'])) { - $result = $orderSubRes; + $result = array('code' => 400, 'message' => '出错啦'); + + if (empty($addressId)) { + $result['code'] = 401; + $result['message'] = '配送地址不能为空'; + } elseif (empty($deliveryTime)) { + $result['code'] = 402; + $result['message'] = '请选择配送时间'; + } elseif (empty($deliveryWay)) { + $result['code'] = 403; + $result['message'] = '请选择配送方式'; + } else { + $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin); + if ($orderSubRes && isset($orderSubRes['code'])) { + $result = $orderSubRes; + } } return $result;