order-ensure-handle.js
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* 订单确认数据处理
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/11/28
*/
'use strict';
const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
const handleViewPrice = list => {
if (list) {
_.forEach(list, val => {
if (val.promotion === '商品金额') {
val.promotion = '商品总价';
val.promotion_amount = `+ ${val.promotion_amount}`;
} else {
val.promotion_amount = _.replace(val.promotion_amount, '+', '+ ');
val.promotion_amount = _.replace(val.promotion_amount, '-', '- ');
}
});
}
};
const handleUseYohoCoin = (info) => {
let resData = {};
let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
if (info) {
Object.assign(resData, {
yoho_coin: info.yoho_coin.toFixed(2),
use_yoho_coin: info.use_yoho_coin,
total_yoho_coin_num: info.total_yoho_coin_num,
yoho_coin_pay_rule: info.yoho_coin_pay_rule,
canUseCoinNum: _.round(info.yoho_coin * 100),
usedCoinNum: _.round(info.use_yoho_coin * 100)
});
if (!resData.canUseCoinNum) {
let coinErrorTip = '';
if (info.total_yoho_coin_num > limitCoin) {
coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件';
} else {
coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`;
}
resData.coinErrorTip = coinErrorTip;
}
}
return resData;
};
const handlePaymentInfo = (d, address) => {
let resData = {};
// 地址信息加密
// d.delivery_address.id = crypto.encryption('', `${d.delivery_address.address_id}`);
// delete d.delivery_address.address_id;
// resData.deliveryAddress = d.delivery_address;
_.forEach(address, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
}
// 地址加密
let id = dd.address_id;
dd.id = crypto.encryption('', `${id}`);
// 删除uid,用户数据保密
_.unset(dd, 'address_id');
_.unset(dd, 'uid');
});
resData.deliveryAddress = address;
d.shopping_cart_data.hasCoin = _.round(d.yoho_coin * 100); // 有货币稀释
// let supportLine = [];
// _.forEach(['zhifubao', 'zaixianzhifu', 'weixinzhifu', 'wangyinzaixian',
// 'caifutong', 'shengfutong', 'tonglianzhifu'], sl => {
// supportLine.push(`//static.yohobuy.com/images/pay/icon/${sl}.png`);
// }
// );
// resData.supportLine = supportLine;
// let supportBank = [];
// _.forEach(
// ['BOC', 'ICBC', 'CMB', 'CCB', 'ABC', 'SPDB', 'CIB', 'GDB', 'SDB', 'CMBC',
// 'COMM', 'CITIC', 'HZCBB2C', 'CEB', 'SHBANK', 'NBBANK', 'SZPAB', 'BJRCB', 'FDB', 'PSBC'],
// sb => {
// supportBank.push(`//static.yohobuy.com/images/bankico/${sb}.gif`);
// }
// );
// resData.supportBank = supportBank;
_.forEach(d.goods_list, g => {
// link to goods
g.linkToGoods = helper.urlFormat(`/product/pro_${g.product_id}_${g.goods_id}/${g.cn_alphabet}.html`,
'', 'item');
});
resData.goodsList = d.goods_list;
_.remove(d.payment_way, function(n) {
return n.is_support === 'N';
});
// let dPw = _.find(d.payment_way, {default: 'Y'});
// let dDt = _.find(d.delivery_time, {default: 'Y'});
// resData.defaultPayDelivery = {
// paymentTypeName: dPw ? dPw.payment_type_name : '在线支付(推荐)',
// paymentType: dPw ? dPw.payment_type : 1,
// paymentTypeId: dPw ? dPw.payment_id : 15,
// deliveryTimeStr: dDt ? dDt.delivery_time_string : '送货时间不限',
// deliveryTimeId: dDt ? dDt.delivery_time_id : 2,
// contractMe: false
// };
if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) {
handleViewPrice(d.shopping_cart_data.promotion_formula_list);
}
Object.assign(resData, {
paymentWay: d.payment_way,
deliveryTime: d.delivery_time,
deliveryWay: d.delivery_way,
shoppingCartData: Object.assign(d.shopping_cart_data, handleUseYohoCoin(d)),
invoices: d.invoices
});
return resData;
};
module.exports = {
handleViewPrice,
handleUseYohoCoin,
handlePaymentInfo
};