Authored by 郭成尧

pay-controller-ctx

... ... @@ -3,14 +3,15 @@
* @Author: Targaryen
* @Date: 2017-01-04 15:17:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-09-12 14:51:58
*/
'use strict';
const mRoot = '../models';
const payModel = require(`${mRoot}/pay`);
const payTool = payModel.payTool;
const utils = '../../../utils';
const payProcess = require(`${utils}/pay-process`);
const payTool = payProcess.payTool;
const headerModel = require('../../../doraemon/models/header'); // 头部model
const aboutModel = require('../../../doraemon/models/about');
const co = require('bluebird').coroutine;
... ... @@ -45,7 +46,7 @@ const payCenter = (req, res, next) => {
}
co(function* () {
let orderDetail = yield payModel.payCenter({
let orderDetail = yield req.ctx(payModel).payCenter({
orderCode: orderCode,
uid: uid,
sessionKey: sessionKey
... ... @@ -130,7 +131,7 @@ const pay = (req, res, next) => {
}
co(function* () {
let orderDetail = yield payModel.getOtherDetail({
let orderDetail = yield req.ctx(payModel).getOtherDetail({
uid: uid,
orderCode: orderCode,
sessionKey: sessionKey
... ... @@ -153,18 +154,18 @@ const pay = (req, res, next) => {
});
}
Payment.pay(user, orderDetail.data, payment, {
req.ctx(Payment).pay(user, orderDetail.data, payment, {
protocol: req.protocol,
openId: openId,
ip: ip
}).then(result => {
if (result && paymentCode === payModel.payments.wechat) {
if (result && paymentCode === payProcess.PAYMENTS.WECHAT) {
if (result.code !== 200) {
res.clearCookie('weixinOpenId' + orderCode);
}
return res.json(result);
}
if (result && result.data && result.data.href && paymentCode === payModel.payments.alipay) {
if (result && result.data && result.data.href && paymentCode === payProcess.PAYMENTS.ALIPAY) {
return res.json({
code: 200,
message: '校验成功',
... ... @@ -212,7 +213,7 @@ const payCod = (req, res, next) => {
return;
}
payModel.getPayCod(param).then(result => {
req.ctx(payModel).getPayCod(param).then(result => {
if (result.match === true) {
req.ctx(aboutModel).about(req.yoho.isApp).then(resu => {
res.render('pay/pay-cod', Object.assign(responseData, result, {wxFooter: resu}));
... ... @@ -258,14 +259,14 @@ const payAli = (req, res, next) => {
return;
}
let verifyResult = payModel.alipayResultVerify(req.query);
let verifyResult = req.ctx(payModel).alipayResultVerify(req.query);
// 支付宝支付校验
if (!verifyResult.payResult) {
return res.render('pay/pay-failure', responseFailure);
}
payModel.getPayAli(param).then(result => {
req.ctx(payModel).getPayAli(param).then(result => {
if (result.match === true) {
req.ctx(aboutModel).about(req.yoho.isApp).then(resu => {
res.render('pay/pay-ali', Object.assign(responseData, result, {wxFooter: resu}));
... ... @@ -312,7 +313,7 @@ const payZero = (req, res, next) => {
return;
}
payModel.getPayAli(param).then(result => {
req.ctx(payModel).getPayAli(param).then(result => {
if (result.match === true) {
if (result.isCancel && result.isCancel === true) {
... ...