🐞 fix(团购): 修复团购定时器多出记录的问题

This commit is contained in:
luying
2022-11-07 15:16:30 +08:00
parent cdb262977c
commit 74fa24414c
3 changed files with 15 additions and 5 deletions

View File

@@ -814,7 +814,10 @@ async function initGroupShopSchedule() {
});
}
let initSumJobs = [];
export async function initSumSchedule() {
let activities = await ActivityModel.findActivityByType(ACTIVITY_TYPE.GROUP_SHOP);
let scheduleMap = new Map<number, { activityId: number, itemId: number, sum: number }[]>(); // 时间 => data
for(let activity of activities) {
@@ -828,13 +831,19 @@ export async function initSumSchedule() {
}
}
console.log('#### initSumJobs', initSumJobs.length);
console.log('#### scheduleMap', scheduleMap);
for(let job of initSumJobs) {
job.cancel();
}
for(let [time, arr] of scheduleMap) {
if(scheduledJobs[`groupShopSetSum${time}`]) {
scheduledJobs[`groupShopSetSum${time}`].cancel();
}
scheduleJob(`groupShopSetSum${time}`, time, async () => {
let job = scheduleJob(`groupShopSetSum${time}`, time, async () => {
await setGroupShopToSetSum(arr);
});
initSumJobs.push(job);
}
}