1
This commit is contained in:
@@ -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}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user