|
@@ -16,6 +16,7 @@ class PayService extends CrudService {
|
|
|
this.payOrderReturnUrl = this.app.config.payReturn.order;
|
|
|
this.wxDomain = _.get(this.app, 'config.httpPrefix.wechat');
|
|
|
this.tran = new Transaction();
|
|
|
+ this.joinErrorRefundCode = _.get(this.app, 'config.errcode.groupJoinRefund');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -137,6 +138,16 @@ class PayService extends CrudService {
|
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
|
await this.tran.rollback();
|
|
|
+ let reason = '服务处理发生错误,原路退款!';
|
|
|
+ if (error.errcode === this.joinErrorRefundCode) {
|
|
|
+ reason = '您未能成功参与拼团:拼团人数已满';
|
|
|
+ // 需要删除订单
|
|
|
+ await this.ctx.service.trade.order.cancel({ order_id: _.get(orderData, '_id') });
|
|
|
+ }
|
|
|
+ // 先退款,所有回调发生错误的单子都需要退掉
|
|
|
+ const str = this.ctx.service.util.trade.createNonceStr();
|
|
|
+ const obj = { order_no: _.get(orderData, 'pay.pay_no'), out_trade_no: `${_.get(orderData, 'pay.pay_no')}-service_error-${str}`, money: _.get(orderData, 'pay.pay_money'), reason };
|
|
|
+ await this.refund(obj);
|
|
|
throw new BusinessError(ErrorCode.SERVICE_FAULT, '支付回调:修改失败');
|
|
|
} finally {
|
|
|
// 清空事务
|