...
|
...
|
@@ -10,7 +10,10 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
// 服务器报错页面
|
|
|
const _serverCrash = (res, params) => {
|
|
|
const _serverCrash = (res, params, err, next) => {
|
|
|
if (err && err.code === 401) {
|
|
|
return next(err);
|
|
|
}
|
|
|
params.title = params.title || '有货分期';
|
|
|
res.render('installment/server-crash', params);
|
|
|
};
|
...
|
...
|
@@ -27,7 +30,7 @@ const _banksInit = () => { |
|
|
};
|
|
|
|
|
|
// 还款列表公共处理块
|
|
|
const _repaymentList = (req, res, opt, params) => {
|
|
|
const _repaymentList = (req, res, next, opt, params) => {
|
|
|
params = _.assign({
|
|
|
uid: req.user.uid
|
|
|
}, params);
|
...
|
...
|
@@ -39,16 +42,16 @@ const _repaymentList = (req, res, opt, params) => { |
|
|
isInstallmentPage: true,
|
|
|
data: result
|
|
|
}, opt));
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: opt.title
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 开通分期首页
|
|
|
const index = (req, res) => {
|
|
|
const index = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
Promise.all([
|
...
|
...
|
@@ -136,15 +139,15 @@ const index = (req, res) => { |
|
|
isInstallmentPage: true,
|
|
|
title: '有货分期'
|
|
|
}, result));
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// ajax 请求分期专享商品
|
|
|
const getInstallmentGoods = (req, res) => {
|
|
|
const getInstallmentGoods = (req, res, next) => {
|
|
|
let allowOrigin = _.get(req, 'headers.origin', null) ?
|
|
|
req.headers.origin : req.protocol + '://' + req.headers.host;
|
|
|
|
...
|
...
|
@@ -162,15 +165,15 @@ const getInstallmentGoods = (req, res) => { |
|
|
} else {
|
|
|
res.json();
|
|
|
}
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 开通结果显示
|
|
|
const review = (req, res) => {
|
|
|
const review = (req, res, next) => {
|
|
|
let openStatus = req.query.status || false;
|
|
|
let uid = req.user.uid;
|
|
|
let data = {
|
...
|
...
|
@@ -214,10 +217,10 @@ const review = (req, res) => { |
|
|
})
|
|
|
}
|
|
|
}, data));
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
|
|
|
} else {
|
...
|
...
|
@@ -249,8 +252,8 @@ const review = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 逾期未还款列表
|
|
|
const overdueList = (req, res) => {
|
|
|
_repaymentList(req, res, {
|
|
|
const overdueList = (req, res, next) => {
|
|
|
_repaymentList(req, res, next, {
|
|
|
title: '逾期未还金额',
|
|
|
posId: 1
|
|
|
}, {
|
...
|
...
|
@@ -259,8 +262,8 @@ const overdueList = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 7日待还款列表
|
|
|
const sevenDayList = (req, res) => {
|
|
|
_repaymentList(req, res, {
|
|
|
const sevenDayList = (req, res, next) => {
|
|
|
_repaymentList(req, res, next, {
|
|
|
title: '近7日待还款',
|
|
|
posId: 2
|
|
|
}, {
|
...
|
...
|
@@ -269,8 +272,8 @@ const sevenDayList = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 本月待还款列表
|
|
|
const monthRepayList = (req, res) => {
|
|
|
_repaymentList(req, res, {
|
|
|
const monthRepayList = (req, res, next) => {
|
|
|
_repaymentList(req, res, next, {
|
|
|
title: '本月待还金额',
|
|
|
posId: 3
|
|
|
}, {
|
...
|
...
|
@@ -279,8 +282,8 @@ const monthRepayList = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 待还总金额列表
|
|
|
const totalRepayList = (req, res) => {
|
|
|
_repaymentList(req, res, {
|
|
|
const totalRepayList = (req, res, next) => {
|
|
|
_repaymentList(req, res, next, {
|
|
|
title: '待还总金额',
|
|
|
posId: 4
|
|
|
}, {
|
...
|
...
|
@@ -300,7 +303,7 @@ const repayRecordPage = (req, res) => { |
|
|
};
|
|
|
|
|
|
// ajax 请求还款记录
|
|
|
const getRepayRecord = (req, res) => {
|
|
|
const getRepayRecord = (req, res, next) => {
|
|
|
let params = _.assign({
|
|
|
uid: req.user.uid,
|
|
|
pageNo: req.query.page || 1
|
...
|
...
|
@@ -315,11 +318,11 @@ const getRepayRecord = (req, res) => { |
|
|
} else {
|
|
|
res.json();
|
|
|
}
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '还款记录'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -365,18 +368,18 @@ const bindCard = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 添加新银行卡请求
|
|
|
const postAccount = (req, res) => {
|
|
|
const postAccount = (req, res, next) => {
|
|
|
var params = _.assign({
|
|
|
uid: req.user.uid
|
|
|
}, req.query);
|
|
|
|
|
|
installmentModel.postAccount(params).then((result) => {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '使用新卡还款'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -407,7 +410,7 @@ function getRealIP(req) { |
|
|
return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress;
|
|
|
}
|
|
|
|
|
|
const activateService = (req, res) => {
|
|
|
const activateService = (req, res, next) => {
|
|
|
|
|
|
installmentModel.activateService({
|
|
|
uid: req.user.uid,
|
...
|
...
|
@@ -423,34 +426,34 @@ const activateService = (req, res) => { |
|
|
ip: getRealIP(req)
|
|
|
}).then((result)=> {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '开通有货分期'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const getBankInfo = (req, res) => {
|
|
|
const getBankInfo = (req, res, next) => {
|
|
|
installmentModel.getBankInfo({
|
|
|
cardNo: req.query.cardNo,
|
|
|
uid: req.user.uid
|
|
|
}).then((result)=> {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const verifyCode = (req, res) => {
|
|
|
const verifyCode = (req, res, next) => {
|
|
|
installmentModel.sendVerifyCode(req.user.uid || 1, req.query.mobile).then((result)=> {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -465,7 +468,7 @@ const orderIndex = (req, res) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const orderList = (req, res) => {
|
|
|
const orderList = (req, res, next) => {
|
|
|
const params = {
|
|
|
uid: req.user.uid,
|
|
|
type: req.query.type || 1,
|
...
|
...
|
@@ -493,15 +496,15 @@ const orderList = (req, res) => { |
|
|
layout: false,
|
|
|
isInstallmentPage: true
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '我的分期订单'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const orderDetail = (req, res) => {
|
|
|
const orderDetail = (req, res, next) => {
|
|
|
const params = {
|
|
|
uid: req.user.uid,
|
|
|
orderCode: req.params.id
|
...
|
...
|
@@ -586,16 +589,16 @@ const orderDetail = (req, res) => { |
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '分期详情'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 还款详情
|
|
|
const repayDetail = (req, res) => {
|
|
|
const repayDetail = (req, res, next) => {
|
|
|
let params = {
|
|
|
uid: req.user.uid,
|
|
|
rePayNo: req.query.id || '',
|
...
|
...
|
@@ -608,11 +611,11 @@ const repayDetail = (req, res) => { |
|
|
isInstallmentPage: true,
|
|
|
isOne: true
|
|
|
}, result[0]));
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '还款详情'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -631,24 +634,24 @@ const agreement = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 计算金额
|
|
|
const totalAmount = (req, res) => {
|
|
|
const totalAmount = (req, res, next) => {
|
|
|
installmentModel.totalAmount(req.query.prices).then((result) => {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 检查验证码
|
|
|
const checkVerifyCode = (req, res) => {
|
|
|
const checkVerifyCode = (req, res, next) => {
|
|
|
installmentModel.checkVerifyCode(req.user.uid, req.query.mobile, req.query.code).then((result) => {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -658,7 +661,7 @@ const serverCrash = (req, res) => { |
|
|
};
|
|
|
|
|
|
// 银行卡列表
|
|
|
const bankCard = (req, res) => {
|
|
|
const bankCard = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
installmentModel.getBankCards(uid).then((result) => {
|
...
|
...
|
@@ -668,18 +671,18 @@ const bankCard = (req, res) => { |
|
|
title: '我的银行卡',
|
|
|
isInstallmentPage: true,
|
|
|
accountList: result,
|
|
|
userName: result[0].userName
|
|
|
userName: _.get(result, '[0].userName')
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '我的银行卡'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 银行卡详情
|
|
|
const cardDetail = (req, res) => {
|
|
|
const cardDetail = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let cardIdNo = req.query.cardIdNo;
|
|
|
|
...
|
...
|
@@ -692,16 +695,16 @@ const cardDetail = (req, res) => { |
|
|
width750: true,
|
|
|
cardDetail: result
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '银行卡详情'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 删除绑定
|
|
|
const delBankCard = (req, res) => {
|
|
|
const delBankCard = (req, res, next) => {
|
|
|
let params = {
|
|
|
uid: req.user.uid,
|
|
|
cardIdNo: req.query.cardIdNo
|
...
|
...
|
@@ -709,16 +712,16 @@ const delBankCard = (req, res) => { |
|
|
|
|
|
installmentModel.delBankCard(params).then((result) => {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '银行卡详情'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 切换银行卡绑定
|
|
|
const setMasterCard = (req, res) => {
|
|
|
const setMasterCard = (req, res, next) => {
|
|
|
let params = {
|
|
|
uid: req.user.uid,
|
|
|
cardIdNo: req.query.cardIdNo
|
...
|
...
|
@@ -726,27 +729,15 @@ const setMasterCard = (req, res) => { |
|
|
|
|
|
installmentModel.setMasterCard(params).then((result) => {
|
|
|
res.json(result);
|
|
|
}).catch(() => {
|
|
|
}).catch((err) => {
|
|
|
_serverCrash(res, {
|
|
|
url: req.originalUrl,
|
|
|
title: '银行卡详情'
|
|
|
});
|
|
|
}, err, next);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const sessionKeyAuth = (req, res, next) => {
|
|
|
let uid = req.query.uid || req.cookies.installmentUid || (req.user.uid && req.user.uid.toString()) || '';
|
|
|
let sessionKey = _.get(req, 'user.uid.sessionKey');
|
|
|
|
|
|
if (sessionKey && !req.session.SESSION_KEY) {
|
|
|
req.session.SESSION_KEY = uid.sessionKey;
|
|
|
}
|
|
|
req.user.uid = {
|
|
|
toString: () => {
|
|
|
return uid.toString();
|
|
|
},
|
|
|
sessionKey
|
|
|
};
|
|
|
next();
|
|
|
};
|
|
|
|
...
|
...
|
|