installment.js
8.92 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
/**
* 分期付款
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/08/01
*/
'use strict';
const installmentModel = require('../models/installment');
const _ = require('lodash');
const helpers = global.yoho.helpers;
// 判断是否已经获取到了开通的状态值
const _reviewStatus = (uid, status) => {
if (status === '1') {
return {
review: {
url: helpers.urlFormat('/product/new')
}
};
} else if (status === '2') {
return Promise.all([installmentModel.getSearchIntallment(), installmentModel.getQueryCreditInfo(uid)]).then((result) => { //eslint-disable-line
return {
success: {
price: result[1].initCreditLimit,
installmentOnly: {
title: '分期专享',
goods: result[0]
}
}
};
});
} else if (status === '3') {
return {
error: {
url: helpers.urlFormat('/product/new')
}
};
}
};
// 还款列表公共处理块
const _repaymentList = (req, res, next, title, params) => {
params = _.assign({
uid: req.user.uid || 1
}, params);
installmentModel.getQueryAmtList(params).then((result) => {
res.render('installment/repayment-list', {
module: 'home',
page: 'repayment-list',
isInstallmentPage: true,
title: title,
data: result
});
}).catch(next);
};
// 开通分期首页
const index = (req, res, next) => {
let uid = req.user.uid || 512579468;
Promise.all([installmentModel.getStauts(uid), installmentModel.getSearchIntallment()]).then((result) => {
// status:0 未申请 1审核中 2已开通 3 审核未通过
let openStatus = result[0];
if (openStatus === '0') {
return installmentModel.getResources().then(data => {
return {
bannerTop: data,
notOpen: true,
installmentOnly: {
title: '分期专享',
goods: result[1]
}
};
});
} else if (openStatus === '2') {
return Promise.all([installmentModel.getQueryCreditInfo(uid), installmentModel.getQueryAmtInfo(uid)]).then((data) => { //eslint-disable-line
let params = _.assign({
isOverdue: false,
installmentOnly: {
title: '分期专享',
goods: result[1]
}
}, data[0], data[1]);
// status: 1 正常 2 逾期 3 不可用 4 未开通
if (data[0].status === '2') {
params.replayStatus = '逾期';
params.isOverdue = true;
} else if (data[0].status === '3') {
params.replayStatus = '不可用';
}
return params;
});
} else if (openStatus === 1) {
res.redirect('/home/installment/review?status=' + openStatus);
} else {
res.redirect('/home/installment/review?status=' + openStatus);
}
}).then((result) => {
// result.pageHeader = _.assign({
// installmentPage: true
// }, headerModel.setNav({
// navTitle: '有货分期',
// navBtn: false
// }));
res.render('installment/open-index', _.assign({
module: 'home',
page: 'installment',
isInstallmentPage: true,
title: '有货分期'
}, result));
}).catch(next);
};
// 开通结果显示
const review = (req, res, next) => {
let openStatus = req.query.status || false;
let uid = req.user.uid || 512579468;
let data = {
module: 'home',
page: 'installment',
title: '有货分期',
isInstallmentPage: true
};
if (openStatus) {
res.render('installment/open-result', _.assign(data, _reviewStatus(uid, +openStatus)));
} else {
installmentModel.getStauts(uid).then((status) => {
return _reviewStatus(uid, status);
}).then((params) => {
res.render('installment/open-result', _.assign(data, params));
}).catch(next);
}
};
// 逾期未还款列表
const overdueList = (req, res, next) => {
_repaymentList(req, res, next, '逾期未还金额', {
queryDays: -1
});
};
// 7日待还款列表
const sevenDayList = (req, res, next) => {
_repaymentList(req, res, next, '近7日待还款', {
queryDays: 7
});
};
// 本月待还款列表
const monthRepayList = (req, res, next) => {
_repaymentList(req, res, next, '本月待还金额', {
queryDays: 30
});
};
// 待还总金额列表
const totalRepayList = (req, res, next) => {
_repaymentList(req, res, next, '待还总金额', {
queryDays: 0
});
};
// 还款记录页面渲染
const repayRecordPage = (req, res) => {
res.render('installment/repay-record', {
module: 'home',
page: 'repay-record',
isInstallmentPage: true,
title: '还款记录'
});
};
// ajax 请求还款记录
const getRepayRecord = (req, res, next) => {
let params = _.assign({
uid: req.user.uid || 1,
pageNo: req.query.page || 1
});
installmentModel.getQueryRePayList(params).then((result) => {
if (result) {
res.render('installment/record-template', {
layout: false,
recordData: result
});
} else {
res.json();
}
}).catch(next);
};
// 账号管理
const account = (req, res, next) => {
let uid = req.user.uid || 0;
installmentModel.getBankCards(uid).then((result) => {
res.render('installment/account', {
accountList: result,
title: '账号管理',
isInstallmentPage: true,
repaymentList: result
});
}).catch(next);
};
const startingService = (req, res) => {
res.render('installment/starting-service', {
module: 'home',
page: 'installment.starting-service',
navTitle: '开通有货分期',
navBtn: false
});
};
const activateService = (req, res, next) => {
installmentModel.activateService({
uid: req.user.uid || 4,
userName: req.body.userName,
identityCardNo: req.body.identityCardNo,
cardNo: req.body.cardNo,
mobile: req.body.mobile,
snsCheckCode: req.body.snsCheckCode,
verifyId: req.body.verifyId
}).then((result)=> {
res.json(result);
}).catch(next);
};
const getBankInfo = (req, res, next) => {
installmentModel.getBankInfo({
cardNo: req.query.cardNo,
uid: req.user.uid || 512579468 // TODO: fix uid
}).then((result)=> {
res.json(result);
}).catch(next);
};
const verifyCode = (req, res, next) => {
installmentModel.sendVerifyCode(req.user.uid || 1, req.query.mobile).then((result)=> {
res.json(result);
}).catch(next);
};
const orderIndex = (req, res) => {
res.render('installment/order', {
module: 'home',
page: 'installment.order',
navTitle: '我的分期订单',
navBtn: false
});
};
const orderList = (req, res) => {
const params = {
uid: req.user.uid || 512579468, // TODO: fix me
type: req.query.type || 1,
page: req.query.page || 1,
limit: req.query.limit || 10
};
installmentModel.getInstallmentOrders(params).then((result)=> {
res.render('installment/order-list', {
orders: result.data.orderList,
layout: false
});
});
};
const orderDetail = (req, res) => {
const params = {
uid: req.user.id || 512579468, // TODO: fix me
orderCode: req.params.id
};
installmentModel.getInstallmentOrderDetail(params).then((result)=> {
res.render('installment/order-detail', {
module: 'home',
page: 'installment.order-detail',
navTitle: '分期详情',
order: result.data,
navBtn: false
});
});
};
// 还款详情
const repayDetail = (req, res, next) => {
let params = {
uid: req.user.id || 512579468,
rePayNo: req.query.id || '',
pageNo: 1
};
installmentModel.getQueryRePayList(params).then((result) => {
res.render('installment/repay-detail', _.assign({
title: '还款详情',
isInstallmentPage: true,
isOne: true
}, result[0]));
}).catch(next);
};
module.exports = {
index,
review,
overdueList,
sevenDayList,
monthRepayList,
totalRepayList,
repayRecordPage,
getRepayRecord,
startingService,
activateService,
verifyCode,
getBankInfo,
account,
orderIndex,
orderList,
orderDetail,
repayDetail
};