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