邮件:修改邮件逻辑
This commit is contained in:
@@ -14,7 +14,7 @@ import { GuildLeader } from '../../../domain/rank';
|
||||
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
|
||||
import { hasStructureConsume, getStructureConsume, gameData } from '../../../pubUtils/data';
|
||||
import { GuildRecModel } from '../../../db/GuildRec';
|
||||
import { sendMail } from '../../../services/mailService';
|
||||
import { sendMailByContent, SendMailFun } from '../../../services/mailService';
|
||||
import { updateUserInfo, isRoleOnline, getRoleOnlineInfo } from '../../../services/redisService';
|
||||
|
||||
import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
@@ -231,17 +231,15 @@ export class GuildHandler {
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { managerCnt: guild.managerCnt });
|
||||
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_MANAGER, memberRoleId, roleName, [guild.name]);
|
||||
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_MANAGER, memberRoleId, { sendName: roleName, params: [guild.name] });
|
||||
} else if (auth == GUILD_AUTH.LEADER) {
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_LEADER, [roleName, role.roleName]);
|
||||
this.app.rpc.chat.guildRemote.changeLeader.toServer(chatSid, code, guild.managerCnt, role, roleId);
|
||||
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
|
||||
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_LEADER, memberRoleId, roleName, [guild.name]);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_LEADER, memberRoleId, { sendName: roleName, params: [guild.name] });
|
||||
} else {
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid,code, { managerCnt: guild.managerCnt });
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_MEMBER, memberRoleId, roleName, [guild.name]);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_MEMBER, memberRoleId, { sendName: roleName, params: [guild.name] });
|
||||
}
|
||||
|
||||
|
||||
@@ -383,7 +381,7 @@ export class GuildHandler {
|
||||
}
|
||||
} else { // 拒绝申请,删除申请
|
||||
for(let { roleId } of applyList) {
|
||||
await sendMail(MAIL_TYPE.GUILD_APPLY_REFUSE, roleId, roleName, [guild.name]);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_APPLY_REFUSE, roleId, { sendName: roleName, params: [guild.name] });
|
||||
}
|
||||
|
||||
await UserGuildApplyModel.deleteByApplyCode(applyCodeList);
|
||||
@@ -678,7 +676,7 @@ export class GuildHandler {
|
||||
// 添加动态
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
|
||||
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid,rec);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_KICK, memberRoleId, roleName, [guild.name]);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_KICK, memberRoleId, { sendName: roleName, params: [guild.name] });
|
||||
|
||||
return resResult(STATUS.SUCCESS, { memberCnt: guild.memberCnt });
|
||||
}
|
||||
@@ -733,8 +731,8 @@ export class GuildHandler {
|
||||
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid,rec);
|
||||
|
||||
this.app.rpc.chat.guildRemote.changeLeader.toServer(chatSid,code, guild.managerCnt, topUser, leaderRoleId);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_IMPEACH, leaderRoleId, roleName, [guild.name]);
|
||||
await sendMail(MAIL_TYPE.GUILD_BE_SET_LEADER, topUser.roleId, roleName, [guild.name]);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_IMPEACH, leaderRoleId, { sendName: roleName, params: [guild.name] });
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_LEADER, topUser.roleId, { sendName: roleName, params: [guild.name] });
|
||||
|
||||
await updateUserInfo(REDIS_KEY.GUILD_INFO, code, [{field: 'leader', value: new GuildLeader(topUser) } ]);
|
||||
|
||||
@@ -837,9 +835,9 @@ export class GuildHandler {
|
||||
|
||||
const { members } = guild;
|
||||
//下发邮件
|
||||
for(let roleId of members) {
|
||||
await sendMail(MAIL_TYPE.SEND_MAIL, roleId, roleName, [info]);
|
||||
}
|
||||
let f = new SendMailFun();
|
||||
f.setWithContentId(MAIL_TYPE.SEND_MAIL, { sendName: roleName, params: [info] });
|
||||
await f.sendToGuild(code, members);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { isSuccess: true });
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getWorldChannelSid, groupRoomId } from '../../../services/chatService';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { GeneralRankParamRole, GeneralRankParamBattle } from '../../../domain/rank';
|
||||
import { getAllGuildActivityStatus } from '../../../services/guildActivityService';
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new ChatRemote(app);
|
||||
@@ -225,4 +226,17 @@ export class ChatRemote {
|
||||
let guildActivities = getAllGuildActivityStatus();
|
||||
channel.pushMessage(this.GUILD_ACTIVITY_STATUS_UPDATE, resResult(STATUS.SUCCESS, { guildActivities }));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向全服推送邮件
|
||||
* @param serverId 服务器id
|
||||
* @param path 推送地址
|
||||
* @param mails 邮件内容
|
||||
*/
|
||||
public async sendMail(serverId: number, path: string, data: { mails: MailParam[] }) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(path, resResult(STATUS.SUCCESS, data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { RoleType } from '../../../db/Role';
|
||||
import { GuildRecType } from '../../../db/GuildRec';
|
||||
import { leaveGuildChannel, groupRoomId } from '../../../services/chatService';
|
||||
import { GuildRankParams, WoodenHorse, Event } from '../../../domain/battleField/guildActivity';
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildRemote(app);
|
||||
@@ -35,6 +36,7 @@ export class GuildRemote {
|
||||
private GUILD_RACE_UPDATE = 'onRaceHorseUpdate'; /// 更新木牛流马
|
||||
private GUILD_RACE_EVENT = 'onRaceEventUpdate'; /// 更新木牛流马
|
||||
private GUILD_POP_UP_ACTIVITY = 'onActivityUpdate'; /// 向军团成员发送弹窗礼包
|
||||
private GUILD_TRAIN_RESET = 'onGuildTainReset'; // 试炼场重置
|
||||
|
||||
/**
|
||||
* 封装,军团相关channel名: 'guild'+guildCode
|
||||
@@ -285,11 +287,26 @@ export class GuildRemote {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 向军团推送弹窗礼包数据活动
|
||||
* @param guildCode
|
||||
*/
|
||||
* @description 向军团推送弹窗礼包数据活动
|
||||
* @param guildCode
|
||||
*/
|
||||
public async sendPopUpActivity(guildCode: string, data: any[]) {
|
||||
console.log("sendPopUpActivity")
|
||||
this.pushMessage(guildCode, this.GUILD_POP_UP_ACTIVITY, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 军团邮件
|
||||
* @param guildCode 军团code
|
||||
* @param path 推送地址
|
||||
* @param data 军团内容
|
||||
*/
|
||||
public async sendMailToGuild(guildCode: string, path: string, data: { mails: MailParam[]}) {
|
||||
this.pushMessage(guildCode, path, data);
|
||||
}
|
||||
|
||||
public async sendTrainReset(guildCode: string) {
|
||||
this.pushMessage(guildCode, this.GUILD_TRAIN_RESET, {});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus';
|
||||
import { setGmMails, getGmMailById, getGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { MAIL_TYPE, MAIL_TEM_TYPE } from "../../../consts/constModules/mailConst";
|
||||
import { mailData } from "../../../pubUtils/interface";
|
||||
import { getContent } from '../../../services/mailService';
|
||||
import { findWhere } from 'underscore';
|
||||
export default function (app: Application) {
|
||||
return new GateRemote(app);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import {Application, BackendSession, ChannelService} from 'pinus';
|
||||
import { MailModel } from '../../../db/Mail';
|
||||
import { GroupMailModel } from '../../../db/GroupMail';
|
||||
import { MailModel, MailType } from '../../../db/Mail';
|
||||
import { GroupMailModel, GroupMailType } from '../../../db/GroupMail';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, GM_MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { addItems } from '../../../services/rewardService';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getMails } from '../../../services/mailService';
|
||||
import { ServerMailModel, ServerMailType } from '../../../db/ServerMail';
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
import { RewardInter } from '../../../pubUtils/interface';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new MailHandler(app);
|
||||
}
|
||||
@@ -32,47 +35,47 @@ export class MailHandler {
|
||||
let roleId: string = session.get('roleId');
|
||||
let { id, mailType } = msg;
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
mail = await MailModel.updateMailByStatus(id, [MAIL_STATUS.CREATE], { status: MAIL_STATUS.READ });
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
mail = await GroupMailModel.updateMailByStatus(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
}
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.READ, mailType }] });
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.updateStatusWithCondition(id, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.READ, [MAIL_STATUS.CREATE])
|
||||
}
|
||||
// if (!mail)
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: mail?[{ id, status: MAIL_STATUS.READ, mailType }]:[] });
|
||||
}
|
||||
|
||||
public async delMails(msg: { id: string, mailType: number, type: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
let { id, type, mailType } = msg;
|
||||
if (type == 1) {//单个删除
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
let mail = await MailModel.delMail(id);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.DELETE, mailType }] });
|
||||
} else if (mailType == MAIL_TYPE.GROUPMAIL) {
|
||||
let mail = await GroupMailModel.delMail(id, roleId);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id, status: MAIL_STATUS.DELETE, mailType }] });
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let mail: MailType|GroupMailType|ServerMailType;
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.delMailById(id);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.delMailById(id, roleId);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.delMailById(id, roleId);
|
||||
}
|
||||
if (!mail) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { mails: [{ id: mail._id, mailType, status: MAIL_STATUS.DELETE}] });
|
||||
} else {//一键删除
|
||||
let mails = [];
|
||||
let resGroupMailIds = await GroupMailModel.findReadAndRewardsMails(roleId);
|
||||
let groupMailIds = resGroupMailIds.map(({_id})=>{
|
||||
mails.push({id:_id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
return _id;
|
||||
});
|
||||
await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.DELETE, roleId);
|
||||
let resMailIds = await MailModel.findReadAndRewardsMails(roleId);
|
||||
let mailIds = resMailIds.map(({_id})=>{
|
||||
mails.push({id: _id, status: MAIL_STATUS.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
return _id;
|
||||
});
|
||||
await MailModel.updateMailStatus(mailIds, MAIL_STATUS.DELETE);
|
||||
let singlemails = await MailModel.delMailsByRoleId(roleId);
|
||||
let groupMails = await GroupMailModel.delMailsByRoleId(roleId);
|
||||
let servermails = await ServerMailModel.delMailsByRoleId(roleId);
|
||||
let mails: { id: string, mailType: GM_MAIL_TYPE, status: MAIL_STATUS }[] = [];
|
||||
for(let mail of singlemails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.SINGLE, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
for(let mail of groupMails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.GROUP, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
for(let mail of servermails) {
|
||||
mails.push({ id: mail._id, mailType: GM_MAIL_TYPE.SERVER, status: MAIL_STATUS.DELETE });
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { mails });
|
||||
}
|
||||
}
|
||||
@@ -83,44 +86,42 @@ export class MailHandler {
|
||||
let sid: string = session.get('sid');
|
||||
let serverId: number = session.get('serverId');
|
||||
let { id, type, mailType } = msg;
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
let nowTime: number = nowSeconds();
|
||||
let mails: MailParam[] = [];
|
||||
if (type == 1) {//单个领取
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
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_STATUS.CREATE]);
|
||||
if (!mail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
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', mail.mailId, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...mail.goods);
|
||||
let mail: MailType|GroupMailType|ServerMailType;
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
mail = await MailModel.updateStatusWithCondition(id, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
} else if (mailType == GM_MAIL_TYPE.SERVER) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
}
|
||||
if (!mail) return resResult(STATUS.WRONG_PARMS);
|
||||
mails.push(new MailParam(mailType, mail, roleId));
|
||||
} else {//一键领取
|
||||
let groupMailRewards = await GroupMailModel.findRewardsMails(roleId);
|
||||
let mailRewards = await MailModel.findRewardsMails(roleId);
|
||||
let { mailGoods: goods, mailIds, groupMailIds} = await this.app.rpc.gm.gmRemote.getUseMails.toServer('gm-server-1', serverId, groupMailRewards, mailRewards);
|
||||
mailGoods = goods;
|
||||
if (!!groupMailIds.length) //领取群体邮件
|
||||
mails = await GroupMailModel.updateMailStatus(groupMailIds, MAIL_STATUS.RECEIVED, roleId);
|
||||
if (!!mailIds.length) //领取单个邮件
|
||||
mails = await MailModel.updateMailStatus(mailIds, MAIL_STATUS.RECEIVED);
|
||||
let singlemails = await MailModel.findRewardsMails(roleId);
|
||||
let groupMails = await GroupMailModel.findRewardsMails(roleId);
|
||||
let servermails = await ServerMailModel.findRewardsMails(serverId, roleId);
|
||||
|
||||
for(let mail of singlemails) {
|
||||
mail = await MailModel.updateStatusWithCondition(mail._id, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.SINGLE, mail, roleId));
|
||||
}
|
||||
for(let mail of groupMails) {
|
||||
mail = await GroupMailModel.updateStatusWithCondition(mail._id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.GROUP, mail, roleId));
|
||||
}
|
||||
for(let mail of servermails) {
|
||||
mail = await ServerMailModel.updateStatusWithCondition(mail._id, roleId, MAIL_STATUS.RECEIVED, [MAIL_STATUS.READ, MAIL_STATUS.CREATE]);
|
||||
if(mail) mails.push(new MailParam(GM_MAIL_TYPE.SERVER, mail, roleId));
|
||||
}
|
||||
}
|
||||
let resGoods = [];
|
||||
if (!!mailGoods && !!mailGoods.length)
|
||||
resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
let mailGoods: RewardInter[] = [];
|
||||
for(let mail of mails) {
|
||||
mailGoods.push(...mail.goods)
|
||||
}
|
||||
let resGoods = await addItems(roleId, roleName, sid, mailGoods);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { mails, goods: resGoods });
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { sendRolesMails } from '../../../services/mailService';
|
||||
// import { sendRolesMails } from '../../../services/mailService';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
export default function (app: Application) {
|
||||
return new RoleRemote(app);
|
||||
@@ -16,9 +16,9 @@ export class RoleRemote {
|
||||
private channelService: ChannelService;
|
||||
|
||||
|
||||
sendGmMailsToRoles(mails) {
|
||||
sendRolesMails(mails)
|
||||
}
|
||||
// sendGmMailsToRoles(mails) {
|
||||
// sendRolesMails(mails)
|
||||
// }
|
||||
|
||||
/**
|
||||
* 重载json资源
|
||||
|
||||
Reference in New Issue
Block a user