returns.js
5.27 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
/**
* 个人中心 退换货
* @author 陈轩 <xuan.chen@yoho.cn>
*/
'use strict';
const helpers = global.yoho.helpers;
const returnsModel = require('../models/returns');
/**
* 我的退换货-列表页
*/
const index = (req, res, next) => {
const page = req.query.page;
returnsModel.getReturnsList(req.user.uid, page, 10)
.then(data => {
const viewData = Object.assign({
module: 'home',
page: 'returns',
meReturnsPage: true
}, data);
res.render('returns/returns', viewData);
})
.catch(next);
};
/**
* 我的订单-退货申请页
*/
const refundApply = (req, res, next) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
returnsModel.getOrderRefund(orderCode, uid).then(result => {
res.render('returns/returns-apply', result);
}).catch(next);
};
/**
* 我的订单-退货提交
*/
const saveRefund = (req, res, next) => {
const uid = req.user.uid;
returnsModel.saveRefund(req, uid).then(result => {
res.send(result);
}).catch(next);
};
/**
* 退货成功
*/
const refundSuccess = (req, res) => {
let resData = {
save: {
type: '退货',
ordersHref: helpers.urlFormat('/home/orders'),
returnsHref: helpers.urlFormat('/home/returns'),
refund: {// 退货时传退货收件地址
address: '南京市江宁区江宁经济技术开发区苏源大道87号YOHO!有货物流中心东一楼',
name: 'YOHO!有货',
phone: '400-889-9646',
postcode: '211106'
}
}
};
res.render('returns/returns-save', {returns: resData});
};
/**
* 换货成功
*/
const exchangeSuccess = (req, res) => {
let resData = {
save: {
type: '换货',
ordersHref: helpers.urlFormat('/home/orders'),
returnsHref: helpers.urlFormat('/home/returns')
}
};
res.render('returns/returns-save', {returns: resData});
};
/**
* 我的退换货-退货详情页
*/
const refundDetail = (req, res, next) => {
const code = req.query.id;
const uid = req.user.uid;
let resData = {
module: 'home',
page: 'returns'
};
returnsModel.getRefundDetail(code, uid).then(result => {
Object.assign(resData, result);
res.render('returns/returns-detail', resData);
}).catch(next);
};
/**
* 我的订单-提交换货申请
*/
const saveExchange = (req, res, next) => {
let uid = req.user.uid;
returnsModel.saveExchange(req, uid).then(result => {
res.send(result);
}).catch(next);
};
/**
* 我的退换货-换货详情页
*/
const exchangeDetail = (req, res, next) => {
const code = req.query.id;
const uid = req.user.uid;
let resData = {
module: 'home',
page: 'returns'
};
returnsModel.getChangeDetail(code, uid).then(result => {
Object.assign(resData, result);
res.render('returns/returns-detail', resData);
}).catch(next);
};
/**
* 我的订单-获取换货方式
*/
const getDelivery = (req, res, next) => {
let areaCode = req.body.areaCode;
// 获取必要参数
let uid = req.user.uid;
let gender = req.yoho.gender;
let channel = req.yoho.channel;
// 调用接口获得该用户支持的换货方式(白金会员可享受上门换货,偏远地区不支持上门换货)
returnsModel.getDelivery(areaCode, uid, gender, channel).then(result => {
res.send(result);
}).catch(next);
};
/**
* 我的订单-换货申请页
*/
const exchangeApply = (req, res, next) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
returnsModel.getOrderExchange(orderCode, uid).then(result => {
res.render('returns/returns-apply', result);
}).catch(next);
};
/**
* 取消退货申请
*/
const cancelRefund = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid;
returnsModel.getCancelRefund(id, uid).then(result => {
res.send(result);
}).catch(next);
};
/**
* 取消换货申请
*/
const cancelChange = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid;
returnsModel.getCancelChange(id, uid).then(result => {
res.send(result);
}).catch(next);
};
/**
* 我的退换货-设置快递单号
*/
const setExpressNumber = (req, res, next) => {
let uid = req.user.uid;
let id = req.body.id;
let isChange = req.body.isChange === 'false' ? false : true;
let expressId = req.body.expressId;
let expressNumber = req.body.expressNumber;
let expressCompany = req.body.expressCompany;
returnsModel.setExpressNumber(id, expressId, expressNumber, uid, expressCompany, isChange).then(result => {
if (res.code && res.code === 201) {
res.json({message: '请求失败'});
}
if (id || expressId || expressNumber || uid || expressCompany || isChange) {
res.send(result);
}
}).catch(next);
};
module.exports = {
index,
refundApply,
saveRefund,
refundSuccess,
refundDetail,
saveExchange,
exchangeApply,
exchangeSuccess,
exchangeDetail,
getDelivery,
cancelRefund,
cancelChange,
setExpressNumber
};