Authored by 毕凯

增加订单价格计算 , 订单提交 @张振

... ... @@ -7,11 +7,15 @@
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Hammer = require('yoho.hammer'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
orderInfo = require('./order-info').orderInfo;
var dispatchModeHammer,
dispatchTimeHammer,
$invoice = $('.invoice');
$invoice = $('.invoice'),
$price = $('.price-cal'),
priceTmpl = Handlebars.compile($('#tmpl-price').html());
lazyLoad();
... ... @@ -55,9 +59,66 @@ $('.invoice').on('touchend', '.checkbox', function() {
}
});
function orderCompute() {
$.ajax({
method: 'POST',
url: '/shoppingCart/orderCompute',
data: {
cartType: orderInfo('cartType'),
deliveryId: orderInfo('deliveryId'),
paymentTypeId: orderInfo('paymentTypeId'),
couponCode: orderInfo('couponCode'),
yohoCoin: orderInfo('yohoCoin')
}
}).then(function(res) {
var priceHtml;
if (!res) {
tip.show('网络出错');
} else {
priceHtml = priceTmpl({
sumPrice: res.order_amount,
salePrice: res.discount_amount,
freight: res.promotion_formula_list[1].promotion_amount,
yohoCoin: res.use_yoho_coin,
price: res.last_order_amount
});
$price.html(priceHtml);
}
}).fail(function() {
tip.show('网络出错');
});
}
function submitOrder() {
$.ajax({
method: 'POST',
url: '/shoppingCart/orderSub',
data: {
addressId: orderInfo('addressId'),
cartType: orderInfo('cartType'),
deliveryId: orderInfo('deliveryId'),
deliveryTimeId: orderInfo('deliveryTimeId'),
invoiceText: orderInfo('invoiceText'),
invoiceType: orderInfo('invoiceType'),
msg: orderInfo('msg'),
paymentTypeId: orderInfo('paymentTypeId'),
paymentType: orderInfo('paymentType'), //支付方式
couponCode: orderInfo('couponCode'),
yohoCoin: orderInfo('yohoCoin')
}
}).then(function(res) {
console.log(res);
}).fail(function() {
tip.show('网络出错');
});
}
// 界面点击,状态存 cookie
$('.dispatch-mode').on('touchend', 'li', function() {
orderInfo('deliveryId', $(this).data('id'));
orderCompute();
});
$('.dispatch-time').on('touchend', 'li', function() {
... ... @@ -69,9 +130,12 @@ $('.coin').on('touchend', function() {
if ($this.find('.checkbox').hasClass('icon-cb-checked')) {
orderInfo('yohoCoin', $this.data('yoho-coin'));
$this.find('.coin-check em').show();
} else {
orderInfo('yohoCoin', 0);
$this.find('.coin-check em').hide();
}
orderCompute();
});
$invoice.on('touchend', function() {
... ... @@ -92,4 +156,6 @@ $('#msg').find('input').on('blur', function() {
$('.pay-mode').on('click', 'li', function() {
orderInfo('paymentTypeId', $(this).data('pay-id'));
orderInfo('paymentType', $(this).data('pay-type'));
submitOrder();
});
... ...
... ... @@ -9,7 +9,19 @@ var info = window.cookie('order-info');
try {
info = JSON.parse(info);
} catch (e) {
info = {};
info = {
deliveryId: null,
deliveryTimeId: null,
paymentTypeId: null,
yohoCoin: null,
addressId: null,
couponCode: null,
couponValue: null,
invoice: null,
invoiceText: null,
invoiceType: null,
msg: null
};
}
exports.orderInfo = function(key, value) {
... ...
... ... @@ -102,23 +102,23 @@
</form>
</section>
<section class="block">
<section class="price-cal block">
<ul class="total">
<li>
<span>总价</span>
&nbsp;&nbsp;¥ {{sumPrice}}
&nbsp;&nbsp;¥{{sumPrice}}
</li>
<li>
<span>活动价</span>
- ¥ {{salePrice}}
- ¥{{salePrice}}
</li>
<li>
<span>运费</span>
+ ¥ {{freight}}
+ ¥{{freight}}
</li>
<li>
<span>YOHO币</span>
- ¥ {{yohoCoin}}
- ¥{{yohoCoin}}
</li>
<li class="cost">
应付金额: <em>¥{{price}}</em>
... ... @@ -128,7 +128,7 @@
<ul class="pay-mode">
{{# paymentWay}}
<li class="{{#if default}}default{{/if}}" data-pay-id={{id}}>
<li class="{{#if default}}default{{/if}}" data-pay-type="{{paymentType}}" data-pay-id="{{id}}">
<span class="iconfont">
{{#if default}}
&#xe62f;
... ... @@ -142,4 +142,27 @@
</ul>
{{/ orderEnsure}}
</div>
<script id="tmpl-price" type="text/tmpl">
<ul class="total">
<li>
<span>总价</span>
&nbsp;&nbsp;¥\{{sumPrice}}
</li>
<li>
<span>活动价</span>
- ¥\{{salePrice}}
</li>
<li>
<span>运费</span>
+ \{{freight}}
</li>
<li>
<span>YOHO币</span>
- ¥\{{yohoCoin}}
</li>
<li class="cost">
应付金额: <em>¥\{{price}}</em>
</li>
</ul>
</script>
{{> layout/footer}}
... ...
... ... @@ -156,7 +156,6 @@ class ShoppingCartController extends AbstractAction
'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData)
);
$this->_view->display('order-ensure', $data);
}
... ... @@ -169,10 +168,10 @@ class ShoppingCartController extends AbstractAction
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryWay', 1);
$paymentType = $this->post('paymentType', 1);
$couponCode = $this->post('paymentType', null);
$yohoCoin = $this->post('paymentType', null);
$deliveryWay = $this->post('deliveryId', 1);
$paymentType = $this->post('paymentTypeId', 1);
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', null);
$uid = $this->getUid(true);
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
}
... ... @@ -268,13 +267,13 @@ class ShoppingCartController extends AbstractAction
$uid = $this->getUid(true);
$addressId = $this->post('addressId', null);
$cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
$deliveryTime = $this->post('deliveryTime', 1); // 默认只工作日配送
$deliveryWay = $this->post('deliveryWay', 1); // 默认普通快递
$invoiceTitle = $this->post('invoiceTitle', null);
$invoiceId = $this->post('invoiceId', null);
$paymentId = $this->post('paymentId', 15);
$deliveryTime = $this->post('deliveryTimeId', 1); // 默认只工作日配送
$deliveryWay = $this->post('deliveryId', 1); // 默认普通快递
$invoiceTitle = $this->post('invoiceText', null);
$invoiceId = $this->post('invoiceType', null);
$paymentId = $this->post('paymentTypeId', 15);
$paymentType = $this->post('paymentType', 1); // 默认在线支付
$remark = $this->post('remark', null); // 默认在线支付
$remark = $this->post('msg', null);
$yohoCoin = $this->post('yohoCoin', 1);
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin);
}
... ... @@ -283,7 +282,7 @@ class ShoppingCartController extends AbstractAction
echo ' ';
} else {
// 提交成功清除Cookie
$this->setCookie('orderInfo', null);
$this->setCookie('order-info', null);
$this->echoJson($result);
}
... ...