mirror of https://github.com/certd/certd
chore: 增加专业版过期通知
parent
a06f3ac5da
commit
7b5043e87b
|
@ -1,11 +1,15 @@
|
|||
import { Autoload, Config, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { PipelineService } from '../pipeline/service/pipeline-service.js';
|
||||
import { logger } from '@certd/basic';
|
||||
import { SysSettingsService } from '@certd/lib-server';
|
||||
import {SysSettingsService, SysSiteInfo} from '@certd/lib-server';
|
||||
import { SiteInfoService } from '../monitor/index.js';
|
||||
import { Cron } from '../cron/cron.js';
|
||||
import {UserSettingsService} from "../mine/service/user-settings-service.js";
|
||||
import {UserSiteMonitorSetting} from "../mine/service/models.js";
|
||||
import {getPlusInfo} from "@certd/plus-core";
|
||||
import dayjs from "dayjs";
|
||||
import {NotificationService} from "../pipeline/service/notification-service.js";
|
||||
import {UserService} from "../sys/authority/service/user-service.js";
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
|
@ -33,6 +37,13 @@ export class AutoCRegisterCron {
|
|||
@Inject()
|
||||
cron: Cron;
|
||||
|
||||
@Inject()
|
||||
notificationService: NotificationService;
|
||||
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
|
||||
@Init()
|
||||
async init() {
|
||||
logger.info('加载定时trigger开始');
|
||||
|
@ -44,6 +55,9 @@ export class AutoCRegisterCron {
|
|||
// const metas = listPropertyDataFromClass(CLASS_KEY, this.echoPlugin);
|
||||
// console.log('metas', metas);
|
||||
await this.registerSiteMonitorCron();
|
||||
|
||||
|
||||
await this.registerPlusExpireCheckCron();
|
||||
}
|
||||
|
||||
async registerSiteMonitorCron() {
|
||||
|
@ -69,4 +83,58 @@ export class AutoCRegisterCron {
|
|||
await this.siteInfoService.triggerJobOnce()
|
||||
}
|
||||
}
|
||||
|
||||
registerPlusExpireCheckCron(){
|
||||
// 添加plus即将到期检查任务
|
||||
this.cron.register({
|
||||
name: 'plus-expire-check',
|
||||
cron: `0 * * * * *`,
|
||||
job: async () => {
|
||||
const plusInfo = getPlusInfo()
|
||||
if (!plusInfo.originVipType || plusInfo.originVipType==="free" ) {
|
||||
return
|
||||
}
|
||||
let label ="专业版"
|
||||
if( plusInfo.originVipType === 'comm'){
|
||||
label = "商业版"
|
||||
}
|
||||
const siteInfo = await this.sysSettingsService.getSetting<SysSiteInfo>(SysSiteInfo)
|
||||
|
||||
const appTitle = siteInfo.title || "certd"
|
||||
const expiresDate = dayjs(plusInfo.expireTime).format("YYYY-MM-DD")
|
||||
// plusInfo.expireTime= dayjs("2025-06-10").valueOf()
|
||||
let expiresDays =Math.floor((plusInfo.expireTime - new Date().getTime())/ 1000 / 60 / 60 / 24)
|
||||
let title = ""
|
||||
let content =""
|
||||
if(expiresDays === 20 ||expiresDays === 10 || expiresDays === 3 || expiresDays === 1 || expiresDays === 0){
|
||||
title = `vip(${label})即将到期`
|
||||
content = `您的${appTitle} vip (${label})剩余${expiresDays}天(${expiresDate})到期,请及时续期,以免影响业务`
|
||||
}else if (expiresDays === -1 || expiresDays === -3 || expiresDays === -7) {
|
||||
title = `vip(${label})已过期`
|
||||
content = `您的${appTitle} vip (${label})已过期${Math.abs(expiresDays)}天(${expiresDate}),请尽快续期,以免影响业务`
|
||||
}
|
||||
if(title){
|
||||
logger.warn(title)
|
||||
logger.warn(content)
|
||||
const url = await this.notificationService.getBindUrl("");
|
||||
const adminUsers = await this.userService.getAdmins()
|
||||
for (const adminUser of adminUsers) {
|
||||
logger.info(`发送vip到期通知给管理员:${adminUser.username}`)
|
||||
await this.notificationService.send({
|
||||
useDefault: true,
|
||||
logger: logger,
|
||||
body:{
|
||||
title,
|
||||
content,
|
||||
errorMessage:title,
|
||||
url
|
||||
}
|
||||
},adminUser.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { MoreThan, Not, Repository } from 'typeorm';
|
||||
import {In, MoreThan, Not, Repository} from 'typeorm';
|
||||
import { UserEntity } from '../entity/user.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import { BaseService, CommonException, Constants, FileService, SysInstallInfo, SysSettingsService } from '@certd/lib-server';
|
||||
|
@ -15,6 +15,8 @@ import { DbAdapter } from '../../../db/index.js';
|
|||
import { simpleNanoId, utils } from '@certd/basic';
|
||||
|
||||
export type RegisterType = 'username' | 'mobile' | 'email';
|
||||
|
||||
export const AdminRoleId = 1
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
|
@ -275,7 +277,7 @@ export class UserService extends BaseService<UserEntity> {
|
|||
},
|
||||
});
|
||||
const roleIds = userRoles.map(item => item.roleId);
|
||||
if (roleIds.includes(1)) {
|
||||
if (roleIds.includes(AdminRoleId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -313,4 +315,23 @@ export class UserService extends BaseService<UserEntity> {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getAdmins() {
|
||||
const admins = await this.userRoleService.find({
|
||||
where: {
|
||||
roleId: AdminRoleId,
|
||||
},
|
||||
});
|
||||
|
||||
const userIds = admins.map(item => item.userId);
|
||||
return await this.repository.find({
|
||||
where: {
|
||||
id: In(userIds),
|
||||
status: 1,
|
||||
},
|
||||
order: {
|
||||
updateTime: 'DESC',
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue