orderDetail.js
17.2 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
'use strict';
const _ = require('lodash');
// const config = global.yoho.config;
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const stringProcess = require(`${global.utils}/string-process`);
const CODE_LOGISTIC_BANNER = '1fc9b2484fcd559049f2f7e0db313f20'; // 物流详情banner资源码
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
closeReasons() {
return this.get({
data: {method: 'app.SpaceOrders.closeReasons'},
param: {cache: true}
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
return {};
}
});
}
/**
* 获取快递有关信息
* @private
*/
_assignExpressInfo(showLogistics, order) {
let data = {};
data = {
logisticsUrl: helpers.urlFormat('/home/logistic', {order_code: order.orderCode})
};
return data;
}
/**
* 获取订单状态
* @private
*/
_getOrderStatus(order, showLogistics) {
let orderBtn = [];
if (!order) {
return {};
}
let attribute = _.parseInt(_.get(order, 'orderExtInfo.attribute'));
order = _.assign(order, {
orderCode: _.get(order, 'orderExtInfo.orderCode')
});
if (attribute === 9 || attribute === 11) {
// 定金预售拼接提示语
let countTime = 0;
let payAmount = 0;
if (_.get(order, 'orderDetailInfo.ext.payLefttime') &&
parseInt(order.orderDetailInfo.ext.payLefttime, 10)) {
countTime = order.orderDetailInfo.ext.payLefttime * 1000;
}
if (_.get(order, 'orderDetailInfo.key') === '203') { // 待支付尾款
payAmount = _.get(order, 'orderExtInfo.orderTailPayAmount');
order.orderDetailInfo.ext.desc = `你的商品已到货,您还需支付尾款<span>¥${payAmount}</span>,
请在<i class="hours new-hours hide">${countTime}</i>内完成支付。超时订单自动取消`;
} else if (_.get(order, 'orderDetailInfo.key') === '201') { // 待支付定金
payAmount = _.get(order, 'orderExtInfo.orderDepositAmount');
order.orderDetailInfo.ext.desc = `您需支付定金<span>¥${payAmount}</span>,
请在<i class="hours new-hours hide">${countTime}</i>内完成支付。超时订单自动取消`;
}
/* 预售商品,不能进行任何操作 */
orderBtn.push({
isAdvance: true
});
return { orderBtn: orderBtn };
}
/* 倒计时时间 订单详情页倒计时不在同一级*/
if (_.get(order, 'orderDetailInfo.ext.payLefttime') && parseInt(order.orderDetailInfo.ext.payLefttime, 10)) {
orderBtn.push({
leftTimeTop: order.orderDetailInfo.ext.payLefttime * 1000
});
}
_.each(order.links, (val) => {
switch (val) {
case 'refundApply':// 申请退款
orderBtn.push({
refundApply: true
});
break;
case 'modifyAddress':// 修改收货地址
orderBtn.push({
modifyAddress: true,
link: helpers.urlFormat('/home/orders/addressModify', {
relation: order.relateOrderCode === 'Y', // 判断是否有关联订单
orderCode: order.orderCode,
areaCode: _.get(order, 'deliveryInfo.deliveryAddress.areaCode', ''),
provinceAreaCode: _.get(order, 'deliveryInfo.isSupportChangeProvince') !== 'Y' &&
_.get(order, 'deliveryInfo.deliveryAddress.provinceAreaCode', '') || ''// 如果不允许修改省
})
});
break;
case 'buyNow':// 立即付款
orderBtn.push({
buyNow: true,
link: helpers.urlFormat('/home/orders/paynew', {order_code: order.orderCode}),
});
break;
case 'closeOrder':// 取消订单
orderBtn.push({
closeOrder: true
});
break;
case 'confirm':// 订单确认
orderBtn.push({
confirm: true
});
break;
case 'getExpress':// 查看物流
orderBtn.push(Object.assign(
{getExpress: true},
this._assignExpressInfo(showLogistics, order)
));
break;
case 'shareOrder':// 晒单评价
break;
case 'delOrder':// 删除订单
orderBtn.push({
delOrder: true,
});
break;
case 'lookQrcode':// 查看二维码
orderBtn.push({
lookQrcode: true,
link: helpers.urlFormat(`/home/QRcode/${order.orderCode}`),
});
break;
case 'afterService':// 售后服务
orderBtn.push({
afterService: true
});
break;
case 'readd':// 再次购买
orderBtn.push({
readd: true
});
break;
default:
break;
}
});
return {orderBtn: orderBtn};
}
orderDetailData(uid, orderCode) {
if (!uid || !orderCode || !stringProcess.isNumeric(orderCode)) {
return Promise.resolve({});
}
return this.get({
data: {
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 = this._getOrderStatus(orderDetail, true);
let offlinestore; // 线下店订单
let deliveryOffline; // 门店取货
orderDetail = _.assign(orderDetail, status, {orderCode: orderCode});
if (parseInt(_.get(orderDetail, 'orderExtInfo.attribute'), 10) === 3) {
orderDetail = _.assign(orderDetail, {
isVirtual: true,
mobile: _.get(orderDetail, 'deliveryInfo.mobile')
});
}
if (orderDetail.deliveryInfo) {
orderDetail = _.assign(orderDetail, {
addressAll: orderDetail.deliveryInfo.area + orderDetail.deliveryInfo.address
});
}
if (orderDetail.links) {
_.forEach(orderDetail.links, (val) => {
if (val === 'getExpress') {
orderDetail = _.assign(orderDetail, {
expressUrl: helpers.urlFormat('/home/logistic', {order_code: orderCode})
});
return;
}
});
}
_.forEach(orderDetail.orderGoods, function(data) {
let obj = {};
let count = +data.buyNumber;
obj = _.assign(obj, {
thumb: data.goodsImage,
name: data.productName,
color: data.factoryColorName ? data.factoryColorName : data.colorName,
size: data.sizeName,
payPrice: data.realPayPrice,
salePrice: parseFloat(data.salesPrice).toFixed(2),
count: count,
tickets: data.goodsType === 'ticket'
// isVipPrice: data.discountTag === 'V',
// isStudebt: data.discountTag === 'S'
});
if (parseInt(data.realPayPrice, 10) === parseInt(data.salesPrice, 10)) {
obj.salePrice = false;
}
if (data.goodsType === 'gift') {
obj = _.assign(obj, {
gift: true,
salePrice: parseFloat(data.salesPrice).toFixed(2),
payPrice: data.goodsPrice
});
} else if (data.goodsType === 'price_gift') {
obj = _.assign(obj, {
advanceBuy: true,
salePrice: parseFloat(data.salesPrice).toFixed(2),
payPrice: data.goodsPrice
});
}
if (data.expectArrivalTime) {
obj = _.assign(obj, {
appearDate: data.expectArrivalTime
});
}
if (data.productSkn) {
obj = _.assign(obj, {
link: '/product/' + data.productSkn + '.html' // 商品url改版
});
}
if (data.goodsType === 'ticket') {
obj = _.assign(obj, {
tickets: true
});
}
goods.push(obj);
orderDetail = _.assign(orderDetail, {
orderCount: count
});
});
orderDetail.goods = goods;
// 为支付的拆单配送信息
if (orderDetail.packageInfo) {
orderDetail = _.assign(orderDetail, {
jitDetailUrl: helpers.urlFormat('/cart/index/new/jitDetail', {
orderCode: orderCode
}),
packageTitle: _.get(orderDetail, 'packageInfo.packageTitle')
});
}
if (parseInt(orderDetail.paymentType, 10) !== 2) {
if (_.get(orderDetail, 'isOfflineshops', 'N') === 'Y') {
offlinestore = orderDetail.offlineStore !== '' ? orderDetail.offlineStore : false;
deliveryOffline = _.get(orderDetail, 'isDeliveryOffline', 'N') === 'Y' ? true : false;
} else {
offlinestore = false;
deliveryOffline = false;
}
orderDetail = _.assign(orderDetail, {
offlinestore: offlinestore,
deliveryOffline: deliveryOffline
});
} else {
orderDetail.paymentName = orderDetail.paymentName !== '' ? orderDetail.paymentName : '货到付款';
}
if (orderDetail.invoice) {
orderDetail.invoice.type = (orderDetail.invoice.type + '' === '2');
}
if (_.get(result, 'data.isSupportRefund', 'N') === 'Y') {
orderDetail.refundUrl = helpers.urlFormat('/home/return/refund', {orderCode: orderCode});
}
if (_.get(result, 'data.isSupportExchange', 'N') === 'Y') {
orderDetail.changeUrl = helpers.urlFormat('/home/return/exchange', {orderCode: orderCode});
}
orderDetail.imUrl = helpers.urlFormat('/service/chatQaList');
return orderDetail;
} else {
logger.error('detail info return no 200');
return {};
}
});
}
// 删除订单
delOrder(orderCode, uid) {
return this.get({
data: {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
order_code: orderCode
}
});
}
// 再次购买
readdData(orderCode, uid) {
return this.get({
data: {
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;
});
}
// 取消订单
cancelOrder(orderCode, uid, reasonId, gender, channel, reason) {
return this.get({
data: {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: orderCode,
reason_id: reasonId,
reason: reason,
gender: gender,
yh_channel: channel
}
});
}
/**
* 申请退款
*/
refundApply(params) {
return this.get({
data: {
method: 'app.SpaceOrders.refundApply',
uid: params.uid,
order_code: params.orderCode,
reason_id: params.reasonId,
reason: params.reason
}
});
}
/*
* 我的订单-查看物流
* @param int $orderCode 订单号
* @param int $uid 用户ID
* @return array
*/
_logisticsData(params) {
let finalParams = {
order_code: params.order_code,
uid: params.uid
};
finalParams.method = 'app.express.li';
// 退换货物流
if (params.type === 'refund' || params.type === 'change') {
_.assign(finalParams, {
method: 'app.express.getNewExpress',
id: params.id,
type: params.type
});
} else {
_.assign(finalParams, {
method: 'app.express.li'
});
}
return this.get({
data: finalParams
});
}
/**
* 获取物流详情页banner
*/
_getLogisterBanner() {
return this.get({
url: 'operations/api/v5/resource/get',
data: {content_code: CODE_LOGISTIC_BANNER},
params: {code: 200},
api: global.yoho.ServiceAPI
});
}
/**
* 查看物流
*
* @param int orderCode 订单编号
* @param int uid 用户ID
* @return array
*/
logistics(params) {
return Promise.all([
this._getLogisterBanner(),
this._logisticsData(params),
]).then(result => {
let finalResult = {
banner: []
};
let banners = result[0];
let logistic = result[1];
// 获取物流详情页banner
if (banners && banners.data) {
_.forEach(banners.data, value => {
_.forEach(value.data, subValue => {
finalResult.banner.push({
url: subValue.url,
img: subValue.src
});
});
});
}
if (logistic && logistic.data) {
finalResult.logisticUrl = _.get(logistic, 'data.url', '');
finalResult.logisticImg = _.get(logistic, 'data.logo', '');
finalResult.logisticCompany = _.get(logistic, 'data.caption', '');
finalResult.logisticNumber = _.get(logistic, 'data.express_number', '');
finalResult.logisticDetail = [];
_.forEach(_.get(logistic, 'data.express_detail', []), value => {
finalResult.logisticDetail.push({
status: value.accept_address,
date: value.acceptTime,
});
});
}
return finalResult;
});
}
/**
* 修改订单地址
* @param {参数} params
*/
changeAddress(params) {
let apiParams = {
method: 'app.SpaceOrders.updateDeliveryAddress',
order_code: params.orderCode,
uid: params.uid,
user_name: params.username,
area_code: params.areaCode,
address: params.address,
mobile: params.mobile,
udid: params.udid
};
if (params.addressId) {
Object.assign(apiParams, {
address_id: params.addressId
});
}
if (params.phone) {
Object.assign(apiParams, {
phone: params.phone
});
}
return this.get({
data: apiParams
});
}
};