邮件:循环邮件优化
This commit is contained in:
@@ -72,14 +72,14 @@ export async function sendMailToGuildByContent(contentId: MAIL_TYPE, guildCode:
|
||||
|
||||
class MailTemp {
|
||||
public code: string;
|
||||
public gmmail: GMMailTypeParam;
|
||||
private contentId: MAIL_TYPE = MAIL_TYPE.SEND_MAIL; // 0-读GmMail,1以上读dicMail
|
||||
private sendName: string = SEND_NAME;
|
||||
private title: string = SEND_TITLE;
|
||||
private content: string = '';
|
||||
private gmmail: GMMailTypeParam;
|
||||
private hasGoods: boolean = false; // 是否内含奖励
|
||||
private goods: RewardInter[] = []; // 发送的奖励
|
||||
private sendTime: number;
|
||||
public sendTime: number;
|
||||
private endTime: number;
|
||||
|
||||
// 从dicMail读取数据
|
||||
@@ -148,6 +148,10 @@ export class SendMailFun {
|
||||
private groupMails: GroupMailType[] = [];
|
||||
private serverMails: ServerMailType[] = [];
|
||||
|
||||
public getMailTemp(code: string) {
|
||||
return this.mailTemps.get(code);
|
||||
}
|
||||
|
||||
// 从dicMail读取数据
|
||||
public setWithContentId(contentId: MAIL_TYPE, params: { sendName?: string, params?: string[], goods?: RewardInter[] }) {
|
||||
let mailTemp = new MailTemp();
|
||||
@@ -167,29 +171,35 @@ export class SendMailFun {
|
||||
// 生成单人邮件
|
||||
public async createSingleMails(code: string, roleIds: string[]) {
|
||||
let mapTemp = this.mailTemps.get(code);
|
||||
if(mapTemp.sendTime < nowSeconds()) return;
|
||||
for(let roleId of roleIds) {
|
||||
let originMail = await MailModel.addMail({ roleId, ...mapTemp.getCreateMailParams() });
|
||||
this.mails.push(originMail);
|
||||
}
|
||||
await GMMailModel.sendMail(mapTemp.gmmail._id, mapTemp.sendTime);
|
||||
}
|
||||
|
||||
// 生成多人邮件
|
||||
public async createGroupMails(code: string, roleIds: string[], guildCode?: string) {
|
||||
let mapTemp = this.mailTemps.get(code);
|
||||
if(mapTemp.sendTime < nowSeconds()) return;
|
||||
let roleStatus = roleIds.map(roleId => {
|
||||
return { roleId, status: MAIL_STATUS.CREATE }
|
||||
})
|
||||
let originMail = await GroupMailModel.addMail({ roleStatus, guildCode, ...mapTemp.getCreateMailParams() });
|
||||
await GMMailModel.sendMail(mapTemp.gmmail._id, mapTemp.sendTime);
|
||||
this.groupMails.push(originMail);
|
||||
}
|
||||
|
||||
// 生成全服邮件
|
||||
public async createServerMails(code: string, serverIds: number[]) {
|
||||
let mapTemp = this.mailTemps.get(code);
|
||||
if(mapTemp.sendTime < nowSeconds()) return;
|
||||
for(let serverId of serverIds) {
|
||||
let originMail = await ServerMailModel.addMail({ serverId, ...mapTemp.getCreateMailParams() });
|
||||
this.serverMails.push(originMail);
|
||||
}
|
||||
await GMMailModel.sendMail(mapTemp.gmmail._id, mapTemp.sendTime);
|
||||
}
|
||||
|
||||
public async setMails(mails: MailType[], groupMails: GroupMailType[], serverMails: ServerMailType[]) {
|
||||
@@ -206,14 +216,12 @@ export class SendMailFun {
|
||||
let pushByServerId = new Map<number, MailParam[]>();
|
||||
|
||||
for(let mail of this.mails) {
|
||||
console.log('#####', mail.sendTime)
|
||||
if(mail.sendTime <= nowSeconds() && mail.endTime > nowSeconds()) {
|
||||
let mailParam = new MailParam(GM_MAIL_TYPE.SINGLE, mail);
|
||||
if(!pushByRoleId.has(mail.roleId)) pushByRoleId.set(mail.roleId, []);
|
||||
pushByRoleId.get(mail.roleId).push(mailParam);
|
||||
}
|
||||
}
|
||||
console.log('#####pushByRoleId', pushByRoleId)
|
||||
for(let mail of this.groupMails) {
|
||||
if(mail.sendTime <= nowSeconds() && mail.endTime > nowSeconds()) {
|
||||
let mailParam = new MailParam(GM_MAIL_TYPE.GROUP, mail);
|
||||
@@ -238,7 +246,6 @@ export class SendMailFun {
|
||||
|
||||
for(let [roleId, mails ] of pushByRoleId) {
|
||||
let uids = await this.getUids(roleId, myRoleId, mySid);
|
||||
console.log('###### onMailsAdd', uids, mails);
|
||||
if(uids.length > 0 && mails.length > 0) {
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails }), uids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user