Authored by 郝肖肖

0元、货到付款订单 数据处理

... ... @@ -37,9 +37,17 @@ const online = (req, res, next) => {
return next();
}
result.order.payment_name = (parseInt(result.order.payment_type, 10) === 1 ? '在线支付' : '货到付款');
order.payment_type = parseInt(order.payment_type, 10);
if (amount > 0) {
if (amount <= 0 || order.payment_type === 2) {
PayData.deliveryData(order).then(orderInfo => {
res.render('pay-success', {
simpleHeader: header,
order: orderInfo,
isDelivery: orderInfo.payment_type === 2
});
});
} else {
res.render('pay', Object.assign({
module: 'shopping',
page: 'pay',
... ... @@ -47,11 +55,6 @@ const online = (req, res, next) => {
simpleHeader: header,
username: decodeURIComponent(req.user.name) || ''
}, result));
} else {
res.render('pay-success', {
simpleHeader: header,
order: order
});
}
}).catch(next);
... ...
... ... @@ -194,13 +194,35 @@ const updateOrderPayBank = (code, payment, bankCode) => {
*/
const sendPayConfirm = (code, payment, uid) => {
return co(function *() {
let data = yield payApi.sendPayConfirm(code, payment, uid);
return data;
return yield payApi.sendPayConfirm(code, payment, uid);
})();
};
/**
* [公共支付成功数据处理]
* @param {[type]} orderInfo [订单信息]
* @param {[type]} fraudData [资源位数据]
* @return {[type]} [{}]
*/
const _execOrderData = (orderInfo, fraudData) => {
let fraud = _.result(_.find(fraudData, {template_name: 'text'}), 'data') || {};
return {
paymentTypes: (orderInfo.payment_type === 1 ? '在线支付' : '货到付款'),
multiPackage: orderInfo.is_multi_package === 'Y',
ordersUrl: helpers.urlFormat('/home/orders'),
vipUrl: helpers.urlFormat('/help/detail', {id: 9}),
returnGoodsUrl: helpers.urlFormat('/help/detail', {id: 49}),
yohoCoinUrl: helpers.urlFormat('/help/detail', {id: 105, contId: 233}),
detailUrl: helpers.urlFormat('/home/orders/detail', {
orderCode: orderInfo.order_code
}),
packageTitle: orderInfo.package_title || '商品需要品牌商调货',
fraudTip: fraud.text || ''
};
};
/**
* 支付成功,前端回调时,处理订单信息
* @param payResult
* @param uid
... ... @@ -217,16 +239,12 @@ const procOrderData = (payResult, uid) => {
return Promise.all([orderDetail(uid, orderCode), payApi.getResourceData(FRAUD_CONTENT_CODE)]).then(procData => {
let orderInfo = procData[0].code === 200 && procData[0].data;
let fraudData = _.result(_.find(procData[1].data, {template_name: 'text'}), 'data') || {};
let resultOrder;
if (!orderInfo) {
result.message = '订单不存在!';
return result;
}
let amount = orderInfo.payment_amount;
if (orderInfo.is_cancel === 'Y') {
logger.warn('front pay success but order is cancel.', {payResult: payResult, order: orderInfo});
return {code: 417, message: '支付成功,但订单已取消,需联系客服!'};
... ... @@ -236,7 +254,7 @@ const procOrderData = (payResult, uid) => {
logger.warn('front pay success but may be notify fail');
}
if (_.round(parseFloat(amount), 2) !== _.round(parseFloat(payResult.totalFee), 2)) {
if (_.round(parseFloat(orderInfo.payment_amount), 2) !== _.round(parseFloat(payResult.totalFee), 2)) {
logger.warn('front pay success but the amount is not same.', {payResult: payResult, order: orderInfo});
return {
code: 415,
... ... @@ -244,24 +262,11 @@ const procOrderData = (payResult, uid) => {
};
}
resultOrder = {
paymentTypes: (orderInfo.payment_type === 1 ? '在线支付' : '货到付款'),
multiPackage: orderInfo.is_multi_package === 'Y',
ordersUrl: helpers.urlFormat('/home/orders'),
vipUrl: helpers.urlFormat('/help/detail', {id: 9}),
returnGoodsUrl: helpers.urlFormat('/help/detail', {id: 49}),
yohoCoinUrl: helpers.urlFormat('/help/detail', {id: 105, contId: 233}),
detailUrl: helpers.urlFormat('/home/orders/detail', {
orderCode: orderInfo.order_code
}),
packageTitle: orderInfo.package_title || '商品需要品牌商调货',
fraudTip: fraudData.text || ''
};
return {
code: 200,
message: '支付成功,请等待发货',
data: {
order: Object.assign(orderInfo, resultOrder)
order: Object.assign(orderInfo, _execOrderData(orderInfo, procData[1] && procData[1].data || {}))
}
};
... ... @@ -269,6 +274,17 @@ const procOrderData = (payResult, uid) => {
})();
};
/**
* [0元订单或者货到付款-成功处理]
* @param {[type]} orderInfo [订单详情]
* @return {[type]} [{}]
*/
const deliveryData = (orderInfo) => {
return payApi.getResourceData(FRAUD_CONTENT_CODE).then(procData => {
return Object.assign(orderInfo, _execOrderData(orderInfo, procData && procData.data || {}));
});
};
module.exports = {
orderDetail,
getPayInfo,
... ... @@ -279,6 +295,7 @@ module.exports = {
sendPayConfirm,
procOrderData,
updateOrderPayment,
payments
payments,
deliveryData
};
... ...
<div class="pay-notice-page yoho-page">
{{# order}}
<div class="order-wrap">
<h1><i class="pay-sure-icon"></i>恭喜您,购买完成!您已成功支付<span class="red">{{payment_amount}}</span>元!</h1>
<h1>
<i class="pay-sure-icon"></i>
{{#if ../isDelivery}}订单提交成功!您需要在收货时向送货员支付{{else}}恭喜您,购买完成!您已成功支付{{/if}}
<span class="red">{{payment_amount}}</span>元!
</h1>
<div class="order-info">
<ul>
<li><span class="l-b">订单号: {{order_code}}</span></li>
<li><span class="l-b">在线金额: {{payment_amount}}</span></li>
<li><span class="l-b">{{#if ../isDelivery}}支付{{else}}在线{{/if}}金额: {{payment_amount}}</span></li>
<li>
<span class="l-b back-yoho-coin">共返有货币:{{yoho_give_coin}}</span>
<a href="{{yohoCoinUrl}}" class="notice-link" target="_blank">有货币能做什么>></a>
... ...
... ... @@ -12,7 +12,7 @@
<div class="cart-pay">
<h2>您的订单已成功,现在就去付款吧~</h2>
<h3>您的订单号:<strong class="order-num">{{order_code}}</strong> 应付金额:<strong>{{payment_amount}}</strong>&nbsp; &nbsp;
支付方式:{{payment_name}} &nbsp; &nbsp; &nbsp; 送货时间:{{delivery_time}}</h3>
支付方式:在线支付 &nbsp; &nbsp; &nbsp; 送货时间:{{delivery_time}}</h3>
<h4>{{../username}},如果2小时内您无法完成付款,系统会将您的订单取消。</h4>
</div>
{{/order}}
... ...