returns.js
3.82 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
/**
* 退换货
* @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 helpers = global.yoho.helpers;
const pageSize = 10;
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 _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 getRefundGoodsData = (orderCode, uid) => {
return returnsAPI.getRefundGoodsAsync(orderCode, uid).then(result => {
let resData = {};
Object.assign(resData, _setSideMenu('我的退/换货'));
resData.returns = {
title: '退货申请',
refund: {}
};
if (result.data) {
Object.assign(resData.returns.refund, _setRefundGoodList(result.data), {
orderCode: orderCode
});
}
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: subRes.data.apply_id}};
}
return {code: 400, message: '申请失败'};
});
} else {
return {code: 403, message: '没有找到该订单'};
}
});
};
module.exports = {
getUserReturn,
getRefundGoodsData,
saveRefund
};