order.js
5.4 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* 结算页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/7/13
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helper = global.yoho.helpers;
/**
* 结算页面api
* @param uid 用户id
*/
const _orderApi = uid => api.get('', {
method: 'app.Shopping.payment',
'cart_type': 'ordinary', // eslint-disable-line
'yoho_coin_mode': 0, // eslint-disable-line
uid: uid
});
/**
* 结算页面
* @param uid [int] user id
*/
const index = uid => {
return _orderApi(uid).then(data => {
if (data.code === 200) {
// do data package
let theData = data.data;
let goods = theData.goods_list;
let shopping = theData.shopping_cart_data;
let packageList = shopping.package_list;
_.forEach(goods, theGoods => {
// format goods link
theGoods.link = helper.urlFormat(
`/product/pro_${theGoods.product_id}_${theGoods.goods_id}/${theGoods.cn_alphabet}.html`);
// format brand url
theGoods.brandUrl = helper.urlFormat(`/product/shop/${theGoods.brand_domain}`);
// 处理商品是否是赠品
if (theGoods.goods_type === 'gift') {
theGoods.isGift = true;
}
});
theData.yoho_coin *= 100; // 有货币稀释
shopping.balanceCoin = theData.use_yoho_coin;
// 拆单后的邮费优惠计算
if (packageList) {
let shippingOrigin = 0;
let shippingCut = 0;
_.forEach(packageList, i => {
shippingOrigin += (i.shopping_orig_cost >>> 0);
shippingCut += (i.shopping_cut_cost >>> 0);
});
// 对运费的数据进行扩展
shippingCut === 0 || Object.assign(
_.filter(shopping.promotion_formula_list, i => i.promotion === '运费'), {
shippingCut: shippingCut,
shippingOrigin: shippingOrigin
}
);
}
return data;
}
return data;
});
};
/**
* 结算api调用
* @param number uid user id
* @param number $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param number $yohoCoin 使用的YOHO币数量
* */
const _computeApi = (uid, deliveryWay, paymentType, yohoCoin) => api.get('', {
method: 'app.Shopping.compute',
uid: uid,
delivery_way: deliveryWay,
payment_type: paymentType,
use_yoho_coin: yohoCoin
});
/**
* 结算
* @param uid [int] user id
* @param yohoCoin [int] 使用的有货币
*/
const compute = (uid, yohoCoin) => {
// 目前仅支持普通快递和在线支付
let deliveryWay = 1;
let paymentType = 1;
let coin;
// YOHO币稀释
if (yohoCoin) {
coin = yohoCoin / 100;
}
return _computeApi(uid, deliveryWay, paymentType, coin).then(result => result);
};
/**
* 提交订单api调用
* @param number uid user id
* @param number address_id 地址id
* @param number use_yoho_coin 使用的有货币(元)
* @param string invoices_title 发票抬头
* @param int invoices_type_id 发票内容
* @param string remark 备注
* @param boolean isPrintPrice 是否打印价格
* @param number delivery_time 送货时间
* @param number delivery_way 送货方式(1-普通,2-顺丰)
* @param number payment_id 支付id
* @param number payment_type 支付类型
*/
const _submit = (uid, other) => {
let apiParms = {
method: 'app.Shopping.submit',
uid: uid,
address_id: other.address_id,
use_yoho_coin: other.use_yoho_coin,
remark: other.remark,
isPrintPrice: other.isPrintPrice,
delivery_time: other.delivery_time,
delivery_way: other.delivery_way,
payment_id: other.payment_id,
payment_type: other.payment_type
};
if (other.invoices_title) {
Object.assign(apiParms, {
invoices_title: other.invoices_title,
invoices_type_id: other.invoices_type_id
});
}
return api.get('', apiParms);
};
/**
* 订单提交
* @param uid [int] userid
* @param other [object] contains some param
*/
const submit = (uid, other) => {
let theOther = {};
Object.assign(theOther, other, {
delivery_time: 2, // 平时和周末都送货
delivery_way: 2, // blk统一为顺丰
payment_id: 1, // 支付宝
payment_type: 1, // 在线支付
use_yoho_coin: other.use_yoho_coin / 100 // 有货币稀释
});
return _submit(uid, theOther).then(result => result);
};
/**
* 查询订单信息接口
* @param uid
* @param code
* @returns {*}
*/
const orderDetail = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.detail',
uid: uid,
order_code: code
}, {code: 200});
};
/**
* 更新订单支付方式
* @param code
* @param payment
* @param uid
* @returns {*}
*/
const updateOrderPayment = (code, payment, uid) => {
return api.get('', {
method: 'app.SpaceOrders.updateOrdersPaymentByCode',
order_code: code,
payment: payment,
uid: uid
});
};
module.exports = {
index,
compute,
submit,
orderDetail,
updateOrderPayment
};