108 lines
4.3 KiB
JavaScript
108 lines
4.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const executor_1 = require("oak-domain/lib/utils/executor");
|
|
const assert_1 = require("oak-domain/lib/utils/assert");
|
|
const checkers = [
|
|
{
|
|
/**
|
|
* 1、settlement.price总和等于settlePlan.price
|
|
* 2、settlePlan.price <= order.paid - order.refunded - order.settlePlanned
|
|
*/
|
|
entity: 'settlePlan',
|
|
action: 'create',
|
|
type: 'logicalData',
|
|
priority: 1,
|
|
checker: (operation, context) => {
|
|
const { data } = operation;
|
|
const checkfn = (settlePlan) => {
|
|
return (0, executor_1.pipeline)(() => context.select('order', {
|
|
data: {
|
|
id: 1,
|
|
paid: 1,
|
|
refunded: 1,
|
|
settlePlanned: 1,
|
|
},
|
|
filter: {
|
|
id: settlePlan.orderId,
|
|
},
|
|
}, { dontCollect: true }), (orders) => {
|
|
const [order] = orders;
|
|
const { paid, refunded, settlePlanned } = order;
|
|
const orderPrice = paid - refunded - settlePlanned;
|
|
(0, assert_1.assert)(settlePlan.price <= orderPrice, '结算计划金额不大于订单可结算金额');
|
|
return context.select('settlement', {
|
|
data: {
|
|
id: 1,
|
|
price: 1,
|
|
iState: 1,
|
|
planId: 1,
|
|
},
|
|
filter: {
|
|
planId: settlePlan.id,
|
|
iState: 'unsettled',
|
|
},
|
|
}, { dontCollect: true });
|
|
}, (settlements) => {
|
|
let amount = 0;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
(0, assert_1.assert)(amount === settlePlan.price, '结算计划金额需等于关联的结算明细金额总和');
|
|
});
|
|
};
|
|
if (data instanceof Array) {
|
|
for (const d of data) {
|
|
checkfn(d);
|
|
}
|
|
}
|
|
else {
|
|
checkfn(data);
|
|
}
|
|
}
|
|
},
|
|
{
|
|
entity: 'settlePlan',
|
|
action: 'close',
|
|
type: 'logicalData',
|
|
checker: (operation, context) => {
|
|
const { filter } = operation;
|
|
return (0, executor_1.pipeline)(() => context.select('settlePlan', {
|
|
data: {
|
|
id: 1,
|
|
price: 1,
|
|
iState: 1,
|
|
settlement$plan: {
|
|
$entity: 'settlement',
|
|
data: {
|
|
id: 1,
|
|
price: 1,
|
|
iState: 1,
|
|
},
|
|
filter: {
|
|
iState: 'unsettled',
|
|
}
|
|
}
|
|
},
|
|
filter,
|
|
}, { dontCollect: true }), (settlePlans) => {
|
|
for (const settlePlan of settlePlans) {
|
|
const { price: planPrice, settlement$plan: settlements } = settlePlan;
|
|
let amount = 0;
|
|
settlements.forEach((settlement) => amount += settlement.price);
|
|
(0, assert_1.assert)(amount === planPrice, '结算计划金额需等于未结算的结算明细金额总和');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
];
|
|
exports.default = checkers;
|