...
|
...
|
@@ -9,10 +9,7 @@ |
|
|
const headerModel = require('../../../doraemon/models/simple-header');
|
|
|
const PayData = require('../models/pay');
|
|
|
const PayHelpers = require('../helpers/payment');
|
|
|
const paySign = require('../helpers/pay/sign');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const _ = require('lodash');
|
|
|
const md5 = require('md5');
|
|
|
const integerTest = /^\d+$/;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -32,8 +29,6 @@ const online = (req, res, next) => { |
|
|
|
|
|
PayData.getPayInfo(uid, orderCode).then(result => {
|
|
|
let order = result.order;
|
|
|
let promotion = order.promotion_formulas;
|
|
|
let coin = 0;
|
|
|
let amount = _.toNumber(order.payment_amount);
|
|
|
let header = headerModel.setSimpleHeaderData() || {};
|
|
|
|
...
|
...
|
@@ -42,7 +37,7 @@ const online = (req, res, next) => { |
|
|
return next();
|
|
|
}
|
|
|
|
|
|
result.order.payment_name = (result.order.payment_type === 1 ? '在线支付' : '货到付款');
|
|
|
result.order.payment_name = (parseInt(result.order.payment_type, 10) === 1 ? '在线支付' : '货到付款');
|
|
|
|
|
|
if (amount > 0) {
|
|
|
res.render('pay', Object.assign({
|
...
|
...
|
@@ -53,21 +48,9 @@ const online = (req, res, next) => { |
|
|
username: decodeURIComponent(req.user.name) || ''
|
|
|
}, result));
|
|
|
} else {
|
|
|
_.forEach(promotion, p => {
|
|
|
if (p.promotion === 'YOHO币') {
|
|
|
coin = parseInt(parseFloat(p.payment_amount.substring(2, p.payment_amount.length)) * 100, 10);
|
|
|
}
|
|
|
});
|
|
|
res.render('pay-success', {
|
|
|
content: {
|
|
|
amount: order.payment_amount,
|
|
|
orderNum: order.order_code,
|
|
|
coin: coin,
|
|
|
orderHref: helpers.urlFormat('/me/order/detail', {
|
|
|
orderCode: order.order_code
|
|
|
}),
|
|
|
walkHref: helpers.urlFormat('/')
|
|
|
}
|
|
|
simpleHeader: header,
|
|
|
order: order
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -123,23 +106,16 @@ const weixinQr = (req, res, next) => { |
|
|
return next();
|
|
|
}
|
|
|
|
|
|
PayData.orderDetail(uid, code).then(result => {
|
|
|
if (result && result.data) {
|
|
|
return result.data;
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
}).then(order => {
|
|
|
PayData.orderDetail(uid, code).then(d => {
|
|
|
d = d && d.data || {};
|
|
|
res.render('weixin-pay', {
|
|
|
module: 'shopping',
|
|
|
page: 'wxpay',
|
|
|
title: '微信扫码支付页面',
|
|
|
simpleHeader: header,
|
|
|
choosePayUrl: helpers.urlFormat('/shopping/pay', {
|
|
|
order_code: order.order_code
|
|
|
}),
|
|
|
choosePayUrl: `//www.yohobuy.com/shopping/pay?ordercode=${d.order_code}`,
|
|
|
qrcodeUrl: qrcodeUrl,
|
|
|
order: order
|
|
|
order: d
|
|
|
});
|
|
|
}).catch(next);
|
|
|
};
|
...
|
...
|
@@ -155,32 +131,8 @@ const weixinPayState = (req, res) => { |
|
|
});
|
|
|
}
|
|
|
|
|
|
PayData.orderDetail(uid, code).then(result => {
|
|
|
let data = {};
|
|
|
|
|
|
result = result && result.data || {};
|
|
|
if (result.is_cancel === 'Y') {
|
|
|
data = {
|
|
|
code: 401,
|
|
|
message: '订单已取消'
|
|
|
};
|
|
|
} else if (result.payment_status === 'Y') {
|
|
|
let payParams = {
|
|
|
orderCode: code,
|
|
|
totalFee: _.round(parseFloat(result.payment_amount), 2)
|
|
|
};
|
|
|
|
|
|
data = {
|
|
|
code: 200,
|
|
|
data: {
|
|
|
href: helpers.urlFormat('/shopping/pay/callback/wechat', Object.assign(payParams, {
|
|
|
sign: md5(paySign.raw(Object.assign({tradeStatus: 'Y'}, payParams)))
|
|
|
}))
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return res.json(data);
|
|
|
PayHelpers.getWxSign(uid, code).then(d => {
|
|
|
return res.json(d);
|
|
|
}).catch(() => {
|
|
|
return res.json({});
|
|
|
});
|
...
|
...
|
@@ -195,6 +147,7 @@ const callback = (req, res, next) => { |
|
|
let type = req.params.type;
|
|
|
let payId = PayData.payments[type];
|
|
|
let query = req.query;
|
|
|
let header = headerModel.setSimpleHeaderData() || {};
|
|
|
|
|
|
if (!payId) {
|
|
|
return next();
|
...
|
...
|
@@ -202,35 +155,14 @@ const callback = (req, res, next) => { |
|
|
|
|
|
PayHelpers.afterPay(query, payId, req.user).then(result => {
|
|
|
if (result.code === 200 && result.data && result.data.order) {
|
|
|
let order = result.data.order;
|
|
|
let promotion = order.promotion_formulas;
|
|
|
let coin = 0;
|
|
|
|
|
|
|
|
|
_.forEach(promotion, p => {
|
|
|
if (p.promotion === 'YOHO币') {
|
|
|
coin = parseInt(parseFloat(p.promotion_amount.substring(2, p.promotion_amount.length)) * 100, 10);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
res.render('pay-success', {
|
|
|
defaultHeader: false,
|
|
|
bcNavFocus: 3,
|
|
|
content: {
|
|
|
cost: order.payment_amount,
|
|
|
orderNum: order.order_code,
|
|
|
coin: coin,
|
|
|
orderHref: helpers.urlFormat('/me/order/detail', {
|
|
|
orderCode: order.order_code
|
|
|
}),
|
|
|
walkHref: helpers.urlFormat('/')
|
|
|
}
|
|
|
simpleHeader: header,
|
|
|
order: result.data.order
|
|
|
});
|
|
|
} else {
|
|
|
res.render('pay-fail', {
|
|
|
defaultHeader: false,
|
|
|
payName: result.payName,
|
|
|
bcNavFocus: 3
|
|
|
simpleHeader: header,
|
|
|
payName: result.payName
|
|
|
});
|
|
|
}
|
|
|
}).catch(next);
|
...
|
...
|
|