邮件系统bug
This commit is contained in:
@@ -57,7 +57,8 @@ export class EntryHandler {
|
||||
await session.abind(role.roleId);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
session.set('updatedMailAt', role.updatedMailAt);
|
||||
let updatedMailAt = role.updatedMailAt?role.updatedMailAt:0;
|
||||
session.set('updatedMailAt', updatedMailAt);
|
||||
session.set('roleName', role.roleName);
|
||||
session.set('eventStatus', role.eventStatus);
|
||||
session.set('sid', self.app.get('serverId'));
|
||||
|
||||
@@ -2,11 +2,13 @@ import { Application, ChannelService } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { setGmMails, getGmMailById, getGmMails, getGmUseMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { MAIL_TYPE, MAIL_TEM_TYPE } from "../../../consts/constModules/mailConst";
|
||||
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';
|
||||
import { MailType } from '../../../db/Mail';
|
||||
export default function (app: Application) {
|
||||
return new GMRemote(app);
|
||||
}
|
||||
@@ -97,14 +99,14 @@ export class GMRemote {
|
||||
channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param));
|
||||
}
|
||||
|
||||
public async refreshGmMails(mails:[any]) {
|
||||
public refreshGmMails(mails:[any]) {
|
||||
setGmMails(mails);
|
||||
}
|
||||
|
||||
public async getMailInfos(roleId: string, serverId: number, mails: [any], groupMails: [any]) {
|
||||
public getMailInfos(roleId: string, serverId: number, mails: [any], groupMails: [any]) {
|
||||
let list: mailData[] = [];
|
||||
let nowTime = nowSeconds();
|
||||
mails.map(async function({ mailId, goods, sendTime, params, status, _id, mailTemType, sendName, endTime}) {
|
||||
mails.map(function({ mailId, goods, sendTime, params, status, _id, mailTemType, sendName, endTime}) {
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
if (endTime < nowTime)
|
||||
return;
|
||||
@@ -120,7 +122,7 @@ export class GMRemote {
|
||||
list.push({ id: _id, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
}
|
||||
});
|
||||
groupMails.map(async function({ mailId, goods, sendTime, endTime, params, sendRoles, _id, mailTemType, sendName }) {
|
||||
groupMails.map(function({ mailId, goods, sendTime, endTime, params, sendRoles, _id, mailTemType, sendName }) {
|
||||
let { status } = findWhere(sendRoles, {roleId});
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
if (endTime < nowTime)
|
||||
@@ -140,13 +142,47 @@ export class GMRemote {
|
||||
return list;
|
||||
}
|
||||
|
||||
public async getMails(updatedMailAt: number, serverId: number) {
|
||||
public getMails(updatedMailAt: number, serverId: number) {
|
||||
let gmMails = getGmMails(updatedMailAt, serverId);
|
||||
return gmMails;
|
||||
}
|
||||
public async getUseMails(serverId: number) {
|
||||
let gmMails = getGmUseMails(serverId);
|
||||
return gmMails;
|
||||
public getUseMails(serverId: number, groupMailRewards: GroupMailType[], mailRewards: MailType[]) {
|
||||
let nowTime = nowSeconds();
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
let mailIds: string[] = [];
|
||||
let groupMailIds: string[] = [];
|
||||
groupMailRewards.map(({_id, goods, mailId, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
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) {
|
||||
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};
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -83,11 +83,11 @@ export class RoleHandler {
|
||||
if (type == 1) {//单个领取
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.READ], { status: MAIL_STATUS.RECEIVED });
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.READ, MAIL_STATUS.CREATE], { status: MAIL_STATUS.RECEIVED });
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
mail = await GroupMailModel.updateMailByStatus(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ]);
|
||||
mail = await GroupMailModel.updateMailByStatus(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else {
|
||||
@@ -95,7 +95,7 @@ export class RoleHandler {
|
||||
}
|
||||
mails.push({ id, status: MAIL_STATUS.RECEIVED, mailType });
|
||||
if (mail.mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = await this.app.rpc.gm.gmRemote.getUseGmMailById.toServer('gm-server-1', id, serverId, nowTime);
|
||||
let gmMail = await this.app.rpc.gm.gmRemote.getUseGmMailById.toServer('gm-server-1', mail.mailId, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
@@ -103,45 +103,15 @@ export class RoleHandler {
|
||||
mailGoods.push(...mail.goods);
|
||||
}
|
||||
} else {//一键领取
|
||||
let ids = [];
|
||||
let gmMails = await this.app.rpc.gm.gmRemote.getUseMails.toServer('gm-server-1', serverId);
|
||||
let groupMailRewards = await GroupMailModel.findRewardsMails(roleId);
|
||||
groupMailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = gmMails.get(id);
|
||||
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});
|
||||
ids.push(_id);
|
||||
});
|
||||
if (!!ids.length)
|
||||
await GroupMailModel.updateMailStatus(ids, MAIL_STATUS.RECEIVED, roleId);
|
||||
let mailRewards = await MailModel.findRewardsMails(roleId);
|
||||
ids = [];
|
||||
mailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = gmMails.get(id);
|
||||
if (!gmMail || !gmMail.goods.length|| gmMail.endTime < nowSeconds()) {
|
||||
return;
|
||||
}
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
if (goods.length)
|
||||
return;
|
||||
mailGoods.push(...goods);
|
||||
}
|
||||
mails.push({id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
ids.push(_id);
|
||||
});
|
||||
if (!!ids.length)
|
||||
await MailModel.updateMailStatus(ids, MAIL_STATUS.RECEIVED);
|
||||
let { mailGoods: goods, mailIds, groupMailIds, mails: resMails} = await this.app.rpc.gm.gmRemote.getUseMails.toServer('gm-server-1', serverId, groupMailRewards, mailRewards);
|
||||
mailGoods = goods;
|
||||
mails = resMails;
|
||||
if (!!mailIds.length)
|
||||
await GroupMailModel.updateMailStatus(mailIds, MAIL_STATUS.RECEIVED, roleId);
|
||||
if (!!groupMailIds.length)
|
||||
await MailModel.updateMailStatus(groupMailIds, MAIL_STATUS.RECEIVED);
|
||||
}
|
||||
let resGoods = [];
|
||||
if (!!mailGoods && !!mailGoods.length)
|
||||
|
||||
@@ -97,7 +97,7 @@ export default class GroupMail extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findRewardsMails(roleId: string, lean = true) {
|
||||
const result: GroupMailType[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, 'sendRoles.status':{ $in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailTemType').lean(lean);
|
||||
const result: GroupMailType[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, 'sendRoles.status':{ $in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailId mailTemType status').lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export default class Mail extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findRewardsMails(roleId: string, lean = true) {
|
||||
const result: MailType[] = await MailModel.find({ roleId, status: {$in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailTemType').lean(lean);
|
||||
const result: MailType[] = await MailModel.find({ roleId, status: {$in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailId mailTemType status').lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user