oak-pay-business/es/watchers/settlePlan.js

38 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
const watchers = [
{
//settle 更新order时filter不允许携带iState故使用fn方式
name: '当settlePlan达到结算时间时结算settlePlan',
entity: 'settlePlan',
filter: async () => {
const now = Date.now();
return {
iState: 'unsettled',
when: {
$lte: now,
},
};
},
projection: {
id: 1,
},
fn: async (context, data) => {
if (data.length > 0) {
const ids = data.map((ele) => ele.id);
await context.operate('settlePlan', {
id: await generateNewIdAsync(),
action: 'settle',
data: {},
filter: {
id: {
$in: ids,
}
}
}, {});
}
return context.opResult;
}
}
];
export default watchers;