训练场宝箱展示bug
This commit is contained in:
@@ -20,6 +20,8 @@ import { lockData } from '../../../services/redLockService';
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
import { unlockTrain } from '../../../services/guildTrainService';
|
||||
import { removeBossRank } from '../../../services/guildBossService';
|
||||
import { removeTrainRank } from '../../../services/guildTrainService';
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
}
|
||||
@@ -601,7 +603,9 @@ export class GuildHandler {
|
||||
|
||||
const guild = await GuildModel.quit(code, roleId, serverId, role.ce, userGuild.auth == GUILD_AUTH.MANAGER);
|
||||
if(!guild) return resResult(STATUS.GUILD_QUIT_ERROR);
|
||||
|
||||
//删除排名信息
|
||||
await removeBossRank(code, roleId);
|
||||
await removeTrainRank(code, roleId, guild.trainId);
|
||||
// 添加动态
|
||||
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
|
||||
this.app.rpc.chat.guildRemote.addRec.toServer(CHAT_SERVER,rec);
|
||||
@@ -635,6 +639,10 @@ export class GuildHandler {
|
||||
|
||||
const guild = await GuildModel.quit(code, memberRoleId, serverId, role.ce, userGuild.auth == GUILD_AUTH.MANAGER);
|
||||
if(!guild) return resResult(STATUS.GUILD_KICK_ERROR);
|
||||
|
||||
//删除排名信息
|
||||
await removeBossRank(code, roleId);
|
||||
await removeTrainRank(code, roleId, guild.trainId);
|
||||
|
||||
this.app.rpc.chat.guildRemote.memberQuit.toServer(CHAT_SERVER,code, roleId, guild);
|
||||
|
||||
|
||||
@@ -85,13 +85,14 @@ export class GuildTrainHandler {
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = [];
|
||||
let isComplete = false;
|
||||
trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
if ( progress >= instance.progress) {
|
||||
isComplete = true;
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
}
|
||||
boxRewards.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
});
|
||||
if (flag) {
|
||||
@@ -150,13 +151,13 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
const battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
// if (!battleRecord || battleRecord.status != 0 || roleId != battleRecord.roleId || battleRecord.record.guildCode != code) {
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
// }
|
||||
if (!battleRecord || battleRecord.status != 0 || roleId != battleRecord.roleId || battleRecord.record.guildCode != code) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let time = Math.floor(battleRecord.createdAt.getTime()/1000);
|
||||
// if (userGuild.trainCount - 1 < 0) {
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
// }
|
||||
if (userGuild.trainCount - 1 < 0) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
if (time < getCurHourPoint(REFRESH_HOUR) && nowSeconds() > getCurHourPoint(REFRESH_HOUR)) {
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_RESETED);//关卡已经重置
|
||||
|
||||
@@ -87,7 +87,7 @@ export class WishPoolHandler {
|
||||
count = wishGoodsHero.count;
|
||||
}
|
||||
const id = genCode(6);
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id, donateNames:[]} }, 'wishGoods');
|
||||
return resResult(STATUS.SUCCESS, { wishGoods: resWishGoods });
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export class WishPoolHandler {
|
||||
if (wishGood.receiveCnt >= wishGood.count)
|
||||
return resResult(STATUS.HAS_RECEIVE_WISH_GOOD);//已经收到
|
||||
let { wishDntCnt } = await UserGuildModel.donateGoods(dntRoleId, 1, 'wishDntCnt');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.donateUpdate(wishRoleId, id, 'wishGoods');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.donateUpdate(wishRoleId, dntRoleName, id, 'wishGoods');
|
||||
let key = 'login_roleId_' + wishRoleId;
|
||||
let sid = await getRedis(key);
|
||||
let goods = await addItems(wishRoleId, role.roleName , sid , [{ id : wishGood.goodId, count: 1 }]);
|
||||
|
||||
@@ -78,7 +78,7 @@ export class GmHandler {
|
||||
return resResult(STATUS.SUCCESS, { msg: content });
|
||||
}
|
||||
|
||||
async addMail(msg: { endTime: number, serverId: number, sendName: string, content: string, goods, sendRoles:[{roleId: string, status: number}], gmMailType: number, sendTime: number, }) {
|
||||
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]);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Application, ChannelService } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { setGmMails, getGmMailById, getGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { setGmMails, getGmMailById, getGmMails, getGmUseMails } 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';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
export default function (app: Application) {
|
||||
return new GMRemote(app);
|
||||
}
|
||||
@@ -102,33 +103,38 @@ export class GMRemote {
|
||||
|
||||
public async 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}) {
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
if (endTime < nowTime)
|
||||
return;
|
||||
let { content } = getContent(parseInt(mailId), params);
|
||||
if (!content)
|
||||
return;
|
||||
list.push({ id: _id, mailId, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
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);
|
||||
let gmMail = getGmMailById(mailId, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return;
|
||||
let { goods, sendTime, content, endTime, sendName } = gmMail;
|
||||
list.push({ id: _id, mailId, 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 }) {
|
||||
let { status } = findWhere(sendRoles, {roleId});
|
||||
if (mailTemType == MAIL_TEM_TYPE.GAMEMAIL) { //模板邮件
|
||||
if (endTime < nowTime)
|
||||
return;
|
||||
let { content } = getContent( parseInt(mailId), params);
|
||||
if (!content)
|
||||
return;
|
||||
list.push({ id: _id, mailId, goods, sendTime, content, endTime, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
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);
|
||||
let gmMail = getGmMailById(mailId, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return;
|
||||
let { goods, sendTime, content, endTime, sendName } = gmMail;
|
||||
list.push({ id: _id, mailId, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
list.push({ id: _id, goods, sendTime, endTime, content, status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
}
|
||||
});
|
||||
return list;
|
||||
@@ -138,4 +144,18 @@ export class GMRemote {
|
||||
let gmMails = getGmMails(updatedMailAt, serverId);
|
||||
return gmMails;
|
||||
}
|
||||
public async getUseMails(serverId: number) {
|
||||
let gmMails = getGmUseMails(serverId);
|
||||
return gmMails;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param mailId
|
||||
* @param serverId
|
||||
* @param nowTime
|
||||
*/
|
||||
public getUseGmMailById(mailId: string, serverId: number, nowTime: number ) {
|
||||
let gmMail = getGmMailById(mailId, serverId, nowTime);
|
||||
return gmMail;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { findWhere } from 'underscore';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { getGmMailById } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
export default function(app: Application) {
|
||||
return new RoleHandler(app);
|
||||
}
|
||||
@@ -75,6 +76,7 @@ export class RoleHandler {
|
||||
let { id, type, mailType } = msg;
|
||||
let mailGoods = [];
|
||||
let mails = [];
|
||||
let nowTime: number = nowSeconds();
|
||||
if (type == 1) {//单个领取
|
||||
let mail;
|
||||
if (mailType == MAIL_TYPE.SINGLEMAIL) {
|
||||
@@ -88,38 +90,52 @@ export class RoleHandler {
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
mails.push({id, status: MAIL_STATUS.DELETE, mailType});
|
||||
mails.push({ id, status: MAIL_STATUS.RECEIVED, mailType });
|
||||
if (mail.mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
let gmMail = await this.app.rpc.gm.gmRemote.getUseGmMailById.toServer('gm-server-1', id, serverId, nowTime);
|
||||
if (!gmMail)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
mailGoods.push(...gmMail.goods);
|
||||
} else {
|
||||
mailGoods.push(...mail.goods);
|
||||
}
|
||||
} else {//一键领取
|
||||
let ids;
|
||||
let ids = [];
|
||||
let gmMails = await this.app.rpc.gm.gmRemote.getUseMails.toServer('gm-server-1', serverId);
|
||||
let groupMailRewards = await GroupMailModel.findRewardsMails(roleId);
|
||||
ids = groupMailRewards.map(({_id, goods, mailTemType})=>{
|
||||
groupMailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
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.DELETE, mailType: MAIL_TYPE.GROUPMAIL});
|
||||
return _id;
|
||||
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})=>{
|
||||
ids = [];
|
||||
mailRewards.map(({_id, goods, mailTemType})=>{
|
||||
if (mailTemType == MAIL_TEM_TYPE.GMTYPE) {
|
||||
let gmMail = getGmMailById(id, serverId);
|
||||
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.DELETE, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
return _id;
|
||||
mails.push({id, status: MAIL_STATUS.RECEIVED, mailType: MAIL_TYPE.SINGLEMAIL});
|
||||
ids.push(_id);
|
||||
});
|
||||
if (!!ids.length)
|
||||
await MailModel.updateMailStatus(ids, MAIL_STATUS.RECEIVED);
|
||||
|
||||
@@ -184,4 +184,12 @@ export async function checkMemberExists(code: string, serverId:number, roleId: s
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 成员退出,删除boss关排行信息
|
||||
* @param guildCode
|
||||
* @param roleId
|
||||
*/
|
||||
export async function removeBossRank(guildCode: string, roleId: string) {
|
||||
await BossInstanceModel.removeBossRank(guildCode, roleId);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { gameData, getGuildActiveWeekReward, getGuildActiveByIdAndType } from "../pubUtils/data";
|
||||
import { gameData, getGuildActiveWeekReward, getGuildActiveByIdAndType, getGoodById } from "../pubUtils/data";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS, MAIL_TYPE, GUILD_AUTH, GUILD_JOB, REDIS_KEY, CHAT_SERVER } from "../consts";
|
||||
@@ -179,15 +179,18 @@ export async function getUserGuildWithRefActive(roleId: string, select: string,
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
let goods = [];
|
||||
wishGoods.map(({ goodId, drawCnt})=>{
|
||||
if (drawCnt > 0)
|
||||
goods.push({id: goodId, count: drawCnt});
|
||||
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 (!!goods.length) {
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = new Array<pushMail>();
|
||||
await getMailContent(roleId, MAIL_TYPE.WISH_POOL_REWARD, [], goods, mails, pushMessage);
|
||||
if (!!mails.length) {
|
||||
await MailModel.addMails(mails);
|
||||
if (!notPush) {
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
|
||||
@@ -167,4 +167,15 @@ export async function checkesetTrain(roleId: string, serverId: number) {
|
||||
if (!userGuild)
|
||||
return;
|
||||
await resetTrain(userGuild.guildCode, serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成员退出删除排行奖励
|
||||
* @param guildCode
|
||||
* @param roleId
|
||||
* @param trainId
|
||||
*/
|
||||
export async function removeTrainRank(guildCode: string, roleId: string, trainId: number) {
|
||||
await GuildTrainModel.removeTrainRank(guildCode, roleId, trainId);
|
||||
|
||||
}
|
||||
@@ -11,16 +11,16 @@ 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';
|
||||
export async function sendMail(operate: number, toRoleId: string, sendName: string = '系统', params: string[] = [], goods: RewardInter[] = []) {
|
||||
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, goods, sendName, mailId: JSON.stringify(operate), endTime: time + nowSeconds(), mailTemType: MAIL_TEM_TYPE.GAMEMAIL, params});
|
||||
let mail = await MailModel.addMail({roleId: toRoleId, sendTime, goods, sendName, mailId: JSON.stringify(operate), endTime: time + nowSeconds(), mailTemType: MAIL_TEM_TYPE.GAMEMAIL, params});
|
||||
let key = 'login_roleId_' + toRoleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails:[{
|
||||
id: mail._id, mailId: mail.mailId, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
id: mail._id, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
}]}), [{uid: toRoleId, sid}]);
|
||||
}
|
||||
}
|
||||
@@ -37,18 +37,18 @@ export function getContent(operate: number, params: string[]) {
|
||||
return { content, time }
|
||||
}
|
||||
|
||||
export async function getMailContent(roleId: string, operate: number, params: string[], goods: RewardInter[], mails: MailType[], pushMessage: pushMail[], sendName: string = '系统') {
|
||||
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: nowSeconds(), mailTemType: MAIL_TEM_TYPE.GAMEMAIL, endTime: time + nowSeconds(), params });
|
||||
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 key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!sid) {
|
||||
pushMessage.push({route: 'onMailsAdd', data:[{
|
||||
id: mail._id, mailId: mail.mailId, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
id: mail._id, goods, sendTime: mail.sendTime, endTime: mail.endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName
|
||||
}], uids: [{ uid: roleId, sid }]});
|
||||
}
|
||||
}
|
||||
@@ -60,34 +60,34 @@ export async function refreshMails(roleId: string, sid: string, serverId: number
|
||||
let addMails: MailType[] = [];
|
||||
let updateMails: mailData[] = [];
|
||||
let pushMails: mailData[] = [];
|
||||
gmMails.forEach(async function ({gmMailType, _id, sendRoles, endTime, content, goods, sendTime, sendName}) {
|
||||
for (let {gmMailType, id: mailId, sendRoles, endTime, content, goods, sendTime, sendName } of gmMails) {
|
||||
if (gmMailType == GM_MAIL_TYPE.GROUPMAIL) { //群体邮件
|
||||
let mail = await GroupMailModel.getMail(_id, MAIL_TEM_TYPE.GMTYPE);
|
||||
let mail = await GroupMailModel.getMail(mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
if (!mail) {
|
||||
const doc = new GroupMailModel();
|
||||
const mail = Object.assign(doc.toJSON(), { mailId: _id, mailTemType: MAIL_TEM_TYPE.GMTYPE, sendRoles });
|
||||
const mail = Object.assign(doc.toJSON(), { mailId, mailTemType: MAIL_TEM_TYPE.GMTYPE, sendRoles, sendName });
|
||||
addGroupMails.push(mail);
|
||||
pushMails.push({ id: mail._id, mailId: _id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
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, _id, MAIL_TEM_TYPE.GMTYPE);
|
||||
pushMails.push({ id: mail._id, mailId: _id, goods, sendTime, endTime, content, status: MAIL_STATUS.CREATE, mailType: MAIL_TYPE.GROUPMAIL, sendName });
|
||||
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) { //游戏服邮件
|
||||
let mail = await MailModel.getMail(roleId, _id, MAIL_TEM_TYPE.GMTYPE);
|
||||
let mail = await MailModel.getMail(roleId, mailId, MAIL_TEM_TYPE.GMTYPE);
|
||||
if (!mail) {
|
||||
const doc = new MailModel();
|
||||
const mail = Object.assign(doc.toJSON(), { mailId: _id, mailTemType: MAIL_TEM_TYPE.GMTYPE, roleId });
|
||||
const mail = Object.assign(doc.toJSON(), { mailId, mailTemType: MAIL_TEM_TYPE.GMTYPE, roleId, sendName });
|
||||
addMails.push(mail);
|
||||
pushMails.push({ id: mail._id, mailId: _id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
pushMails.push({ id: mail._id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName });
|
||||
} else {
|
||||
updateMails.push({ id: mail._id, mailId: _id, goods, sendTime, endTime, content, status: mail.status, mailType: MAIL_TYPE.SINGLEMAIL, sendName })
|
||||
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}]);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,22 @@ import { refreshMails } from '../services/mailService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
|
||||
import { RoleModel } from '../db/Role';
|
||||
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')) || 0;
|
||||
let updatedMailAt: number = parseInt(session.get('updatedMailAt'));
|
||||
if (!updatedMailAt) {
|
||||
let { updatedMailAt: updatedTime } = await RoleModel.findByRoleId(roleId, 'updatedMailAt');
|
||||
updatedMailAt = updatedTime;
|
||||
}
|
||||
let uids = [{uid: roleId, sid}];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPushCurrentTime', resResult(STATUS.SUCCESS, {time: Date.now()}), uids);
|
||||
if (!!roleId && updatedMailAt < nowSeconds() - 5) { //保持最少5秒间隙
|
||||
session.set('updatedMailAt', nowSeconds());
|
||||
let nowTime = nowSeconds();
|
||||
if (!!roleId && updatedMailAt < nowTime - 5) { //保持最少5秒间隙
|
||||
session.set('updatedMailAt', nowTime);
|
||||
RoleModel.updatedRoleMailAt(roleId, nowTime);
|
||||
await refreshMails(roleId, sid, serverId, updatedMailAt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,17 +86,19 @@ export async function setPvpSeasonResult(obj:{ name:string, notSetNext?: boolean
|
||||
}
|
||||
|
||||
export async function setPvpDefResultOnTime(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number, addMails: Array<MailType>, pushMessage:Array<any>) {
|
||||
let { score, pLv, heroScores, challengeCnt, challengeRefTime, goods } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime);
|
||||
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});
|
||||
//下发邮件
|
||||
await getMailContent(pvpDefense.roleId, MAIL_TYPE.PVP_RANK_REWARD, [], goods, addMails, pushMessage);
|
||||
if (!!rankGoods.length)
|
||||
await getMailContent(pvpDefense.roleId, MAIL_TYPE.PVP_RANK_REWARD, [JSON.stringify(seasonNum), JSON.stringify(rankLv)], rankGoods, addMails, pushMessage, oldSeasonEndTime);
|
||||
if (!!heroGoods.length)
|
||||
await getMailContent(pvpDefense.roleId, MAIL_TYPE.PVP_RESULT, [JSON.stringify(seasonNum)], heroGoods, addMails, pushMessage, oldSeasonEndTime);
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime:number, rankLv?:number) {
|
||||
let pvpRankRewards = getPvpRankRewards();
|
||||
let pvpHeroRewards = getPvpHeroRewards();
|
||||
let goods = [];
|
||||
if (!rankLv) {
|
||||
rankLv = await getMyRank(REDIS_KEY.PVP_RANK, 0, pvpDefense.roleId);// 排行榜排名
|
||||
}
|
||||
@@ -110,7 +112,6 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
}
|
||||
let rankGoods = [];
|
||||
if(pvpRankReward) {
|
||||
goods = goods.concat(pvpRankReward.reward);
|
||||
rankGoods = pvpRankReward.reward;
|
||||
}
|
||||
let heroGoods = [];
|
||||
@@ -120,7 +121,6 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
let heroScore = pvpDefense.heroScores[i];
|
||||
let pvpHeroReward = getScore(pvpHeroRewards, heroScore.score);
|
||||
if (pvpHeroReward) {
|
||||
goods = goods.concat(pvpHeroReward.reward);
|
||||
heroScore.score = pvpHeroReward.heroscore;
|
||||
if (!!pvpHeroReward.reward[0]) {
|
||||
heroGoods.push({
|
||||
@@ -137,7 +137,9 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
oldSeasonData:{refOppCnt: pvpDefense.refOppCnt, rankLv, score: pvpDefense.score, pLv: oldPLv, heroScores: oldHeroScores,
|
||||
seasonNum: pvpDefense.seasonNum, challengeCnt, challengeRefTime, seasonEndTime: oldSeasonEndTime
|
||||
}, heroGoods, rankGoods, show: true });
|
||||
return { rankLv, score, pLv, heroScores: pvpDefense.heroScores, seasonNum, challengeCnt:PVP.PVP_CHALLENGE_COUNTS, challengeRefTime:0, oldSeasonEndTime, goods};
|
||||
return { rankLv, score, pLv, heroScores: pvpDefense.heroScores, seasonNum, challengeCnt:PVP.PVP_CHALLENGE_COUNTS, challengeRefTime:0, oldSeasonEndTime, heroGoods:heroGoods.map(({id, count})=>{
|
||||
return {id, count};
|
||||
}), rankGoods};
|
||||
}
|
||||
|
||||
export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime:number) {
|
||||
@@ -147,13 +149,16 @@ export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: num
|
||||
}
|
||||
let resultMaxRank = getResultMaxRank();
|
||||
let rankLv = resultMaxRank.min;
|
||||
let {score, pLv, heroScores, challengeCnt, challengeRefTime, goods } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime, rankLv);
|
||||
let {score, pLv, heroScores, challengeCnt, challengeRefTime, rankGoods, heroGoods } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime, rankLv);
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(pvpDefense.roleId, {score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime});
|
||||
let { roleName, lv, vLv, headHid, sHid, title , roleId } = role;
|
||||
let params = new RankParam(roleName, lv, vLv, headHid, sHid, title);
|
||||
setRank(REDIS_KEY.PVP_RANK, 0, roleId, pvpDefense.score, pvpDefense.updatedAt.getTime(), params);
|
||||
//下发邮件
|
||||
await sendMail(MAIL_TYPE.PVP_RANK_REWARD, roleId, '系统', [], goods);
|
||||
if (!!rankGoods.length)
|
||||
await sendMail(MAIL_TYPE.PVP_RANK_REWARD, roleId, '系统', [JSON.stringify(seasonNum), JSON.stringify(pLv)], rankGoods, oldSeasonEndTime);
|
||||
if (!!heroGoods.length)
|
||||
await sendMail(MAIL_TYPE.PVP_RESULT, roleId, '系统', [JSON.stringify(seasonNum)], heroGoods, oldSeasonEndTime);
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user