邮件:修改邮件逻辑
This commit is contained in:
@@ -6,11 +6,7 @@ import { MonthlyTicketData } from '../../domain/activityField/monthlyTicketField
|
||||
import { addReward, stringToRewardInter, stringToRewardParam } from './giftPackageService';
|
||||
import moment = require('moment');
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { getMailContent } from './../mailService';
|
||||
import { MailModel, MailType } from '../../db/Mail';
|
||||
import { pushMail } from '../../pubUtils/interface';
|
||||
import { pinus } from 'pinus';
|
||||
import { resResult } from '../../pubUtils/util';
|
||||
import { sendMailByContent } from './../mailService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -38,17 +34,10 @@ export async function monthlyTicketActivity(serverId: number, roleId: string, ty
|
||||
if ((playerData.price > 0 && playerData.isOpen) || playerData.price === 0) {
|
||||
if (playerData.todayIndex - 1 > playerData.dayIndex) {//过期还没领取
|
||||
//下发邮件奖励
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = new Array<pushMail>();
|
||||
for (let i = playerData.dayIndex + 1; i < playerData.todayIndex; i++) {
|
||||
let goods = stringToRewardInter(playerData.baseReward)
|
||||
await getMailContent(roleId, MAIL_TYPE.MONTHLY_REWARD, [], goods, mails, pushMessage);
|
||||
await sendMailByContent(MAIL_TYPE.MONTHLY_REWARD, roleId, { params: [], goods });
|
||||
}
|
||||
|
||||
await MailModel.addMails(mails);
|
||||
pushMessage.forEach(({ route, data, uids }) => {
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
||||
});
|
||||
await ActivityMonthlyTicketModel.setDayIndex(serverId, roleId, playerData.activityId, playerData.todayIndex - 1);
|
||||
playerData.dayIndex = playerData.todayIndex - 1;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getZeroPointD, getTimeFunD } from '../pubUtils/timeUtil';
|
||||
import { gameData, getGoodById } from '../pubUtils/data';
|
||||
import { DividendParam, DividendType } from '../db/Dividend';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { getMailContent } from './mailService';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { pinus, BackendSession, FrontendOrBackendSession } from 'pinus';
|
||||
import { participants } from './guildActivityService';
|
||||
import { Member } from '../domain/battleField/guildActivity';
|
||||
@@ -261,16 +261,14 @@ export async function sendUngotDividend(debug = false) {
|
||||
}
|
||||
}
|
||||
|
||||
let mails: MailType[] = [];
|
||||
let pushMessage: pushMail[] = [];
|
||||
for (let [roleId, count] of rewards) {
|
||||
// TODO: 邮件类型修改
|
||||
await getMailContent(roleId, MAIL_TYPE.GUILD_BOSS_REWARD, [JSON.stringify(count)], [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count }], mails, pushMessage);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BOSS_REWARD, roleId, {
|
||||
params: [JSON.stringify(count)],
|
||||
goods: [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count }]
|
||||
});
|
||||
}
|
||||
await MailModel.addMails(mails);
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
||||
});
|
||||
|
||||
debug === true ? await updateDebugDividendsStatus(DIVIDEND_STATUS.SENT) : await updateOfficialDividendsStatus(DIVIDEND_STATUS.SENT);
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import { getGuildChannelSid, getWorldChannelSid, getCityChannelSid } from "./cha
|
||||
import { pinus } from "pinus";
|
||||
import { GuildActivityRecordModel } from "../db/GuildActivityRec";
|
||||
import { genAuction } from "./auctionService";
|
||||
import { sendMail } from "./mailService";
|
||||
import { sendMailByContent } from "./mailService";
|
||||
import { getHonourObject } from '../pubUtils/itemUtils';
|
||||
import { GuildActivityCityType, GuildActivityCityModel } from "../db/GuildActivityCity";
|
||||
import { DicCityActivity } from "../pubUtils/dictionary/DicCityActivity";
|
||||
@@ -417,7 +417,7 @@ export async function gateActivitySettleReward(guildCode: string, serverId: numb
|
||||
|
||||
async function updateUserRecAndSendHonour(honour: number, myScore: number, rank: number, roleId: string, members: Member[]) {
|
||||
let honourObj = getHonourObject(Math.floor(honour));
|
||||
await sendMail(MAIL_TYPE.GUILD_ACTIVITY_REWARD, roleId, '系统', [], [honourObj])
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_ACTIVITY_REWARD, roleId, { goods: [honourObj] })
|
||||
|
||||
await UserGuildActivityRecModel.updateInfoByRoleId(roleId, { score: myScore, rank });
|
||||
let index = members.findIndex(cur => cur.roleId == roleId);
|
||||
|
||||
@@ -2,14 +2,14 @@ import { BossInstanceType, BossInstanceModel } from '../db/BossInstance';
|
||||
import { getZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { lockData } from '../services/redLockService';
|
||||
import { findIndex } from 'underscore';
|
||||
import { MailModel, MailType } from '../db/Mail';
|
||||
import { MailType } from '../db/Mail';
|
||||
import { sismemberAsync, smembersAsync, saddAsync, delAsync, getRoleOnlineInfo } from '../services/redisService';
|
||||
import { pinus } from 'pinus';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { deepCopy, resResult } from '../pubUtils/util';
|
||||
import { BattleRecordModel } from '../db/BattleRecord';
|
||||
import { getArmyBossRank, gameData } from '../pubUtils/data';
|
||||
import { getMailContent } from '../services/mailService';
|
||||
import { sendMailByContent } from '../services/mailService';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { MAIL_TYPE, AUCTION_SOURCE } from '../consts';
|
||||
import { GUILD_BOSS_STATUS } from '../consts/constModules/guildConst';
|
||||
@@ -133,11 +133,9 @@ export async function bossResult(code: string, serverId: number, dataName: strin
|
||||
let goods = getArmyBossRankReward(rankLv);
|
||||
if (!goods || !goods.length)
|
||||
return;
|
||||
await getMailContent(roleId, MAIL_TYPE.GUILD_BOSS_REWARD, [JSON.stringify(rankLv)], goods, mails, pushMessage);
|
||||
});
|
||||
await MailModel.addMails(mails);
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BOSS_REWARD, roleId, {
|
||||
params: [JSON.stringify(rankLv)], goods
|
||||
})
|
||||
});
|
||||
// 加入拍卖行
|
||||
let dicBossBase = gameData.bossBaseByBossLv.get(bossLv);
|
||||
|
||||
@@ -9,14 +9,10 @@ import { SystemConfigModel } from "../db/SystemConfig";
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { pinus, BackendSession, FrontendOrBackendSession } from "pinus";
|
||||
import { ARMY } from "../pubUtils/dicParam";
|
||||
import { sendMail } from "./mailService";
|
||||
import { sendMailByContent } from "./mailService";
|
||||
import { initSingleRank, getRoleOnlineInfo, updateUserInfo, isRoleOnline } from "./redisService";
|
||||
import { GuildRankParam, GuildLeader } from "../domain/rank";
|
||||
import { lockData, lockDataNoRetry } from '../services/redLockService';
|
||||
import { ErrLogModel } from '../db/ErrLog';
|
||||
import { MailType, MailModel } from '../db/Mail';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { getMailContent } from '../services/mailService';
|
||||
import { DATA_NAME } from '../consts/dataName';
|
||||
import { addRoleToGuildChannel } from "./chatService";
|
||||
import { Rank } from "./rankService";
|
||||
@@ -223,25 +219,20 @@ export async function getUserGuildWithRefActive(roleId: string, select?: string,
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now);
|
||||
if (isRefDaily) {
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = new Array<pushMail>();
|
||||
wishGoods.map(async function ({ donateNames, goodId, drawCnt }) {
|
||||
let goodInfo = getGoodById(goodId)
|
||||
if (!goodInfo)
|
||||
return;
|
||||
for (let i = 0; i < drawCnt; i++) {
|
||||
let donateName = donateNames[donateNames.length - i - 1];
|
||||
await getMailContent(roleId, MAIL_TYPE.WISH_POOL_REWARD, [donateName, goodInfo.name], [{ id: goodId, count: drawCnt }], mails, pushMessage);
|
||||
}
|
||||
});
|
||||
if (!!mails.length) {
|
||||
await MailModel.addMails(mails);
|
||||
if (!notPush) {
|
||||
pushMessage.forEach(({ route, data, uids }) => {
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
||||
await sendMailByContent(MAIL_TYPE.WISH_POOL_REWARD, roleId, {
|
||||
params: [donateName, goodInfo.name],
|
||||
goods: [{ id: goodId, count: drawCnt }],
|
||||
notPush
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = []; wishGoods = [];
|
||||
let receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt }, {}, select);
|
||||
@@ -304,7 +295,7 @@ export async function settleGuildWeekly() {
|
||||
count: Math.ceil(cur.count * jobActiveRatio)
|
||||
}
|
||||
});
|
||||
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, { goods: reward });
|
||||
// 任务
|
||||
await checkTask(roleId, null, null, TASK_TYPE.GUILD_JOB, 1, false, { job });
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ import { resResult, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { GuildTrainReportModel } from '../db/GuildTrainReport';
|
||||
import { DATA_NAME } from '../consts/dataName';
|
||||
import { getMailContent } from './mailService';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { MAIL_TYPE } from '../consts';
|
||||
import { getGuildChannelSid } from './chatChannelService';
|
||||
/**
|
||||
* 获得userGuild,并检查,是否需要每日重置购买挑战次数和今日挑战次数,已经检查是否需要每周重置练兵场
|
||||
* @param roleId
|
||||
@@ -151,8 +152,7 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
}
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'trainRewards', {});
|
||||
const guildTrains = await GuildTrainModel.getGuildTrainBoxs(code);
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = [];
|
||||
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(GUILD_STRUCTURE.TRAIN);
|
||||
//结算未领取的宝箱奖励发送到邮件中
|
||||
userGuildList.forEach(async function ({roleId, trainRewards}) {
|
||||
@@ -177,14 +177,15 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
}
|
||||
}
|
||||
if (!!goods.length) {
|
||||
await getMailContent(roleId, MAIL_TYPE.GUILD_TRAIN_REWARD, [], goods, mails, pushMessage);
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_TRAIN_REWARD, roleId, {
|
||||
params: [], goods
|
||||
});
|
||||
}
|
||||
});
|
||||
await MailModel.addMails(mails);
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails:data }), uids);
|
||||
pinus.app.channelService.pushMessageByUids('onGuildTainReset', resResult(STATUS.SUCCESS, {}), uids);//通知在线玩家练兵场重置,
|
||||
});
|
||||
|
||||
let chatSid = await getGuildChannelSid(code);
|
||||
pinus.app.rpc.chat.guildRemote.sendTrainReset.toServer(chatSid, code);
|
||||
|
||||
await GuildTrainModel.resetGuildTrain(code);//将开启的练兵场锁定
|
||||
await unlockTrain(code, 1);//开启练兵场1级
|
||||
await UserGuildModel.resetTrainUserGuild(code);//重置玩家的挑战次数和购买挑战次数
|
||||
|
||||
@@ -1,190 +1,206 @@
|
||||
import { RewardInter, pushMail, mailData } from "../pubUtils/interface";
|
||||
import { MailModel, MailType } from "../db/Mail";
|
||||
import { GroupMailModel, GroupMailType } from "../db/GroupMail";
|
||||
import { ServerMailModel, ServerMailType } from '../db/ServerMail';
|
||||
import { getRoleOnlineInfo } from "./redisService";
|
||||
import { pinus } from "pinus";
|
||||
import { gameData } from "../pubUtils/data";
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { GroupMailModel, GroupMailType } from "../db/GroupMail";
|
||||
import { findWhere } from "underscore";
|
||||
import { MAIL_TYPE, MAIL_TEM_TYPE, GM_MAIL_TYPE, MAIL_STATUS } from "../consts/constModules/mailConst";
|
||||
import { DATA_NAME } from '../consts/dataName';
|
||||
import { lockData } from './redLockService';
|
||||
import { GM_MAIL_TYPE, MAIL_STATUS, MAIL_TYPE, SEND_NAME } from "../consts";
|
||||
import { MailParam } from '../domain/roleField/mail';
|
||||
import { GMMailType, GMMailModel } from "../db/GMMail";
|
||||
import { getGuildChannelSid, getWorldChannelSid } from "./chatChannelService";
|
||||
|
||||
/**
|
||||
* 下发邮件
|
||||
* @param operate
|
||||
* @param toRoleId
|
||||
* @param sendName
|
||||
* @param params
|
||||
* @param goods
|
||||
* @param sendTime
|
||||
*/
|
||||
export async function sendMail(operate: number, toRoleId: string, sendName: string = '系统', params: string[] = [], goods: RewardInter[] = [], sendTime: number = nowSeconds()) {
|
||||
let { content, time } = getContent(operate, params);
|
||||
if (!content)
|
||||
return;
|
||||
let mail = await MailModel.addMail({roleId: toRoleId, sendTime, goods, sendName, mailId: JSON.stringify(operate), endTime: time + nowSeconds(), mailTemType: MAIL_TEM_TYPE.GAMEMAIL, params});
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(toRoleId);
|
||||
if(hisOnlineInfo.isOnline) {
|
||||
let sid = hisOnlineInfo.sid;
|
||||
if (!!sid) {//下发邮件,对应前端红点提示
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails:[{
|
||||
id: mail._id, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
}]}), [{uid: toRoleId, sid}]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 封装玩家的邮件内容
|
||||
* @param operate
|
||||
* @param params
|
||||
*/
|
||||
export function getContent(operate: number, params: string[]) {
|
||||
let mail = gameData.mail.get(operate);
|
||||
if (!mail)
|
||||
return {};
|
||||
let { content, time } = mail;
|
||||
content = content||'%d';
|
||||
for(let p of params) {
|
||||
content = content.replace(/%d/, p);
|
||||
}
|
||||
return { content, time }
|
||||
}
|
||||
/**
|
||||
* 封装获得邮件的下发信息,以及需要添加的邮件信息
|
||||
* @param roleId
|
||||
* @param operate
|
||||
* @param params
|
||||
* @param goods
|
||||
* @param mails
|
||||
* @param pushMessage
|
||||
* @param sendTime
|
||||
* @param sendName
|
||||
*/
|
||||
export async function getMailContent(roleId: string, operate: number, params: string[], goods: RewardInter[], mails: MailType[], pushMessage: pushMail[], sendTime?:number, sendName: string = '系统') {
|
||||
const doc = new MailModel();
|
||||
let { content, time } = getContent(operate, params);
|
||||
if (!content)
|
||||
return;
|
||||
const mail = Object.assign(doc.toJSON(), { roleId, goods, sendName, mailId: operate, sendTime: sendTime||nowSeconds(), mailTemType: MAIL_TEM_TYPE.GAMEMAIL, endTime: time + nowSeconds(), params });
|
||||
mails.push(mail);
|
||||
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(roleId);
|
||||
if(hisOnlineInfo.isOnline) {
|
||||
let sid = hisOnlineInfo.sid;
|
||||
if (!!sid) {
|
||||
pushMessage.push({route: 'onMailsAdd', data:[{
|
||||
id: mail._id, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
}], uids: [{ uid: roleId, sid }]});
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查上次刷新过后至今 gm后台是否有新邮件下发给玩家
|
||||
* @param roleId
|
||||
* @param sid
|
||||
* @param serverId
|
||||
* @param updatedMailAt
|
||||
*/
|
||||
export async function refreshMails(roleId: string, sid: string, serverId: number, updatedMailAt: number) {
|
||||
let res:any = await lockData(serverId, DATA_NAME.GAMEMAIL, roleId);//加锁
|
||||
let gmMails = await pinus.app.rpc.gm.gmRemote.getMailsByTime.toServer('gm-server-1', updatedMailAt, serverId);
|
||||
let addGroupMails: GroupMailType[] = [];
|
||||
let addMails: MailType[] = [];
|
||||
let updateMails: mailData[] = [];
|
||||
let pushMails: mailData[] = [];
|
||||
for (let { gmMailType, id: mailId, sendRoles, endTime, content, goods, sendTime, sendName } of gmMails) {
|
||||
if (gmMailType == GM_MAIL_TYPE.GROUPMAIL) { //检查gm群体邮件是否需要加入
|
||||
let mail = await GroupMailModel.getMail(mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
if (!mail) {
|
||||
const doc = new GroupMailModel();
|
||||
const mail = Object.assign(doc.toJSON(), { mailId, mailTemType: MAIL_TEM_TYPE.GMTYPE, sendRoles, sendName });
|
||||
addGroupMails.push(mail);
|
||||
pushMails.push({ id: mail._id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
} else {
|
||||
let { sendRoles } = mail;
|
||||
let sendRole = findWhere(sendRoles, {roleId});
|
||||
if (!sendRole) {
|
||||
await GroupMailModel.pushRoleMail(roleId, mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
pushMails.push({ id: mail._id, goods, sendTime, endTime, content, status: MAIL_STATUS.CREATE, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
}
|
||||
}
|
||||
} else if (gmMailType == GM_MAIL_TYPE.SERVER) { //检查gm服邮件是否需要加入
|
||||
let mail = await MailModel.getMail(roleId, mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
if (!mail) {
|
||||
const doc = new MailModel();
|
||||
const mail = Object.assign(doc.toJSON(), { mailId, mailTemType: MAIL_TEM_TYPE.GMTYPE, roleId, sendName });
|
||||
addMails.push(mail);
|
||||
pushMails.push({ id: mail._id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
} else {
|
||||
//若加入过,可能修改过奖励内容等信息,更新一下邮件的内容
|
||||
updateMails.push({ id: mail._id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName })
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!!updateMails.length) {//下发邮件修改推送
|
||||
pinus.app.channelService.pushMessageByUids('onMailsUpdate', resResult(STATUS.SUCCESS, { mails: updateMails }), [{uid: roleId, sid}]);
|
||||
}
|
||||
if (!!addGroupMails.length) {
|
||||
await GroupMailModel.addGroupMails(addGroupMails);
|
||||
}
|
||||
if (!!addMails.length) {
|
||||
await MailModel.addMails(addMails);
|
||||
}
|
||||
if (!!pushMails.length) {
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: pushMails}), [{uid: roleId, sid}]);//下发邮件,对应前端红点提示
|
||||
}//下发邮件,对应前端红点提示
|
||||
res.releaseCallback();
|
||||
return nowSeconds();
|
||||
}
|
||||
/**
|
||||
* 获取邮件信息,gm邮件需要从gm-server-1缓存中读取
|
||||
* @param roleId
|
||||
* @param serverId
|
||||
* 获取邮件信息
|
||||
* @param {String} roleId 玩家id
|
||||
* @param {Number} serverId 服务器id
|
||||
*/
|
||||
export async function getMails(roleId: string, serverId: number) {
|
||||
let mails = await MailModel.getMailsByRoleId(roleId)||[];
|
||||
let groupMails = await GroupMailModel.getGroupMailsByRoleId(roleId)||[];
|
||||
let list: mailData[] = await pinus.app.rpc.gm.gmRemote.getMailInfos.toServer('gm-server-1', roleId, serverId, mails, groupMails);
|
||||
let mails = await MailModel.findByRoleId(roleId)||[];
|
||||
let groupMails = await GroupMailModel.findByRoleId(roleId)||[];
|
||||
let serverMails = await ServerMailModel.findByRoleId(roleId, serverId)||[];
|
||||
|
||||
let list = getMailInfos(roleId, mails, groupMails, serverMails);
|
||||
list.sort((a, b) => a.sendTime - b.sendTime);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发gm邮件的群体邮件
|
||||
* @param mails
|
||||
* 根据数据库数据,生成返回数据
|
||||
* @param {String} roleId 玩家id
|
||||
* @param {MailType[]} mails 单人邮件
|
||||
* @param {GroupMailType[]} groupMails 多人邮件
|
||||
* @param {ServerMailType[]} serverMails 全服邮件
|
||||
*/
|
||||
export async function sendRolesMails(mails) {
|
||||
let addGroupMails: GroupMailType[] = [];
|
||||
let pushMessage: pushMail[] = [];
|
||||
for (let { gmMailType, id: mailId, sendRoles, endTime, content, goods, sendTime, sendName } of mails) {
|
||||
let uids = [];
|
||||
if (endTime < nowSeconds()|| sendTime > nowSeconds())
|
||||
continue;
|
||||
if (gmMailType != GM_MAIL_TYPE.GROUPMAIL) //不是群体邮件说明是全服邮件,不进行下发
|
||||
return;
|
||||
let mail = await GroupMailModel.getMail(mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
if (!mail) {
|
||||
const doc = new GroupMailModel();
|
||||
mail = Object.assign(doc.toJSON(), { mailId, mailTemType: MAIL_TEM_TYPE.GMTYPE, sendRoles, sendName });
|
||||
addGroupMails.push(mail);
|
||||
} else {
|
||||
return;
|
||||
function getMailInfos(roleId: string, mails: MailType[], groupMails: GroupMailType[], serverMails: ServerMailType[]) {
|
||||
let list: MailParam[] = []; // 结果
|
||||
for(let mail of mails) {
|
||||
list.push(new MailParam( GM_MAIL_TYPE.SINGLE, mail, roleId));
|
||||
}
|
||||
for(let mail of groupMails) {
|
||||
list.push(new MailParam(GM_MAIL_TYPE.GROUP, mail, roleId));
|
||||
}
|
||||
for(let mail of serverMails) {
|
||||
list.push(new MailParam(GM_MAIL_TYPE.SERVER, mail, roleId));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
export async function sendMailByContent(contentId: MAIL_TYPE, hisRoleId: string, params: { sendName?: string, endTime?: number, params?: string[], goods?: RewardInter[], notPush?: boolean }) {
|
||||
let f = new SendMailFun();
|
||||
f.setWithContentId(contentId, params);
|
||||
await f.sendToUsers(GM_MAIL_TYPE.SINGLE, [hisRoleId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件方法类
|
||||
*/
|
||||
export class SendMailFun {
|
||||
private mailType: GM_MAIL_TYPE = GM_MAIL_TYPE.SINGLE; // 邮件类型 1-单人 2-多人 3-全服
|
||||
private contentId: MAIL_TYPE = MAIL_TYPE.SEND_MAIL; // 0-读GmMail,1以上读dicMail
|
||||
private params: string[] = [];
|
||||
private sendName: string = SEND_NAME;
|
||||
private gmmail: GMMailType;
|
||||
private hasGoods: boolean = false; // 是否内含奖励
|
||||
private goods: RewardInter[] = []; // 发送的奖励
|
||||
private sendTime: number;
|
||||
private endTime: number;
|
||||
private notPush: boolean = false;
|
||||
|
||||
// 从dicMail读取数据
|
||||
public setWithContentId(contentId: MAIL_TYPE, params: { sendName?: string, endTime?: number, params?: string[], goods?: RewardInter[] }) {
|
||||
let dicMail = gameData.mail.get(contentId);
|
||||
this.contentId = contentId;
|
||||
this.sendTime = nowSeconds();
|
||||
this.endTime = this.sendTime + dicMail?.time||0;
|
||||
this.setParam({ ...params });
|
||||
}
|
||||
|
||||
// 从GMMail表读取数据
|
||||
public async setWithGmMail(gmmailId: string) {
|
||||
let gmmail = await GMMailModel.getGmMailById(gmmailId);
|
||||
if(gmmail) {
|
||||
this.gmmail = gmmail;
|
||||
this.sendTime = gmmail.sendTime;
|
||||
this.endTime = gmmail.endTime;
|
||||
this.setParam({ ...gmmail });
|
||||
}
|
||||
for (let { roleId } of sendRoles) {
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(roleId);
|
||||
if(hisOnlineInfo.isOnline && hisOnlineInfo.sid) {
|
||||
uids.push({sid: hisOnlineInfo.sid, uid: roleId});
|
||||
}
|
||||
|
||||
private setParam(params: { sendName?: string, endTime?: number, params?: string[], goods?: RewardInter[], content?: string }) {
|
||||
if(params.sendName) this.sendName = params.sendName;
|
||||
if(params.endTime) this.endTime = params.endTime;
|
||||
if(params.content) {
|
||||
this.params.push(params.content);
|
||||
}
|
||||
if(params.params) this.params = params.params;
|
||||
if(params.goods) {
|
||||
this.hasGoods = params.goods.length > 0;
|
||||
this.goods = params.goods;
|
||||
}
|
||||
}
|
||||
|
||||
private getCreateMailParams() {
|
||||
return {
|
||||
contentId: this.contentId,
|
||||
mail: this.gmmail?._id,
|
||||
sendTime: this.sendTime,
|
||||
endTime: this.endTime,
|
||||
params: this.params,
|
||||
goods: this.goods,
|
||||
sendName: this.sendName,
|
||||
hasGoods: this.hasGoods
|
||||
}
|
||||
}
|
||||
|
||||
// 生成单人邮件
|
||||
private async createSingleMails(roleIds: string[]) {
|
||||
let mails = new Map<string, MailParam>();
|
||||
for(let roleId of roleIds) {
|
||||
let originMail = await MailModel.addMail({ roleId, ...this.getCreateMailParams() });
|
||||
let mail = new MailParam(this.mailType, originMail);
|
||||
mails.set(roleId, mail);
|
||||
}
|
||||
|
||||
return mails;
|
||||
}
|
||||
|
||||
// 生成多人邮件
|
||||
private async createGroupMails(roleIds: string[]) {
|
||||
let roleStatus = roleIds.map(roleId => {
|
||||
return { roleId, status: MAIL_STATUS.CREATE }
|
||||
})
|
||||
let originMail = await GroupMailModel.addMail({ roleStatus, ...this.getCreateMailParams() });
|
||||
return new MailParam(this.mailType, originMail);
|
||||
}
|
||||
|
||||
// 生成全服邮件
|
||||
private async createServerMails(serverIds: number[]) {
|
||||
let mails = new Map<number, MailParam>();
|
||||
for(let serverId of serverIds) {
|
||||
let originMail = await ServerMailModel.addMail({ serverId, ...this.getCreateMailParams() });
|
||||
mails.set(serverId, new MailParam(this.mailType, originMail));
|
||||
}
|
||||
return mails
|
||||
}
|
||||
|
||||
// 向某几个玩家推送
|
||||
public async sendToUsers(mailType: GM_MAIL_TYPE.SINGLE|GM_MAIL_TYPE.GROUP,roleIds: string[], myRoleId?: string, mySid?: string) {
|
||||
this.mailType = mailType;
|
||||
let uids: { uid: string, sid: string }[] = []
|
||||
for(let roleId of roleIds) {
|
||||
let sid = '';
|
||||
if(roleId == myRoleId) {
|
||||
sid = mySid;
|
||||
} else {
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(roleId);
|
||||
if(hisOnlineInfo.isOnline) {
|
||||
sid = hisOnlineInfo.sid;
|
||||
}
|
||||
}
|
||||
if(sid) {
|
||||
uids.push({ uid: roleId, sid });
|
||||
}
|
||||
}
|
||||
pushMessage.push({route: 'onMailsAdd', data:[{
|
||||
id: mail._id, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: MAIL_STATUS.CREATE, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
}], uids});
|
||||
|
||||
if (uids.length > 0) {//下发邮件,对应前端红点提示
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
let mails = await this.createSingleMails(roleIds);
|
||||
for(let { uid, sid } of uids) {
|
||||
let mail = mails.get(uid);
|
||||
if(mail && !this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), [{ uid, sid }]);
|
||||
}
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
let mail = await this.createGroupMails(roleIds);
|
||||
if(!this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), uids);
|
||||
} else { // mailType错误
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!!addGroupMails.length) {
|
||||
await GroupMailModel.addGroupMails(addGroupMails);
|
||||
|
||||
// 向军团推送
|
||||
public async sendToGuild(guildCode: string, members: string[]) {
|
||||
this.mailType = GM_MAIL_TYPE.GROUP;
|
||||
let mails = await this.createGroupMails(members);
|
||||
let chatSid = await getGuildChannelSid(guildCode);
|
||||
if(!this.notPush) pinus.app.rpc.chat.guildRemote.sendMailToGuild.toServer(chatSid, guildCode, 'onMailsAdd', { mails });
|
||||
}
|
||||
|
||||
// 向全服推送
|
||||
public async sendToServer(serverIds: number[]) {
|
||||
this.mailType = GM_MAIL_TYPE.SERVER;
|
||||
let mails = await this.createServerMails(serverIds);
|
||||
for(let serverId of serverIds) {
|
||||
let mail = mails.get(serverId);
|
||||
if(mail && !this.notPush) {
|
||||
let chatSid = await getWorldChannelSid(serverId);
|
||||
pinus.app.rpc.chat.chatRemote.sendMail.toServer(chatSid, serverId, 'onMailsAdd', { mails: [mail] });
|
||||
}
|
||||
}
|
||||
}
|
||||
pushMessage.forEach( message=> {
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: message.data }), message.uids);
|
||||
});//下发邮件,对应前端红点提示
|
||||
}
|
||||
@@ -346,7 +346,9 @@ export function getLvByScore(heroScores: HeroScores[]) {
|
||||
}
|
||||
|
||||
export async function defaultHeroes ( role:RoleType, challengeCnt?:number, challengeRefTime?:number, isUpdate?: boolean) {
|
||||
let { heroes, isDefaultHero } = await PvpDefenseModel.findByRoleId(role.roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(role.roleId);
|
||||
if(!pvpDefense) return;
|
||||
let { heroes, isDefaultHero } = pvpDefense;
|
||||
if (!isUpdate && !isDefaultHero) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { FrontendOrBackendSession, pinus } from "pinus";
|
||||
import { refreshMails } from './mailService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { resResult, shouldRefresh, shouldRefreshWeek } from '../pubUtils/util';
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { RoleModel } from '../db/Role';
|
||||
// import { RoleModel } from '../db/Role';
|
||||
import { refDailyTask, refDailyTaskBox } from './taskService'
|
||||
|
||||
/**
|
||||
@@ -13,17 +12,8 @@ import { refDailyTask, refDailyTaskBox } from './taskService'
|
||||
export async function refresh(session: FrontendOrBackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const sid = session.get('sid');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let updatedMailAt: number = parseInt(session.get('updatedMailAt')); //记录上次更新gm邮件的时间
|
||||
let uids = [{uid: roleId, sid}];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPushCurrentTime', resResult(STATUS.SUCCESS, {time: Date.now()}), uids);
|
||||
let nowTime = nowSeconds();
|
||||
if (!!roleId && updatedMailAt < nowTime - 5) { //保持最少5秒间隙
|
||||
session.set('updatedMailAt', nowTime);
|
||||
session.push('updatedMailAt', () => {});
|
||||
RoleModel.updatedRoleMailAt(roleId, nowTime);
|
||||
await refreshMails(roleId, sid, serverId, updatedMailAt);
|
||||
}
|
||||
await refreshDaily(session);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank,
|
||||
import { deepCopy, resResult, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { getLvByScore } from './pvpService';
|
||||
import { getAllOnlineRoles, getAllServers, initSingleRank, delGuildActivityRank } from './redisService';
|
||||
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME } from '../consts';
|
||||
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME, SEND_NAME } from '../consts';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { MailModel, MailType } from '../db/Mail';
|
||||
import { pinus } from 'pinus';
|
||||
@@ -16,7 +16,7 @@ import { indexOf } from 'underscore';
|
||||
import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
|
||||
import { settleGuildWeekly } from './guildService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { getMailContent, sendMail } from './mailService';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { reportOnline } from '../pubUtils/httpUtil';
|
||||
import { UserModel } from '../db/User';
|
||||
import { getGuildActivityByDic, setMedianCe, sendEndMsgToAll, autoDeclare, sendGuildActivityStatus } from './guildActivityService';
|
||||
@@ -101,20 +101,11 @@ export async function setPvpSeasonResult(obj?:{ name:string, notSetNext?: boolea
|
||||
let lastPageNum = resultMaxRank.min % pageNum;
|
||||
for (let page = 0; page < maxPage + 1; page++) {
|
||||
let pvpDefenses = await PvpDefenseModel.getPvpDef(pageNum, page == maxPage?lastPageNum:page);
|
||||
let addMails = new Array<MailType>();
|
||||
let pushMessage = new Array<any>();
|
||||
for (let pvpDefense of pvpDefenses) {
|
||||
if (pvpDefense.seasonNum !== seasonNum) {
|
||||
await setPvpDefResultOnTime(pvpDefense, seasonNum, oldSeasonEndTime, addMails, pushMessage);
|
||||
await setPvpDefResultOnTime(pvpDefense, seasonNum, oldSeasonEndTime, obj?.notPush);
|
||||
}
|
||||
}
|
||||
await MailModel.addMails(addMails);
|
||||
if (obj?.notPush) {
|
||||
continue;
|
||||
}
|
||||
for (let message of pushMessage) {
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: message.data }), [{uid: message.uid, sid: message.sid}]);
|
||||
}
|
||||
}
|
||||
return { seasonNum, seasonEndTime, oldSeasonEndTime};
|
||||
}
|
||||
@@ -123,18 +114,22 @@ export async function setPvpSeasonResult(obj?:{ name:string, notSetNext?: boolea
|
||||
* @param pvpDefense
|
||||
* @param seasonNum
|
||||
* @param oldSeasonEndTime
|
||||
* @param addMails
|
||||
* @param pushMessage
|
||||
*/
|
||||
export async function setPvpDefResultOnTime(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number, addMails: Array<MailType>, pushMessage:Array<any>) {
|
||||
export async function setPvpDefResultOnTime(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number, notPush?: boolean) {
|
||||
//检查并返回排名结算以及武将功勋结算
|
||||
let { score, pLv, heroScores, challengeCnt, challengeRefTime, rankGoods, heroGoods, rankLv } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime);
|
||||
pvpDefense = await PvpDefenseModel.updateInfo(pvpDefense.roleId, {score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime});
|
||||
//下发邮件
|
||||
if (!!rankGoods.length) //排名奖励
|
||||
await getMailContent(pvpDefense.roleId, MAIL_TYPE.PVP_RANK_REWARD, [JSON.stringify(seasonNum), (rankLv>1000?'999+':JSON.stringify(rankLv))], rankGoods, addMails, pushMessage, oldSeasonEndTime);
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RANK_REWARD, pvpDefense.roleId, {
|
||||
params: [JSON.stringify(seasonNum), (rankLv>1000?'999+':JSON.stringify(rankLv))],
|
||||
goods: rankGoods, endTime: oldSeasonEndTime, notPush
|
||||
});
|
||||
if (!!heroGoods.length) //武将功勋奖励
|
||||
await getMailContent(pvpDefense.roleId, MAIL_TYPE.PVP_RESULT, [JSON.stringify(seasonNum)], heroGoods, addMails, pushMessage, oldSeasonEndTime);
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RESULT, pvpDefense.roleId, {
|
||||
params: [JSON.stringify(seasonNum)],
|
||||
goods: heroGoods, endTime: oldSeasonEndTime, notPush
|
||||
});
|
||||
return pvpDefense;
|
||||
}
|
||||
/**
|
||||
@@ -214,9 +209,9 @@ export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: num
|
||||
r.setRankWithRoleInfo(pvpDefense.roleId, pvpDefense.score, pvpDefense.updatedAt.getTime(), role, true);
|
||||
//下发邮件
|
||||
if (!!rankGoods.length)
|
||||
await sendMail(MAIL_TYPE.PVP_RANK_REWARD, roleId, '系统', [JSON.stringify(seasonNum), '999+'], rankGoods, oldSeasonEndTime);
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RANK_REWARD, roleId, { params: [JSON.stringify(seasonNum), '999+'], goods: rankGoods, endTime: oldSeasonEndTime });
|
||||
if (!!heroGoods.length)
|
||||
await sendMail(MAIL_TYPE.PVP_RESULT, roleId, '系统', [JSON.stringify(seasonNum)], heroGoods, oldSeasonEndTime);
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RESULT, roleId, { params: [JSON.stringify(seasonNum)], goods: heroGoods, endTime: oldSeasonEndTime });
|
||||
return pvpDefense;
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user