refund.js
5.33 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
/**
* 退换货
* @type {Object}
*/
'use strict';
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const refundModel = require('../models/refund');
const notLoginCode = 400;
const notLoginTip = '抱歉,您暂未登录!';
const helpers = global.yoho.helpers;
const refund = {
refund(req, res) {
let headerData = headerModel.setNav({
navTitle: '退货申请',
suggestSub: {
text: ''
},
navBtn: false
});
res.render('refund/refund', {
module: 'home',
pageHeader: headerData,
page: 'refund',
localCss: true
});
},
order(req, res, next) {
const uid = req.user.uid;
const orderCode = req.query.orderCode;
if (!orderCode) {
return next();
}
refundModel.getOrderData(uid, orderCode).then(result => {
res.json(result);
}).catch(next);
},
submit(req, res, next) {
const uid = req.user.uid;
refundModel.submitRefundData(uid, req.body).then(result => {
res.json(result);
}).catch(next);
},
/**
* 退换货 - 商品寄回信息
* @param {*} req
* @param {*} res
* @param {*} next
*/
logistics(req, res) {
let headerData = headerModel.setNav({
navTitle: '退换货订单列表'
});
res.render('refund/logistics', {
module: 'home',
page: 'refund-logistics',
pageHeader: headerData,
applyid: req.query.applyid,
type: req.query.type,
localCss: true
});
},
/**
* 获取快递公司名称
* @param {*} req
* @param {*} res
* @param {*} next
*/
getCompanyList(req, res, next) {
refundModel.getExpressCompany().then(result => {
res.json(_.get(result, 'data', []));
}).catch(next);
},
saveLogistics(req, res, next) {
const uid = req.user.uid;
const applyid = req.body.applyid;
refundModel.setexpress(applyid, uid, {
type: req.body.type,
expressCompany: req.body.expressCompany,
expressNumber: req.body.expressNumber,
expressId: req.body.expressId
}).then(data => {
return res.json(data);
}).catch(next);
},
refundStatus(req, res) {
const applyId = req.params.applyId;
let headerData = headerModel.setNav({
navTitle: '退货状态',
backUrl: helpers.urlFormat('/home/return'),
navBtn: false
});
res.render('refund/status', {
module: 'home',
pageHeader: headerData,
page: 'refund-status',
applyId: applyId,
type: 'refund',
localCss: true
});
},
exchangeStatus(req, res) {
const applyId = req.params.applyId;
let headerData = headerModel.setNav({
navTitle: '换货状态',
backUrl: helpers.urlFormat('/home/return'),
navBtn: false
});
res.render('refund/status', {
module: 'home',
pageHeader: headerData,
page: 'refund-status',
applyId: applyId,
type: 'exchange',
localCss: true
});
},
statusDetail(req, res, next) {
const uid = req.user.uid;
const applyid = req.query.applyid;
const type = req.query.type;
if (type === 'refund') {
refundModel.getRefundDetail(applyid, uid).then(result => {
return res.json(result);
}).catch(next);
} else {
refundModel.getChangeDetail(applyid, uid).then(result => {
return res.json(result);
}).catch(next);
}
},
/**
* 退换货订单列表
* @param {*} req
* @param {*} res
*/
refundOrders(req, res) {
let headerData = headerModel.setNav({
navTitle: '退换货订单列表'
});
res.render('refund/refund-order', {
module: 'home',
page: 'refund-order',
pageHeader: headerData,
localCss: true
});
},
/**
* 获取退换货订单
* @param req
* @param res
* @returns {*|{read, write}}
*/
getRefundOrders(req, res, next) {
const uid = req.user.uid;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
let param = {
uid: uid,
page: req.query.page,
limit: req.query.limit
};
refundModel.getRefundOrders(param).then(result => {
return res.json(result);
}).catch(next);
},
/**
* 取消申请
* @param req
* @param res
*/
cancelApply(req, res, next) {
const uid = req.user.uid;
const id = req.body.id;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
refundModel.cancelRefundApply(uid, id).then(result => {
return res.json(result);
}).catch(next);
}
};
module.exports = refund;