settlePlan checker、trigger调整

This commit is contained in:
lxy 2025-07-17 16:07:16 +08:00
parent 64464d0b00
commit db74dec6ac
3 changed files with 14 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import withdrawAccounts from './withdrawAccount';
import refundCheckers from './refund';
import withdrawTransferCheckers from './withdrawTransfer';
import shipCheckers from './ship';
import settlePlanCheckers from './settlePlan';
const checkers = [
...refundCheckers,
@ -25,6 +26,7 @@ const checkers = [
...wpProductCheckers,
...withdrawTransferCheckers,
...shipCheckers,
...settlePlanCheckers,
] as Checker<EntityDict, keyof EntityDict, RuntimeCxt>[];
export default checkers;

View File

@ -13,6 +13,7 @@ const checkers: Checker<EntityDict, 'settlePlan', RuntimeCxt>[] = [
entity: 'settlePlan',
action: 'create',
type: 'logicalData',
priority: 1,
checker: (operation, context) => {
const { data } = operation as EntityDict['settlePlan']['Create'];
const checkfn = (settlePlan: EntityDict['settlePlan']['CreateOperationData']) => {
@ -51,6 +52,16 @@ const checkers: Checker<EntityDict, 'settlePlan', RuntimeCxt>[] = [
settlements!.forEach(
(settlement) => amount += settlement.price
);
if (settlePlan.settlement$plan && settlePlan.settlement$plan.length > 0) {
for (const settlementOper of settlePlan.settlement$plan) {
const settlementData = settlementOper.data;
if (settlementData instanceof Array) {
settlementData.forEach((s) => amount += s.price ?? 0);
} else {
amount += settlementData?.price ?? 0;
}
}
}
assert(amount === settlePlan.price!, '结算计划金额需等于关联的结算明细金额总和');
}
)

View File

@ -11,6 +11,7 @@ const triggers: Trigger<EntityDict, 'settlePlan', BRC>[] = [
action: 'create',
when: 'before',
asRoot: true,
priority: 99,
fn: async ({ operation }, context, option) => {
const { data } = operation;
let count = 0;