accountOper type为consume时允许totalPlus为0;修改changeOrderStateByPay方法以支持仅存在一个account的pay且price为0的order支付与退款
This commit is contained in:
parent
b03830ce1a
commit
e5248a39b4
|
|
@ -27,7 +27,7 @@ const checkers = [
|
|||
}
|
||||
switch (type) {
|
||||
case 'consume': {
|
||||
if (totalPlus >= 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
if (totalPlus > 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为consume时,其totalPlus/availPlus必须为0或负数,且totalPlus的绝对值要更大');
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,13 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
paid: 1,
|
||||
refunded: 1,
|
||||
iState: 1,
|
||||
entity: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: {
|
||||
$ne: 'closed',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
filter,
|
||||
|
|
@ -71,7 +77,7 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}
|
||||
}
|
||||
else if (hasRefunding) {
|
||||
assert(!hasPaying && payPaid === orderPrice && payRefunded < orderPrice);
|
||||
assert(!hasPaying && payPaid === orderPrice && payRefunded <= orderPrice);
|
||||
if (orderIState !== 'refunding' || orderRefunded !== payRefunded) {
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
|
|
@ -85,9 +91,9 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payRefunded) {
|
||||
else if (payRefunded > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'refunded')) {
|
||||
// 已经在退款流程当中
|
||||
assert(payPaid === orderPrice && payPaid === orderPaid);
|
||||
assert(payPaid === orderPrice);
|
||||
const iState = payPaid === orderPrice ? 'refunded' : 'partiallyRefunded';
|
||||
if (orderIState !== iState || orderRefunded !== payRefunded) {
|
||||
const action = payRefunded === orderPrice ? 'refundAll' : 'refundPartially';
|
||||
|
|
@ -103,9 +109,9 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payPaid) {
|
||||
else if (payPaid > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'paid')) {
|
||||
// 在支付流程当中
|
||||
//存在已完成的pay更新order的paid和iState
|
||||
// 存在已完成的pay更新order的paid和iState
|
||||
assert(orderRefunded === 0);
|
||||
const iState = payPaid === orderPrice ? 'paid' : 'partiallyPaid';
|
||||
if (orderIState !== iState || orderPaid !== payPaid) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ const checkers = [
|
|||
}
|
||||
switch (type) {
|
||||
case 'consume': {
|
||||
if (totalPlus >= 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
if (totalPlus > 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为consume时,其totalPlus/availPlus必须为0或负数,且totalPlus的绝对值要更大');
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,13 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
paid: 1,
|
||||
refunded: 1,
|
||||
iState: 1,
|
||||
entity: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: {
|
||||
$ne: 'closed',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
filter,
|
||||
|
|
@ -74,7 +80,7 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}
|
||||
}
|
||||
else if (hasRefunding) {
|
||||
(0, assert_1.default)(!hasPaying && payPaid === orderPrice && payRefunded < orderPrice);
|
||||
(0, assert_1.default)(!hasPaying && payPaid === orderPrice && payRefunded <= orderPrice);
|
||||
if (orderIState !== 'refunding' || orderRefunded !== payRefunded) {
|
||||
await context.operate('order', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
|
|
@ -88,9 +94,9 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payRefunded) {
|
||||
else if (payRefunded > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'refunded')) {
|
||||
// 已经在退款流程当中
|
||||
(0, assert_1.default)(payPaid === orderPrice && payPaid === orderPaid);
|
||||
(0, assert_1.default)(payPaid === orderPrice);
|
||||
const iState = payPaid === orderPrice ? 'refunded' : 'partiallyRefunded';
|
||||
if (orderIState !== iState || orderRefunded !== payRefunded) {
|
||||
const action = payRefunded === orderPrice ? 'refundAll' : 'refundPartially';
|
||||
|
|
@ -106,9 +112,9 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payPaid) {
|
||||
else if (payPaid > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'paid')) {
|
||||
// 在支付流程当中
|
||||
//存在已完成的pay更新order的paid和iState
|
||||
// 存在已完成的pay更新order的paid和iState
|
||||
(0, assert_1.default)(orderRefunded === 0);
|
||||
const iState = payPaid === orderPrice ? 'paid' : 'partiallyPaid';
|
||||
if (orderIState !== iState || orderPaid !== payPaid) {
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ const checkers: Checker<EntityDict, 'accountOper', RuntimeCxt>[] = [
|
|||
}
|
||||
switch (type) {
|
||||
case 'consume': {
|
||||
if (totalPlus >= 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
if (totalPlus > 0 || availPlus > 0 || totalPlus > availPlus) {
|
||||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为consume时,其totalPlus/availPlus必须为0或负数,且totalPlus的绝对值要更大');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'deposit': {
|
||||
if (totalPlus < 0 || availPlus < 0 || totalPlus !== availPlus ||
|
||||
if (totalPlus < 0 || availPlus < 0 || totalPlus !== availPlus ||
|
||||
typeof refundablePlus === 'number' && refundablePlus < 0) {
|
||||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为deposit时,其totalPlus/availPlus必须为正数且相等, refundable必须为空或者正数');
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ const checkers: Checker<EntityDict, 'accountOper', RuntimeCxt>[] = [
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'earn' : {
|
||||
case 'earn': {
|
||||
if (totalPlus <= 0 || availPlus < 0) {
|
||||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为earn时,其totalPlus必须为正数、availPlus必须为非负数');
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ const checkers: Checker<EntityDict, 'accountOper', RuntimeCxt>[] = [
|
|||
break;
|
||||
}
|
||||
case 'cutoffRefundable': {
|
||||
if (totalPlus !==0 || availPlus !== 0 || typeof refundablePlus !== 'number' || refundablePlus >= 0) {
|
||||
if (totalPlus !== 0 || availPlus !== 0 || typeof refundablePlus !== 'number' || refundablePlus >= 0) {
|
||||
throw new OakInputIllegalException('accountOper', ['refundablePlus'], 'accountOper为cutoffRefundable时,其totalPlus/availPlus必须为0,且refundablePlus必须为负数');
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,13 @@ async function changeOrderStateByPay(
|
|||
paid: 1,
|
||||
refunded: 1,
|
||||
iState: 1,
|
||||
entity: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: {
|
||||
$ne: 'closed',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
filter,
|
||||
|
|
@ -98,9 +104,9 @@ async function changeOrderStateByPay(
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payRefunded >= 0) {
|
||||
else if (payRefunded > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'refunded')) {
|
||||
// 已经在退款流程当中
|
||||
assert(payPaid === orderPrice && payPaid === orderPaid);
|
||||
assert(payPaid === orderPrice);
|
||||
const iState = payPaid === orderPrice ? 'refunded' : 'partiallyRefunded';
|
||||
if (orderIState !== iState || orderRefunded !== payRefunded) {
|
||||
const action = payRefunded === orderPrice ? 'refundAll' : 'refundPartially';
|
||||
|
|
@ -116,7 +122,7 @@ async function changeOrderStateByPay(
|
|||
}, option);
|
||||
}
|
||||
}
|
||||
else if (payPaid >= 0) {
|
||||
else if (payPaid > 0 || (pays?.length === 1 && pays?.[0].entity === 'account' && orderPrice === 0 && pays?.[0].iState === 'paid')) {
|
||||
// 在支付流程当中
|
||||
// 存在已完成的pay更新order的paid和iState
|
||||
assert(orderRefunded === 0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue