邮件 活跃度下发

This commit is contained in:
mamengke01
2021-02-05 11:45:07 +08:00
parent 871e71ab54
commit 286eb231a6
36 changed files with 1183 additions and 439 deletions

View File

@@ -7,14 +7,16 @@ export interface DicMail {
readonly id: number;
// 内容 %d 替换
readonly content: string;
readonly time: number;
}
const str = readJsonFile(FILENAME.DIC_MAIL);
let arr = JSON.parse(str);
export const dicMail = new Map<number, string>();
export const dicMail = new Map<number, DicMail>();
arr.forEach(o => {
dicMail.set(o.id, o.content);
o.time = o.time * 24 * 60 * 60;
dicMail.set(o.id, o);
});
arr = undefined;

View File

@@ -57,6 +57,8 @@ export interface DicBossBase {
readonly reward: RewardInter[];
readonly consume: number;
readonly opencost: number;
}
const DicBossKeys: KeysEnum<DicBossBase> = {
@@ -65,7 +67,8 @@ const DicBossKeys: KeysEnum<DicBossBase> = {
bossLevel: true,
wars: true,
reward: true,
consume: true
consume: true,
opencost: true
};
// 练兵场

View File

@@ -0,0 +1,38 @@
import { mailInit, setMails, GMMail } from '../gmData/gmMail';
import { nowSeconds } from '../timeUtil';
const ALL_SERVER = 0;
export let gmData:any = {};
export async function init() {
gmData.mails = await mailInit();
}
export function getGmMails(updatedMailAt: number, serverId: number) {
let list = [];
let serverIds = [serverId, ALL_SERVER];
for (let serverId of serverIds) {
if (!gmData.mails.get(serverId))
continue;
gmData.mails.get(serverId).map(({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType})=>{
if (updatedAt >= updatedMailAt || sendTime > updatedMailAt || endTime < nowSeconds() )
list.push({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType});
});
}
return list;
}
export function getGmMailById(id: string, serverId: number) {
let gmMail;
if (!!gmData.mails.get(serverId)) {
gmMail = gmData.mails.get(serverId).get(id);
}
if (!gmMail) {
if (!!gmData.mails.get(ALL_SERVER)) {
gmMail = gmData.mails.get(ALL_SERVER).get(id);
}
}
return gmMail;
}
export function setGmMails(mails: GMMail[]) {
setMails(mails, gmData.mails);
}

View File

@@ -0,0 +1,59 @@
type KeysEnum<T> = { [P in keyof Required<T>]: true };
import { RewardInter } from '../interface';
import { GMMailModel } from '../../db/GMMail';
const _ = require('lodash');
export interface GMMail {
readonly id: string;
readonly sendRoles?: Array<{roleId: string, status: number}>;
readonly goods: Array<RewardInter>;
readonly sendTime: number;
readonly endTime: number;
readonly content: string;
readonly gmMailType: number;
readonly updatedAt: number;
readonly serverId: number;
readonly sendName: string;
}
const GMMailKeys: KeysEnum<GMMail> = {
id: true,
sendRoles: true,
goods: true,
sendTime: true,
endTime: true,
content: true,
gmMailType: true,
updatedAt: true,
serverId: true,
sendName: true
};
export async function mailInit() {
let gmMail = new Map<number, any>();
let mails = await GMMailModel.getMails();
mails.map((o:any)=>{
o.id = o._id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
return gmMail;
}
export function setMails(mails:GMMail[], gmMail) {
mails.map((o:any)=>{
o.id = o._id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
}

View File

@@ -104,6 +104,18 @@ export interface Uid {
export interface pushMail {
route: string;
data:any[];
uids:Uid[];
}
data: mailData[];
uids: Uid[];
}
export interface mailData {
id: string;
mailId: string;
goods: RewardInter[];
sendTime: number;
endTime: number;
content: string;
status: number;
mailType: number;
sendName: string;
}