修改了deposit的退款逻辑,未测试

This commit is contained in:
Xu Chang 2024-09-29 16:57:27 +08:00
parent 1d891ac353
commit 51d0b797a5
14 changed files with 81 additions and 20 deletions

View File

@ -798,7 +798,9 @@ const i18ns = [
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -19,7 +19,9 @@
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -2,6 +2,7 @@ import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { getAccountEntity, getPayClazz } from '../utils/payClazz';
import assert from 'assert';
import { updateWithdrawState } from './withdraw';
import { RefundExceedMax, PayUnRefundable } from '../types/Exception';
/**
* 开始退款的逻辑
* @param context
@ -15,6 +16,9 @@ async function startRefunding(context, data) {
paid: 1,
refunded: 1,
iState: 1,
entity: 1,
entityId: 1,
refundable: 1,
deposit: {
id: 1,
accountId: 1,
@ -29,10 +33,15 @@ async function startRefunding(context, data) {
}
}, { dontCollect: true });
const { paid, refunded, deposit, order } = pay;
assert(paid - refunded >= data.price);
if (paid - refunded < data.price) {
throw new RefundExceedMax();
}
if (!pay.refundable) {
throw new PayUnRefundable();
}
if (deposit) {
// 是提现其Account相应的计算在withdraw进行
assert(data.withdrawId);
// 充值不可能从account渠道支付
assert(pay.entity !== 'account');
}
else {
assert(order);

View File

@ -16,6 +16,9 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
export declare class RefundExceedMax<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string);
}
export declare class PayUnRefundable<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string);
}
export declare class StartPayFailure<ED extends EntityDict> extends OakException<ED> {
constructor(message: string);
}

View File

@ -16,7 +16,12 @@ export class ExternalPayUtilException extends OakException {
}
export class RefundExceedMax extends OakException {
constructor(message) {
super(message || '可退款的总额不足');
super(message || 'error::refund.create.exceedMax');
}
}
export class PayUnRefundable extends OakException {
constructor(message) {
super(message || 'error::refund.create.payUnrefundable');
}
}
export class StartPayFailure extends OakException {

View File

@ -800,7 +800,9 @@ const i18ns = [
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -19,7 +19,9 @@
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -5,6 +5,7 @@ const uuid_1 = require("oak-domain/lib/utils/uuid");
const payClazz_1 = require("../utils/payClazz");
const assert_1 = tslib_1.__importDefault(require("assert"));
const withdraw_1 = require("./withdraw");
const Exception_1 = require("../types/Exception");
/**
* 开始退款的逻辑
* @param context
@ -18,6 +19,9 @@ async function startRefunding(context, data) {
paid: 1,
refunded: 1,
iState: 1,
entity: 1,
entityId: 1,
refundable: 1,
deposit: {
id: 1,
accountId: 1,
@ -32,10 +36,15 @@ async function startRefunding(context, data) {
}
}, { dontCollect: true });
const { paid, refunded, deposit, order } = pay;
(0, assert_1.default)(paid - refunded >= data.price);
if (paid - refunded < data.price) {
throw new Exception_1.RefundExceedMax();
}
if (!pay.refundable) {
throw new Exception_1.PayUnRefundable();
}
if (deposit) {
// 是提现其Account相应的计算在withdraw进行
(0, assert_1.default)(data.withdrawId);
// 充值不可能从account渠道支付
(0, assert_1.default)(pay.entity !== 'account');
}
else {
(0, assert_1.default)(order);

View File

@ -16,6 +16,9 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
export declare class RefundExceedMax<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string);
}
export declare class PayUnRefundable<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string);
}
export declare class StartPayFailure<ED extends EntityDict> extends OakException<ED> {
constructor(message: string);
}

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeException = exports.StartPayFailure = exports.RefundExceedMax = exports.ExternalPayUtilException = void 0;
exports.makeException = exports.StartPayFailure = exports.PayUnRefundable = exports.RefundExceedMax = exports.ExternalPayUtilException = void 0;
const tslib_1 = require("tslib");
const types_1 = require("oak-domain/lib/types");
const DependentExceptions_1 = tslib_1.__importDefault(require("./DependentExceptions"));
@ -21,10 +21,16 @@ class ExternalPayUtilException extends types_1.OakException {
exports.ExternalPayUtilException = ExternalPayUtilException;
class RefundExceedMax extends types_1.OakException {
constructor(message) {
super(message || '可退款的总额不足');
super(message || 'error::refund.create.exceedMax');
}
}
exports.RefundExceedMax = RefundExceedMax;
class PayUnRefundable extends types_1.OakException {
constructor(message) {
super(message || 'error::refund.create.payUnrefundable');
}
}
exports.PayUnRefundable = PayUnRefundable;
class StartPayFailure extends types_1.OakException {
constructor(message) {
super(message);

View File

@ -800,7 +800,9 @@ const i18ns: I18n[] = [
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -19,7 +19,9 @@
},
"refund": {
"create": {
"hasAnotherRefunding": "您有一笔退款正在进行中"
"hasAnotherRefunding": "您有一笔退款正在进行中",
"exceedMax": "退款额度大于可用值",
"payUnrefundable": "支付已经不可退款"
}
}
}

View File

@ -6,7 +6,7 @@ import { BRC } from '../types/RuntimeCxt';
import { getAccountEntity, getPayClazz } from '../utils/payClazz';
import assert from 'assert';
import { updateWithdrawState } from './withdraw';
import { RefundExceedMax, PayUnRefundable } from '@project/types/Exception';
/**
* 退
* @param context
@ -21,6 +21,9 @@ async function startRefunding(context: BRC, data: EntityDict['refund']['CreateSi
paid: 1,
refunded: 1,
iState: 1,
entity: 1,
entityId: 1,
refundable: 1,
deposit: {
id: 1,
accountId: 1,
@ -36,10 +39,15 @@ async function startRefunding(context: BRC, data: EntityDict['refund']['CreateSi
}, { dontCollect: true });
const { paid, refunded, deposit, order } = pay;
assert(paid! - refunded! >= data.price!);
if (paid! - refunded! < data.price!) {
throw new RefundExceedMax();
}
if (!pay.refundable) {
throw new PayUnRefundable();
}
if (deposit) {
// 是提现其Account相应的计算在withdraw进行
assert(data.withdrawId!);
// 充值不可能从account渠道支付
assert (pay.entity !== 'account');
}
else {
assert(order);

View File

@ -20,7 +20,13 @@ export class ExternalPayUtilException<ED extends EntityDict> extends OakExceptio
export class RefundExceedMax<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string) {
super(message || '可退款的总额不足');
super(message || 'error::refund.create.exceedMax');
}
}
export class PayUnRefundable<ED extends EntityDict> extends OakException<ED> {
constructor(message?: string) {
super(message || 'error::refund.create.payUnrefundable');
}
}