Authored by 郭成尧

pay-controller-ctx

@@ -3,14 +3,15 @@ @@ -3,14 +3,15 @@
3 * @Author: Targaryen 3 * @Author: Targaryen
4 * @Date: 2017-01-04 15:17:51 4 * @Date: 2017-01-04 15:17:51
5 * @Last Modified by: Targaryen 5 * @Last Modified by: Targaryen
6 - * @Last Modified time: 2017-09-12 14:51:58  
7 */ 6 */
8 7
9 'use strict'; 8 'use strict';
10 9
11 const mRoot = '../models'; 10 const mRoot = '../models';
12 const payModel = require(`${mRoot}/pay`); 11 const payModel = require(`${mRoot}/pay`);
13 -const payTool = payModel.payTool; 12 +const utils = '../../../utils';
  13 +const payProcess = require(`${utils}/pay-process`);
  14 +const payTool = payProcess.payTool;
14 const headerModel = require('../../../doraemon/models/header'); // 头部model 15 const headerModel = require('../../../doraemon/models/header'); // 头部model
15 const aboutModel = require('../../../doraemon/models/about'); 16 const aboutModel = require('../../../doraemon/models/about');
16 const co = require('bluebird').coroutine; 17 const co = require('bluebird').coroutine;
@@ -45,7 +46,7 @@ const payCenter = (req, res, next) => { @@ -45,7 +46,7 @@ const payCenter = (req, res, next) => {
45 } 46 }
46 47
47 co(function* () { 48 co(function* () {
48 - let orderDetail = yield payModel.payCenter({ 49 + let orderDetail = yield req.ctx(payModel).payCenter({
49 orderCode: orderCode, 50 orderCode: orderCode,
50 uid: uid, 51 uid: uid,
51 sessionKey: sessionKey 52 sessionKey: sessionKey
@@ -130,7 +131,7 @@ const pay = (req, res, next) => { @@ -130,7 +131,7 @@ const pay = (req, res, next) => {
130 } 131 }
131 132
132 co(function* () { 133 co(function* () {
133 - let orderDetail = yield payModel.getOtherDetail({ 134 + let orderDetail = yield req.ctx(payModel).getOtherDetail({
134 uid: uid, 135 uid: uid,
135 orderCode: orderCode, 136 orderCode: orderCode,
136 sessionKey: sessionKey 137 sessionKey: sessionKey
@@ -153,18 +154,18 @@ const pay = (req, res, next) => { @@ -153,18 +154,18 @@ const pay = (req, res, next) => {
153 }); 154 });
154 } 155 }
155 156
156 - Payment.pay(user, orderDetail.data, payment, { 157 + req.ctx(Payment).pay(user, orderDetail.data, payment, {
157 protocol: req.protocol, 158 protocol: req.protocol,
158 openId: openId, 159 openId: openId,
159 ip: ip 160 ip: ip
160 }).then(result => { 161 }).then(result => {
161 - if (result && paymentCode === payModel.payments.wechat) { 162 + if (result && paymentCode === payProcess.PAYMENTS.WECHAT) {
162 if (result.code !== 200) { 163 if (result.code !== 200) {
163 res.clearCookie('weixinOpenId' + orderCode); 164 res.clearCookie('weixinOpenId' + orderCode);
164 } 165 }
165 return res.json(result); 166 return res.json(result);
166 } 167 }
167 - if (result && result.data && result.data.href && paymentCode === payModel.payments.alipay) { 168 + if (result && result.data && result.data.href && paymentCode === payProcess.PAYMENTS.ALIPAY) {
168 return res.json({ 169 return res.json({
169 code: 200, 170 code: 200,
170 message: '校验成功', 171 message: '校验成功',
@@ -212,7 +213,7 @@ const payCod = (req, res, next) => { @@ -212,7 +213,7 @@ const payCod = (req, res, next) => {
212 return; 213 return;
213 } 214 }
214 215
215 - payModel.getPayCod(param).then(result => { 216 + req.ctx(payModel).getPayCod(param).then(result => {
216 if (result.match === true) { 217 if (result.match === true) {
217 req.ctx(aboutModel).about(req.yoho.isApp).then(resu => { 218 req.ctx(aboutModel).about(req.yoho.isApp).then(resu => {
218 res.render('pay/pay-cod', Object.assign(responseData, result, {wxFooter: resu})); 219 res.render('pay/pay-cod', Object.assign(responseData, result, {wxFooter: resu}));
@@ -258,14 +259,14 @@ const payAli = (req, res, next) => { @@ -258,14 +259,14 @@ const payAli = (req, res, next) => {
258 return; 259 return;
259 } 260 }
260 261
261 - let verifyResult = payModel.alipayResultVerify(req.query); 262 + let verifyResult = req.ctx(payModel).alipayResultVerify(req.query);
262 263
263 // 支付宝支付校验 264 // 支付宝支付校验
264 if (!verifyResult.payResult) { 265 if (!verifyResult.payResult) {
265 return res.render('pay/pay-failure', responseFailure); 266 return res.render('pay/pay-failure', responseFailure);
266 } 267 }
267 268
268 - payModel.getPayAli(param).then(result => { 269 + req.ctx(payModel).getPayAli(param).then(result => {
269 if (result.match === true) { 270 if (result.match === true) {
270 req.ctx(aboutModel).about(req.yoho.isApp).then(resu => { 271 req.ctx(aboutModel).about(req.yoho.isApp).then(resu => {
271 res.render('pay/pay-ali', Object.assign(responseData, result, {wxFooter: resu})); 272 res.render('pay/pay-ali', Object.assign(responseData, result, {wxFooter: resu}));
@@ -312,7 +313,7 @@ const payZero = (req, res, next) => { @@ -312,7 +313,7 @@ const payZero = (req, res, next) => {
312 return; 313 return;
313 } 314 }
314 315
315 - payModel.getPayAli(param).then(result => { 316 + req.ctx(payModel).getPayAli(param).then(result => {
316 317
317 if (result.match === true) { 318 if (result.match === true) {
318 if (result.isCancel && result.isCancel === true) { 319 if (result.isCancel && result.isCancel === true) {