returns.js
5.48 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
/**
* 退换货controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/18
*/
'use strict';
const mcHandler = require('../models/menu-crumb-handler');
const returns = require('../models/returns');
const _ = require('lodash');
/**
* 退换货列表页
*/
const index = (req, res, next) => {
const uid = req.user.uid;
const page = req.query.page;
returns.getUserReturn(uid, page).then(result => {
res.display('index', {
page: 'return-list',
isMe: true,
content: Object.assign({
nav: mcHandler.getMeCrumb('我的退/换货'),
navigation: mcHandler.getSideMenu('我的退/换货'),
banner: 'http://placehold.it/{width}x{height}'
}, result)
});
}).catch(next);
};
/**
* 退货申请页
*/
const refund = (req, res, next) => {
let uid = req.user.uid;
let code = parseInt(req.params.orderCode, 10);
if (!uid || !code) {
return next();
}
returns.getRefundGoodsData(code, uid).then(result => {
res.display('index', {
page: 'refund',
content: result
});
}).catch(next);
};
/**
* 退货申请提交
* @return { Object } 申请结果
*/
const refundApply = (req, res, next) => {
let orderCode = req.body.orderCode,
uid = req.user.uid,
goods = req.body.goods,
payment = req.body.payment;
if (!orderCode || _.isEmpty(goods) || _.isEmpty(payment)) {
return res.json({
code: 203,
message: '非法提交'
});
}
returns.saveRefund(orderCode, uid, goods, payment).then(result => {
res.json(result);
}).catch(next);
};
/**
* 退货详情页
*/
const refundDetail = (req, res, next) => {
let applyId = parseInt(req.params.applyId, 10),
uid = req.user.uid;
if (!uid || !applyId) {
return next();
}
returns.getRefundDetailData(applyId, uid).then(result => {
res.display('index', {
page: 'refund-detail',
content: result
});
}).catch(next);
};
/**
* 换货申请页
*/
const exchange = (req, res, next) => {
const code = req.params.orderCode;
const uid = req.user.uid;
returns.getChangeGoodsList(code, uid).then(result => {
res.display('index', {
page: 'exchange',
isMe: true,
content: Object.assign({
nav: mcHandler.getMeCrumb('我的退/换货'),
navigation: mcHandler.getSideMenu('我的退/换货'),
banner: 'http://placehold.it/{width}x{height}'
}, result)
});
}).catch(next);
};
/**
* 获取商品详情
* @function getProductInfo
* @param { number } productId 商品id
* @param { number } productSkn 商品skn
* @return { Object } 商品信息
*/
const getProductInfo = (req, res, next) => {
const productId = req.query.productId;
const productSkn = req.query.productSkn;
returns.getProductInfo(productId, productSkn).then(result => {
res.json(result);
}).catch(next);
};
/**
* 换货详情页
*/
const exchangeDeatail = (req, res) => {
let id = parseInt(req.params.applyId, 10),
uid = req.user.uid;
returns.getExchangeDetailData(id, uid).then(result => {
res.display('index', {
page: 'exchange-detail',
isMe: true,
content: {
nav: mcHandler.getMeCrumb('我的退/换货'),
navigation: mcHandler.getSideMenu('我的退/换货'),
banner: 'http://placehold.it/{width}x{height}',
returns: {
title: '换货申请',
exchange: result.exchangeDetail
}
}
});
});
};
/**
* 换货申请提交
*/
const exchangeSubmit = (req, res, next) => {
const uid = req.user.uid;
returns.submitChange(req.query, uid).then(result => {
res.json(result);
}).catch(next);
};
/**
* 取消退换货申请
* @function cancelApply
* @param { string } uid 用户uid
* @param { string } type 退换货类型 refund--退货 exchange--换货
* @return { Object } 取消退换货结果
*/
const cancelApply = (req, res, next) => {
const uid = req.user.uid;
const id = req.body.id;
const type = req.body.type === 'exchange';
if (!uid || !id) {
return next();
}
returns.cancelReturnApply(id, uid, type).then(result => {
res.json(result);
}).catch(next);
};
/**
* 设置寄回物流单号
* @function setEepress
* @param { Object } param 物流信息
* @return { Object } 潮流尖货状态
*/
const setEepress = (req, res, next) => {
const uid = req.user.uid;
const param = req.body;
if (!uid) {
return next();
}
returns.setBackEepress(uid, param).then(result => {
res.json(result);
}).catch(next);
};
/**
* 获取银行列表
* @function setEepress
* @return { Object } 银行列表
*/
const getUnion = (req, res, next) => {
returns.getUnionData().then(result => {
res.json(result);
}).catch(next);
};
const getChangeType = (req, res, next) => {
const uid = req.user.uid;
const areaCode = req.query.areaCode;
returns.getChangeType(uid, areaCode).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
refund,
refundApply,
exchange,
getProductInfo,
refundDetail,
exchangeDeatail,
exchangeSubmit,
cancelApply,
setEepress,
getUnion,
getChangeType
};