returns.js
12.7 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
/**
* 退换货
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/19
*/
'use strict';
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const mcHandler = require('./menu-crumb-handler');
const returnsAPI = require('./returns-api');
// const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const pageSize = 10;
const returnAddress = {
address: '江苏省南京市江宁区江宁经济技术开发区苏源大道87号YOHO!BUY(有货)物流中心东一楼',
name: 'YOHO!',
code: '210000',
phone: '17714194699'
};
// const _reduceArrByProductSku = data => {
// const d = [];
//
// d.push(data[0]);
//
// data.reduce((p, c) => { //eslint-disable-line
// if (p && c && p.productSku !== c.productSku) {
// d.push[c];
// }
// });
//
// return d;
// };
const getUserReturn = (uid, page) => {
return api.get('', {
method: 'app.refund.getList',
uid: uid,
page: page || 1,
limit: 10
}).then(result => {
const basicData = {
title: '我的退/换货'
};
const refundStr = {
1: '退货',
2: '换货'
};
const data = camelCase(result.data);
const paginationOpts = data.total > pageSize ? {
paginationOpts: {
total: data.total,
page: data.page,
limit: pageSize
}
} : false;
data.list.forEach(item => {
item.orderGoods = item.goods;
item.createTime = item.orderCreateTime;
item.hidePrice = true;
item.showStatus = true;
item.refundStr = refundStr[item.refundType];
item.orderGoods.forEach(it => {
it.hidePrice = true;
});
});
return {
returnsList: Object.assign(data, paginationOpts, basicData)
};
});
};
const _setSideMenu = (type) => {
return {
nav: mcHandler.getMeCrumb(type),
navigation: mcHandler.getSideMenu(type)
};
};
const _calcStatusRate = (num, total) => {
let rate = 0;
if (total) {
rate = `${_.toInteger(num / total * 100)}%`;
}
return rate;
};
const submitChange = (data, uid) => {
return returnsAPI.changeSubmitAsync(data, uid).then(result => {
return result;
});
};
const _setDefaultStatus = (type) => {
const list = ['提交申请', '审核通过', '商品寄回', '商品入库', `${type}完成`];
let statusList = [];
let resData = {};
_.forEach(list, (value, key) => {
statusList.push({
step: _.toInteger(key) + 1,
name: value
});
});
statusList[0].act = true;
resData.returnStstus = {
rate: _calcStatusRate(1, statusList.length),
statusList: statusList
};
return resData;
};
const _setReturnStatus = (list, half) => {
let resData = {};
if (list && list.length) {
let statusList = [],
step = 0;
let rate;
// 遍历进度列表
_.forEach(list, (value, key) => {
let state = {
act: value.act === 'Y',
step: _.toInteger(key) + 1,
name: value.name
};
if (state.act) {
step++;
}
statusList.push(state);
});
// 多半格进度特殊处理
if (half) {
rate = _calcStatusRate(step * 2 + 1, statusList.length * 2);
} else {
rate = _calcStatusRate(step, statusList.length);
}
resData.returnStstus = {
rate: rate,
statusList: statusList
};
}
return resData;
};
const _setRefundGoodList = (data) => {
let resData = {};
if (data.goods_list) {
let goods = [];
_.forEach(data.goods_list, value => {
let cnAlphabet = value.cn_alphabet ? value.cn_alphabet : '';
goods.push({
href: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goods_id}/${cnAlphabet}.html`),
img: value.goods_image,
name: value.product_name,
size: value.size_name,
color: value.color_name,
num: 1, // 接口目前不支持
price: value.last_price,
skn: value.product_skn,
skc: value.product_skc,
sku: value.product_sku,
type: value.goods_type,
typeId: value.goods_type_id,
reasonList: data.return_reason
});
if (value.hasShoes) {
resData.hasShoes = true;
}
});
resData.goods = goods;
}
resData.speclialReason = data.special_return_reason;
return resData;
};
const _setRefundDetailData = (data) => {
let resData = {
id: data.id || 0
};
data.status = 20;
switch (data.status) {
case 10:
resData.orderReview = {pass: true};
resData.refundExpress = true;
resData.refundAddress = returnAddress;
break;
case 20:
resData.refundExpress = true;
break;
case 30:
resData.backStorage = true;
break;
case 40:
resData.refundSure = {
mode: data.return_amount_mode_name,
account: data.return_amount_mode_name,
amount: data.return_amount_total,
coin: data.use_yoho_coin_num
};
break;
case 91:
resData.cancelApply = true;
break;
default:
resData.orderReview = true;
break;
}
if (resData.refundExpress) {
resData.refundExpress = {expressList: data.expressList};
if (_.get(data, 'notice.id', 0) === 20) {
let company = _.get(data, 'notice.express_company'),
key = _.findKey(data.expressList, {name: company});
Object.assign(resData.refundExpress, {
id: key ? data.expressList[key].id : 0,
company: company,
number: _.get(data, 'notice.express_number', 0)
});
}
}
let goods = [];
_.forEach(data.goods_list, value => {
let cnAlphabet = value.cn_alphabet ? value.cn_alphabet : '';
goods.push({
href: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goods_id}/${cnAlphabet}.html`),
img: value.goods_image,
name: value.product_name,
size: value.size_name,
color: value.color_name,
num: 1, // 接口目前不支持
reason: value.reason_name || '--',
price: value.sales_price,
remark: value.remark,
evidence: value.evidence_images
});
});
resData.goods = goods;
return resData;
};
const _setExpressData = (data) => {
var resData = [];
if (!_.isEmpty(data)) {
let list = [];
_.forEach(data, value => {
list = list.concat(value);
});
_.forEach(list, value => {
resData.push({
id: value.id,
name: value.company_name
});
});
}
return resData;
};
const _setExchangeDetailData = (data) => {
let list = {};
switch (data.status) {
case 0:
list.audit = true;
break;
case 10:
list.through = true;
break;
case 50:
list.send = true;
list.auditSuccess = true;
break;
case 40:
list.finish = true;
list.auditSuccess = true;
break;
default:
break;
}
return list;
};
const getRefundGoodsData = (orderCode, uid) => {
return returnsAPI.getRefundGoodsAsync(orderCode, uid).then(result => {
let resData = {};
Object.assign(resData, _setSideMenu('我的退/换货'));
resData.returns = {
title: '退货申请',
refund: _setDefaultStatus('退货') || {}
};
if (result.data) {
Object.assign(resData.returns.refund, _setRefundGoodList(result.data), {
orderCode: orderCode
});
}
return resData;
});
};
const getRefundDetailData = (applyId, uid) => {
return Promise.all([
returnsAPI.getRefundDetailAsync(applyId, uid),
returnsAPI.getExpressCompanyAsync()
]).then(result => {
let resData = {};
Object.assign(resData, _setSideMenu('我的退/换货'));
resData.returns = {
title: '退货申请',
refundDetail: {}
};
if (result[0] && result[0].data) {
let data = result[0].data;
if (result[1] && result[1].data) {
data.expressList = _setExpressData(result[1].data);
}
// 设置状态进度
Object.assign(resData.returns.refundDetail, _setReturnStatus(data.statusList, !data.status));
// 设置退货详情信息
Object.assign(resData.returns.refundDetail, _setRefundDetailData(data));
}
return resData;
});
};
const saveRefund = (orderCode, uid, goods, payment) => {
return returnsAPI.getOrderInfoAsync(orderCode, uid, '').then(result => {
if (!_.isEmpty(result)) {
return returnsAPI.refundSubmitAsync(orderCode, uid, goods, payment).then(subRes => {
if (subRes && subRes.data) {
return {
code: 200,
data: {
refer: `/me/return/refund/detail/${subRes.data.apply_id}`
}
};
}
return {code: 400, message: '申请失败'};
});
} else {
return {code: 403, message: '没有找到该订单'};
}
});
};
const getProductInfo = (productId, productSkn) => {
return returnsAPI.getProductInfoAsync(productId, productSkn).then(result => {
if (result.code === 200) {
camelCase(result);
result.data.goodsList.forEach(good => {
good.colorImage = helpers.image(good.colorImage, 20, 20);
});
}
return result;
});
};
const getChangeGoodsList = (orderCode, uid) => {
return returnsAPI.getChangeGoodsListAsync(orderCode, uid).then(result => {
const basicData = {
title: '申请换货'
};
let data;
if (result && result.data) {
data = camelCase(result.data);
// data.goodsList = _reduceArrByProductSku(data.goodsList);
data.hidePrice = true;
data.orderCode = orderCode;
data.goodsList.forEach(good => {
good.showCheckbox = true;
good.hidePrice = true;
// good.buyNumber = good.num;
good.buyNumber = 1;
});
}
return {
returnsChange: Object.assign(basicData, data)
};
});
};
const getExchangeDetailData = (id, uid) => {
return returnsAPI.getExchangeDetail(id, uid).then(result => {
let exchangeData = {};
Object.assign(exchangeData, _setSideMenu('我的退/换货'));
exchangeData = {
title: '换货申请',
exchangeDetail: {}
};
if (result.data) {
// console.log(_setRefundDetailData(result.data));
Object.assign(exchangeData.exchangeDetail, _setReturnStatus(result.data.statusList));// 头部
Object.assign(exchangeData.exchangeDetail, _setExchangeDetailData(result.data));
// Object.assign(exchangeData.exchangeDetail, camelCase(result.data));
}
// console.log(exchangeData);
return {returns: exchangeData};
});
};
const cancelReturnApply = (id, uid, type) => {
return returnsAPI.cancelReturnAsync(id, uid, type).then(result => {
let resData = result || {
code: 400,
message: '取消失败'
};
return resData;
});
};
const setBackEepress = (uid, param) => {
const type = param.type === 'exchange';
return returnsAPI.setExpressNumberAsync(uid, param, type).then(result => {
let resData = result || {
code: 400,
message: '设置寄回单号失败'
};
return resData;
});
};
module.exports = {
getUserReturn,
getRefundGoodsData,
getChangeGoodsList,
getProductInfo,
getRefundDetailData,
saveRefund,
getExchangeDetailData,
submitChange,
cancelReturnApply,
setBackEepress
};