Authored by 郭成尧

pay-modified

... ... @@ -24,11 +24,13 @@ const payCenter = (req, res, next) => {
let uid = req.user.uid;
let sessionKey = req.session.TOKEN;
if (!orderCode || !uid || !sessionKey) {
if (!orderCode || !uid) {
res.redirect('/');
}
if (sessionKey) {
sessionKey = sessionKey.substr(0, sessionKey.length - 8);
}
let headerData = headerModel.setNav({
navTitle: '支付中心'
... ... @@ -59,12 +61,12 @@ const payCenter = (req, res, next) => {
* @param req
* @param res
*/
const goAlipay = (req, res) => {
const goAlipay = (req, res, next) => {
let orderCode = req.query.order_code;
let user = req.user;
let uid = req.user.uid;
let sessionKey = req.session.TOKEN;
let paymentType = req.query.payment_type;
let payment = req.query.payment;
if (!orderCode || !uid || !sessionKey) {
res.redirect('/');
... ... @@ -77,14 +79,14 @@ const goAlipay = (req, res) => {
sessionKey: sessionKey
});
if (!orderDetail) {
if (!orderDetail || !orderDetail.data) {
return res.json({
code: 400,
msg: '没有找到该订单!'
});
}
if (orderDetail.is_cancel === 'Y') {
if (orderDetail.data.is_cancel === 'Y') {
let url = helpers.urlFormat('/home/orders/detail', { order_code: orderCode });
return res.json({
... ... @@ -93,36 +95,13 @@ const goAlipay = (req, res) => {
}).redirect(url);
}
/* TODO 要不搞点儿日志? */
yield payModel.savePrePayInfo({
uid: uid,
orderCode: orderCode,
payment: paymentType
});
let payRequestPars = Payment.pay(user, orderDetail, paymentType, req.protocol);
if (!payRequestPars) {
return res.json({
code: 400,
msg: '支付系统繁忙,请稍后再试'
});
}
let paymentRecod = yield payModel.updateOrderPayment({
orderCode: orderCode,
payment: paymentType,
uid: uid
});
if (!paymentRecod) {
return res.json({
code: 400,
msg: '系统繁忙,请稍后再试'
});
Payment.pay(user, orderDetail.data, payment, req.protocol).then(result => {
if (result && result.data && result.data.href) {
res.redirect(result.data.href);
} else {
res.redirect('/');
}
return res.redirect(payRequestPars.pay_url + payRequestPars.pars);
}).catch(next);
})();
};
... ...
/**
* 支付成功页
* 支付
* @author: jing.li<jing.li@yoho.cn>
* @date: 2016/10/25
*/
... ... @@ -16,6 +16,13 @@ const _ = require('lodash');
const co = require('bluebird').coroutine;
const logger = global.yoho.logger;
// 支付方式
const payments = {
alipay: 33,
wechat: 36,
alibank: 42
};
// 资源位
const _getBanner = (param) => {
return serviceAPI.get('operations/api/v5/resource/get', {
... ... @@ -87,22 +94,6 @@ const _getOthersBuy = (param) => {
};
/**
* 选择支付,校验时间间隔,插入数据
* @returns {*|Promise.<TResult>}
* @private
*/
const savePrePayInfo = (params) => {
return api.get('', {
method: 'app.order.savePrePayInfo',
uid: params.uid,
orderCode: params.orderCode,
payment: params.payment
}, { code: 200 }).then(result => {
return result && result.data;
});
};
/**
* 获取订单支付银行信息
* @param id
*/
... ... @@ -260,10 +251,13 @@ const payTool = {
* 支持的支付方式列表
* @returns {[*,*]}
*/
payAppInfo() {
payAppInfo(orderCode) {
return [{
appIcon: '',
payLink: helpers.urlFormat('/shopping/pay/index'),
payLink: helpers.urlFormat('/cart/index/new/pay/goalipay', {
payment: payments.alipay + '_platform',
order_code: orderCode
}),
appId: 'alipay',
app: '支付宝支付',
hint: '支付宝钱包支付',
... ... @@ -310,7 +304,7 @@ const payCenter = (params) => {
let resultData = _.get(result, 'data', {});
return {
payAppInfo: payTool.payAppInfo(),
payAppInfo: payTool.payAppInfo(params.orderCode),
orderCode: params.orderCode,
hasWxShare: true,
orderTotal: resultData.payment_amount || 0,
... ... @@ -394,8 +388,8 @@ const getPayAli = (param) => {
};
module.exports = {
payments,
getOtherDetail: _getOtherDetail,
savePrePayInfo,
updateOrderPayment,
updateOrderPayBank,
getBankByOrder,
... ...