邮件 活跃度下发
This commit is contained in:
59
shared/pubUtils/gmData/gmMail.ts
Normal file
59
shared/pubUtils/gmData/gmMail.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user