邮件:修改邮件逻辑

This commit is contained in:
luying
2021-06-28 13:31:29 +08:00
parent 2ffe0f7890
commit 3b1d458a87
29 changed files with 932 additions and 626 deletions
@@ -8,6 +8,9 @@ import { GMMailModel } from '../../../db/GMMail';
import { setGmMails } from '../../../pubUtils/gmData/gmDataUtil';
import { getRoleOnlineInfo } from '../../../services/redisService';
import { dispatch } from '../../../util/dispatcher';
import { SendMailFun } from '../../../services/mailService';
import { GM_MAIL_TYPE } from '../../../consts';
import { RewardInter } from '../../../pubUtils/interface';
export default function(app: Application) {
return new GmHandler(app);
}
@@ -75,11 +78,34 @@ export class GmHandler {
}
//对接gm后台,下发邮件
async addMail(msg: { endTime: number, serverId: number, sendName: string, content: string, goods, sendRoles:[{roleId: string, status: number}], gmMailType: number, sendTime: number }) {
let {sendRoles, endTime, content, sendName, gmMailType, sendTime, goods, serverId} = msg;
let mail = await GMMailModel.addMail({serverId, sendRoles, sendName, endTime, content, gmMailType, sendTime, goods});
setGmMails([mail]);//更新邮件缓存
this.app.rpc.role.roleRemote.sendGmMailsToRoles.toServer('role-server-1',[mail]);//检查是否是群体邮件,并下发群体邮件,非群体邮件通过Filter刷新下发
async addMail(msg: { endTime: number, sendName: string, content: string, goods: RewardInter[], sendTime: number }) {
let {endTime, content, sendName, sendTime, goods } = msg;
let mail = await GMMailModel.addMail({endTime, content, sendName, sendTime, goods});
return resResult(STATUS.SUCCESS, { mail });
}
async sendMail(msg: { id: string, mailType: number, roleIds?: string[], serverIds?: number[] }, session: BackendSession) {
let { id, mailType, roleIds, serverIds } = msg;
let f = new SendMailFun();
await f.setWithGmMail(id);
if(mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
await f.sendToUsers(mailType, roleIds);
} else {
await f.sendToServer(serverIds);
}
return resResult(STATUS.SUCCESS);
}
async sendWithContent(msg: { contentId: number, mailType: number, params: { params?: string[], sendName?: string, goods?: RewardInter[], endTime?: number}, roleIds?: string[], serverIds?: number[] }, session: BackendSession) {
let { contentId, mailType, roleIds, serverIds, params } = msg;
let f = new SendMailFun();
f.setWithContentId(contentId, params);
if(mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
await f.sendToUsers(mailType, roleIds);
} else {
await f.sendToServer(serverIds);
}
return resResult(STATUS.SUCCESS);
}
async reloadResource(msg: {}, session: BackendSession) {
+45 -92
View File
@@ -4,7 +4,6 @@ import { STATUS } from '../../../consts';
import { setGmMails, getGmMailById, getGmMails, getGmUseMails } from '../../../pubUtils/gmData/gmDataUtil';
import { MAIL_TYPE, MAIL_TEM_TYPE, MAIL_STATUS } from "../../../consts/constModules/mailConst";
import { mailData } from "../../../pubUtils/interface";
import { getContent } from '../../../services/mailService';
import { findWhere } from 'underscore';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { GroupMailType } from '../../../db/GroupMail';
@@ -104,53 +103,7 @@ export class GMRemote {
public refreshGmMails(mails:[any]) {
setGmMails(mails);
}
/**
* 获得邮件详情信息
* @param roleId
* @param serverId
* @param mails
* @param groupMails
*/
public getMailInfos(roleId: string, serverId: number, mails: [any], groupMails: [any]) {
let list: mailData[] = [];
let nowTime = nowSeconds();
//单个邮件
mails.map(function({ mailId, goods, sendTime, params, status, _id, mailTemType, sendName, endTime}) {
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //gm邮件,检查是否超时,并获得gm邮件的content,sendName endTime sendTime goods等信息
if (endTime < nowTime)
return;
let { content } = getContent(parseInt(mailId), params);
if (!content)
return;
list.push({ id: _id, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
} else if (mailTemType == MAIL_TEM_TYPE.GMTYPE) { //系统邮件
let gmMail = getGmMailById(mailId, serverId, nowTime);
if (!gmMail)
return;
let { goods, sendTime, content, endTime, sendName } = gmMail;
list.push({ id: _id, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
}
});
//群体邮件
groupMails.map(function({ mailId, goods, sendTime, endTime, params, sendRoles, _id, mailTemType, sendName }) {
let { status } = findWhere(sendRoles, {roleId});
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //gm邮件,检查是否超时,并获得gm邮件的content,sendName endTime sendTime goods等信息
if (endTime < nowTime)
return;
let { content } = getContent( parseInt(mailId), params);
if (!content)
return;
list.push({ id: _id, goods, sendTime, content, endTime, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
} else if (mailTemType == MAIL_TEM_TYPE.GMTYPE) { //系统邮件
let gmMail = getGmMailById(mailId, serverId, nowTime);
if (!gmMail)
return;
let { goods, sendTime, content, endTime, sendName } = gmMail;
list.push({ id: _id, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
}
});
return list;
}
/**
* 获得据上次刷新后,可以加入的邮件
* @param updatedMailAt
@@ -160,50 +113,50 @@ export class GMRemote {
let gmMails = getGmMails(updatedMailAt, serverId);
return gmMails;
}
/**
* 获得可以领取的邮件奖
* @param serverId
* @param groupMailRewards
* @param mailRewards
*/
public getUseMails(serverId: number, groupMailRewards: GroupMailType[], mailRewards: MailType[]) {
let nowTime = nowSeconds();
let mailGoods = [];
let mails = [];
let mailIds = [];
let groupMailIds = [];
groupMailRewards.map(({_id, goods, mailId, mailTemType})=>{
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {//gm邮件检查是否有奖励以及是否可以领取
let gmMail = getGmMailById(mailId, serverId, nowTime);
if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
return;
}
mailGoods.push(...gmMail.goods);
} else {
if (!goods.length)//系统邮件,检查是否有奖励
return;
mailGoods.push(...goods);
}
mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.GROUPMAIL});
groupMailIds.push(_id);
});
mailRewards.map(({_id, goods, mailId, mailTemType})=>{
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {//gm邮件检查是否有奖励以及是否可以领取
let gmMail = getGmMailById(mailId, serverId, nowTime);
if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
return;
}
mailGoods.push(...gmMail.goods);
} else {
if (!goods.length)//系统邮件,检查是否有奖励
return;
mailGoods.push(...goods);
}
mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.SINGLEMAIL});
mailIds.push(_id);
});
return {mailIds, groupMailIds, mails, mailGoods};
}
// /**
// * 获得可以领取的邮件奖
// * @param serverId
// * @param groupMailRewards
// * @param mailRewards
// */
// public getUseMails(serverId: number, groupMailRewards: GroupMailType[], mailRewards: MailType[]) {
// let nowTime = nowSeconds();
// let mailGoods = [];
// let mails = [];
// let mailIds = [];
// let groupMailIds = [];
// groupMailRewards.map(({_id, goods, mailId, mailTemType})=>{
// if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {//gm邮件检查是否有奖励以及是否可以领取
// let gmMail = getGmMailById(mailId, serverId, nowTime);
// if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
// return;
// }
// mailGoods.push(...gmMail.goods);
// } else {
// if (!goods.length)//系统邮件,检查是否有奖励
// return;
// mailGoods.push(...goods);
// }
// mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.GROUPMAIL});
// groupMailIds.push(_id);
// });
// mailRewards.map(({_id, goods, mailId, mailTemType})=>{
// if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {//gm邮件检查是否有奖励以及是否可以领取
// let gmMail = getGmMailById(mailId, serverId, nowTime);
// if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
// return;
// }
// mailGoods.push(...gmMail.goods);
// } else {
// if (!goods.length)//系统邮件,检查是否有奖励
// return;
// mailGoods.push(...goods);
// }
// mails.push({id: _id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.SINGLEMAIL});
// mailIds.push(_id);
// });
// return {mailIds, groupMailIds, mails, mailGoods};
// }
/**
* 通过模板mailId获得gm邮件
* @param mailId