|
@@ -3,6 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
|
|
+const Transaction = require('mongoose-transactions');
|
|
|
|
|
|
//
|
|
//
|
|
class PayService extends CrudService {
|
|
class PayService extends CrudService {
|
|
@@ -14,6 +15,7 @@ class PayService extends CrudService {
|
|
this.dictDataModel = this.ctx.model.Dev.DictData;
|
|
this.dictDataModel = this.ctx.model.Dev.DictData;
|
|
this.payOrderReturnUrl = this.app.config.payReturn.order;
|
|
this.payOrderReturnUrl = this.app.config.payReturn.order;
|
|
this.wxDomain = _.get(this.app, 'config.httpPrefix.wechat');
|
|
this.wxDomain = _.get(this.app, 'config.httpPrefix.wechat');
|
|
|
|
+ this.tran = new Transaction();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -78,6 +80,16 @@ class PayService extends CrudService {
|
|
// 请求微信支付接口的数据
|
|
// 请求微信支付接口的数据
|
|
if (type === '0') {
|
|
if (type === '0') {
|
|
payData = this.getWxPayData(order_id, totalMoney, payObject.pay_no);
|
|
payData = this.getWxPayData(order_id, totalMoney, payObject.pay_no);
|
|
|
|
+ payObject.openid = payData.openid;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ this.tran.update('Order', order_id, { pay: payObject });
|
|
|
|
+ await this.tran.run();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await this.tran.rollback();
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
+ if (type === '0') {
|
|
res = await this.create(payData);
|
|
res = await this.create(payData);
|
|
res = this.preparToUniAppWxPay(res);
|
|
res = this.preparToUniAppWxPay(res);
|
|
}
|
|
}
|
|
@@ -96,10 +108,9 @@ class PayService extends CrudService {
|
|
console.error('没有支付订单号');
|
|
console.error('没有支付订单号');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- const arr = out_trade_no.split('-');
|
|
|
|
- const noPart = _.last(arr);
|
|
|
|
const openid = _.get(payer, 'openid');
|
|
const openid = _.get(payer, 'openid');
|
|
- let orderData = await this.orderModel.findOne({ no: new RegExp(`${noPart}`), 'pay.openid': openid });
|
|
|
|
|
|
+ console.log({ 'pay.pay_no': new RegExp(`${out_trade_no}`), 'pay.openid': openid });
|
|
|
|
+ let orderData = await this.orderModel.findOne({ 'pay.pay_no': new RegExp(`${out_trade_no}`), 'pay.openid': openid });
|
|
// TODO: 没找到订单也是有问题的,需要报警
|
|
// TODO: 没找到订单也是有问题的,需要报警
|
|
if (!orderData) {
|
|
if (!orderData) {
|
|
console.error('没有找到订单');
|
|
console.error('没有找到订单');
|