邮件:GM后台发送邮件逻辑修改

This commit is contained in:
luying
2022-05-21 20:44:50 +08:00
parent 7eea8f4e8a
commit 8a58435283
4 changed files with 38 additions and 81 deletions

View File

@@ -71,6 +71,26 @@ export async function sendMailToGuildByContent(contentId: MAIL_TYPE, guildCode:
return true;
}
export async function sendMailsByGmMail(gmmails: GMMailType[]) {
let f = new SendMailFun();
for(let gmmail of gmmails) {
let { receivers, mailType, sendTimes, circleStart, circleEnd } = gmmail;
let code = await f.setWithGmMail(gmmail);
if(!code) continue;
let mapTemp = f.getMailTemp(code);
if(sendTimes.indexOf(mapTemp.sendTime) == -1 && circleStart <= mapTemp.sendTime && circleEnd >= mapTemp.sendTime) {
if(mailType == GM_MAIL_TYPE.SINGLE) {
await f.createSingleMails(code, receivers.map(cur => cur.roleId));
} else if (mailType == GM_MAIL_TYPE.GROUP) {
await f.createGroupMails(code, receivers.map(cur => cur.roleId));
} else if (mailType == GM_MAIL_TYPE.SERVER) {
await f.createServerMails(code, receivers.map(cur => cur.serverId));
}
}
}
await f.pushToUsers();
}
class MailTemp {
public code: string;
public gmmail: GMMailTypeParam;
@@ -98,9 +118,6 @@ class MailTemp {
}
public async setWithGmMail(gmmail: GMMailType) {
this.code = genCode(8);
this.gmmail = gmmail;
this.contentId = 0;
if(gmmail.timeType == MAIL_TIME_TYPE.IMMEDIATE) {
this.sendTime = nowSeconds();
} else if (gmmail.timeType == MAIL_TIME_TYPE.DELAY) {
@@ -121,6 +138,9 @@ class MailTemp {
}
this.sendTime = time;
}
this.code = genCode(8);
this.gmmail = gmmail;
this.contentId = 0;
this.endTime = this.sendTime + gmmail.expire * 60 * 60;
this.sendName = gmmail.sendName;
this.title = gmmail.title;
@@ -209,6 +229,7 @@ export class SendMailFun {
// 生成全服邮件
public async createServerMails(code: string, serverIds: number[]) {
let mapTemp = this.mailTemps.get(code);
console.log('###### createServerMails 1', code, this.mailTemps, mapTemp)
if(mapTemp.sendTime < nowSeconds()) return;
for(let serverId of serverIds) {
let originMail = await ServerMailModel.addMail({ serverId, ...mapTemp.getCreateMailParams() });