This commit is contained in:
张成
2026-03-24 17:03:54 +08:00
parent 268520a0f2
commit 5b654824b4
25 changed files with 799 additions and 111 deletions

View File

@@ -36,6 +36,8 @@ class Schedule {
async init() {
const bizSubscriptionLogic = require("../api/service/biz_subscription_logic");
const usageSvc = require("../api/service/biz_usage_service");
const baseModel = require("../middleware/baseModel");
node_schedule.scheduleJob("10 0 * * *", async () => {
await this.execute_with_lock("biz_subscription_expire", async () => {
@@ -43,6 +45,29 @@ class Schedule {
logs.log(`[定时任务] 订阅到期扫描完成,更新行数: ${n}`);
});
});
node_schedule.scheduleJob("0 9 * * *", async () => {
await this.execute_with_lock("biz_subscription_renew_remind", async () => {
const subs = await baseModel.biz_subscription.findAll({ where: { status: "active" } });
const now = Date.now();
for (const s of subs) {
const end = new Date(s.end_time).getTime();
const days = Math.ceil((end - now) / 86400000);
if (days >= 0 && [7, 3, 1].includes(days)) {
logs.log(
`[续费提醒] subscription_id=${s.id} user_id=${s.user_id}${days} 天后到期`
);
}
}
});
});
node_schedule.scheduleJob("30 0 1 * *", async () => {
await this.execute_with_lock("biz_usage_monthly_init", async () => {
const n = await usageSvc.ensureUsageRowsForCurrentMonth();
logs.log(`[定时任务] 月用量行初始化/补齐,处理订阅数: ${n}`);
});
});
}
}