...
|
...
|
@@ -8,10 +8,12 @@ |
|
|
|
|
|
const mRoot = '../models';
|
|
|
const payModel = require(`${mRoot}/pay`);
|
|
|
const payTool = payModel.payTool;
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
const co = require('bluebird').coroutine;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const Payment = require('../helpers/payment');
|
|
|
const WxPay = require('../helpers/pay/wechat');
|
|
|
|
|
|
/**
|
|
|
* 支付中心
|
...
|
...
|
@@ -19,10 +21,12 @@ const Payment = require('../helpers/payment'); |
|
|
* @param res
|
|
|
* @param next
|
|
|
*/
|
|
|
const payCenter = (req, res, next) => {
|
|
|
const payCenter = (req, res) => {
|
|
|
let orderCode = req.query.order_code;
|
|
|
let uid = req.user.uid;
|
|
|
let sessionKey = req.session.TOKEN;
|
|
|
let userAgent = req.get('User-Agent');
|
|
|
let hasWxShare = Boolean(userAgent.match(/MicroMessenger/i) && userAgent.match(/MicroMessenger/i).length > 0);
|
|
|
|
|
|
if (!orderCode || !uid) {
|
|
|
res.redirect('/');
|
...
|
...
|
@@ -32,28 +36,51 @@ const payCenter = (req, res, next) => { |
|
|
sessionKey = sessionKey.substr(0, sessionKey.length - 8);
|
|
|
}
|
|
|
|
|
|
let headerData = headerModel.setNav({
|
|
|
navTitle: '支付中心'
|
|
|
co(function* () {
|
|
|
let orderDetail = yield payModel.payCenter({
|
|
|
orderCode: orderCode,
|
|
|
uid: uid
|
|
|
});
|
|
|
|
|
|
if (hasWxShare) {
|
|
|
let openId = req.session['weixinOpenId' + orderCode];
|
|
|
|
|
|
if (!openId) {
|
|
|
let getOpenidResult = yield WxPay.getOpenid(req.query.code, req.originalUrl);
|
|
|
|
|
|
if (getOpenidResult.openid) {
|
|
|
openId = getOpenidResult.openid;
|
|
|
}
|
|
|
|
|
|
if (getOpenidResult.redirectUrl) {
|
|
|
return res.redirect(getOpenidResult.redirectUrl);
|
|
|
}
|
|
|
|
|
|
if (openId) {
|
|
|
req.session['weixinOpenId' + orderCode] = openId;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let responseData = {
|
|
|
pageHeader: headerData,
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: '支付中心'
|
|
|
}),
|
|
|
module: 'cart',
|
|
|
page: 'pay',
|
|
|
title: '支付中心 | Yoho!Buy有货 | 潮流购物逛不停'
|
|
|
};
|
|
|
|
|
|
payModel.payCenter({
|
|
|
title: '支付中心 | Yoho!Buy有货 | 潮流购物逛不停',
|
|
|
payAppInfo: payTool.payAppInfo(orderCode),
|
|
|
orderCode: orderCode,
|
|
|
hasWxShare: hasWxShare,
|
|
|
orderTotal: orderDetail.payment_amount || 0,
|
|
|
orderTotalFormat: parseInt(orderDetail.payment_amount, 10),
|
|
|
orderCount: payTool.calBuyNumCount(orderDetail.order_goods),
|
|
|
uid: uid,
|
|
|
sessionKey: sessionKey
|
|
|
}).then(result => {
|
|
|
res.render('pay/pay-center', Object.assign(responseData, result, {
|
|
|
isOldUser: Boolean(req.cookies._isOldUser && req.cookies._isOldUser === '4'),
|
|
|
}));
|
|
|
}).catch(next);
|
|
|
|
|
|
isOldUser: Boolean(req.cookies._isOldUser && req.cookies._isOldUser === '4')
|
|
|
};
|
|
|
|
|
|
res.render('pay/pay-center', responseData);
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -72,7 +99,7 @@ const goAlipay = (req, res, next) => { |
|
|
res.redirect('/');
|
|
|
}
|
|
|
|
|
|
co(function*() {
|
|
|
co(function* () {
|
|
|
let orderDetail = yield payModel.getOtherDetail({
|
|
|
uid: uid,
|
|
|
orderCode: orderCode,
|
...
|
...
|
|