orderDetail.js
10.3 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
// const config = global.yoho.config;
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const closeReasons = () => {
return api.get('', {
method: 'app.SpaceOrders.closeReasons'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
return {};
}
});
};
/**
* 获取快递有关信息
* @private
*/
const _assignExpressInfo = (showLogistics, order) => {
let data = {};
if (showLogistics && order.expressCompany && order.expressCompany.caption) {
data = {
logisticsUrl: helpers.urlFormat('/home/logistic', {order_code: order.orderCode}),
logisticsCompany: order.expressCompany.caption,
logisticsNum: order.expressNumber || ''
};
}
return data;
};
/**
* 获取订单状态
* @private
*/
const _getOrderStatus = (order, showLogistics) => {
let result = {};
if (order.isCancel === 'Y') {
return {
canceled: true
};
}
order.status = parseInt(order.status, 10);
// 先判断订单付款方式,根据不同的付款方式计算订单状态。(注:货到付款没有待付款状态)
// 支付方式为非货到付款时,计算订单状态。
if (parseInt(order.paymentType, 10) !== 2) {
switch (order.status) {
case 0:
/* 待付款 */
Object.assign(result, {
unpaid: true,
payUrl: helpers.urlFormat('/home/orders/pay', {order_code: order.orderCode})
});
break;
case 1:
case 2:
case 3:
/* 已付款状态不给查看物流 URL */
Object.assign(result, {
unreceived: true
});
break;
case 4:
case 5:
/* 已发货状态,给查看物流或二维码URL */
Object.assign(result, {
unreceived: true
});
/* 是否门票 */
if (order.virtualType && parseInt(order.virtualType, 10) === 3) {
Object.assign(result, {
qrcode: helpers.urlFormat(`/home/QRcode/${order.orderCode}`)
});
} else {
Object.assign(result, _assignExpressInfo(showLogistics, order));
}
break;
case 6:
/* 已成功订单,给查看物流或二维码URL */
Object.assign(result, {
completed: true
});
/* 是否门票 */
if (order.virtual_type && parseInt(order.virtual_type, 10) === 3) {
Object.assign(result, {
qrcode: helpers.urlFormat(`/home/QRcode/${order.orderCode}`)
});
} else {
Object.assign(result, _assignExpressInfo(showLogistics, order));
}
break;
default:
break;
}
} else {
/* 订单为货到付款订单时,计算订单状态。(货到付款没有待付款状态) */
switch (order.status) {
case 0:
/* 备货中 */
Object.assign(result, {
unpaid: true
});
break;
case 1:
case 2:
case 3:
/* 已付款状态不给查看物流URL */
Object.assign(result, {
unreceived: true
});
break;
case 4:
case 5:
/* 待收货状态,给查看物流 url */
Object.assign(result, {
unreceived: true
});
Object.assign(result, _assignExpressInfo(showLogistics, order));
break;
case 6:
/* 待收货状态,给查看物流 url */
Object.assign(result, {
completed: true
});
Object.assign(result, _assignExpressInfo(showLogistics, order));
break;
default:
break;
}
}
return result;
};
const orderDetailData = (uid, orderCode) => {
return api.get('', {
method: 'app.SpaceOrders.detail',
uid: uid,
order_code: orderCode
}).then((result) => {
if (result && result.code === 200) {
let orderDetail = camelCase(result.data);
let goods = [];
let status = _getOrderStatus(orderDetail, true);
orderDetail = _.assign(orderDetail, status);
if (orderDetail.virtualType && orderDetail.virtualType === 3) {
orderDetail = _.assign(orderDetail, {
isVirtual: true,
mobile: result.data.mobile
});
}
orderDetail = _.assign(orderDetail, {
addressAll: orderDetail.area + orderDetail.address
// createTime: date('Y-m-d H:i:s', orderDetail.createTime)
});
// _.defer(function(orderDetail.createTime) {
// console.log(_.now() - orderDetail.createTime);
// }, _.now());
if (orderDetail.counterFlag && orderDetail.counterFlag === 'Y') {
orderDetail = _.assign(orderDetail, {
leftTime: parseInt(orderDetail.payLefttime, 10) * 1000
});
}
_.forEach(orderDetail.orderGoods, function(data) {
let obj = {};
let count = +data.buyNumber;
obj = _.assign(obj, {
thumb: data.goodsImage,
name: data.productName,
color: data.colorName,
size: data.sizeName,
price: data.goodsPrice,
count: count
});
if (data.goodsType === 'gift') {
obj = _.assign(obj, {
gift: true
});
} else if (data.goodsType === 'priceGift') {
obj = _.assign(obj, {
advanceBuy: true
});
}
if (data.expectArrivalTime) {
obj = _.assign(obj, {
appearDate: data.expectArrivalTime
});
}
if (data.productSkn) {
obj = _.assign(obj, {
link: '/product/show_' + data.productSkn + '.html'
});
}
goods.push(obj);
orderDetail = _.assign(orderDetail, {
orderCount: count
});
});
orderDetail.goods = goods;
if (orderDetail.paymentStatus === 'Y') {
orderDetail = _.assign(orderDetail, {
isPay: true
});
}
// 判断是否可以修改地址
if (orderDetail.canUpdateDeliveryAddress === 'Y') {
orderDetail = _.assign(orderDetail, {
changeable: true
});
}
// 判断是否有关联订单
if (orderDetail.relateOrderCode === 'Y') {
orderDetail = _.assign(orderDetail, {
relation: true
});
} else {
orderDetail = _.assign(orderDetail, {
relation: false
});
}
// 定金预售
if (orderDetail.attribute * 1 === 9) {
orderDetail = _.assign(orderDetail, {
isDepositAdvance: true
});
}
orderDetail = _.assign(orderDetail, {
goodsAmount: orderDetail.paymentAmount,
url: '/home/addressModify?orderCode=' + orderCode + '&relation=' + orderDetail.relation
});
// 为支付的拆单配送信息
if (orderDetail.isMultiPackage && orderDetail.isMultiPackage === 'Y') {
orderDetail = _.assign(orderDetail, {
isJit: true
// jitDetailUrl: '/cart/index/jitDetailUrl'
});
}
if (orderDetail.invoice) {
orderDetail.invoice.type = (orderDetail.invoice.type + '' === '2');
}
// 取消订单原因列表
let resons = closeReasons();
return closeReasons().then(list => {
resons = list;
orderDetail = _.assign(orderDetail, {
cancelReason: resons
});
return orderDetail;
});
// return orderDetail;
} else {
logger.error('detail info return no 200');
return {};
}
});
};
// 删除订单
const delOrder = (orderCode, uid) => {
return api.get('', {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
order_code: orderCode
});
};
// 再次购买
const readdData = (orderCode, uid) => {
return api.get('', {
method: 'app.Shopping.readd',
uid: uid,
order_code: orderCode
}).then((result) => {
if (result && result.code === 200) {
result.message = '商品已重新加入购物车';
} else if (result.code === '400') {
result.message = '缺失参数';
} else {
result.message = '商品加入购物车失败';
result.datat = {};
}
return result;
});
};
// 取消订单
const cancelOrder = (orderCode, uid, reasonId, gender, channel, reason) => {
return api.get('', {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: orderCode,
reasonId: reasonId,
reasons: reason,
gender: gender,
yh_channel: channel
});
};
module.exports = {
orderDetailData,
closeReasons,
delOrder,
readdData,
cancelOrder
};