训练场宝箱展示bug

This commit is contained in:
mamengke01
2021-02-06 11:55:36 +08:00
parent d9bea0444c
commit d9458ede5f
22 changed files with 246 additions and 108 deletions

View File

@@ -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);

View File

@@ -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);//关卡已经重置

View File

@@ -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 }]);

View File

@@ -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]);

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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 })=>{

View File

@@ -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);
}

View File

@@ -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}]);
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -91,6 +91,12 @@ export default class BossInstance extends BaseModel {
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode, 'ranks.roleId': roleId }, { $set:{ 'ranks.$.time': nowSeconds() } }, { new: true }).lean(lean);
return bossInstance;
}
public static async removeBossRank(guildCode: string, roleId: string, lean = true) {
const guildTrain: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode },
{ $pull:{ ranks: { roleId } }}, {new: true}).lean(lean);
return guildTrain;
}
}
export const BossInstanceModel = getModelForClass(BossInstance);

View File

@@ -18,7 +18,7 @@ export default class GMMail extends BaseModel {
@prop({ required: true })
serverId: number;
@prop({ required: true })
@prop({ required: true, type: SendRole, default:[], _id: false })
sendRoles: SendRole[];
@prop({ required: true, type: RewardInter, default: [], _id: false })
@@ -39,10 +39,10 @@ export default class GMMail extends BaseModel {
@prop({ required: true })
gmMailType: number; //1:群体邮件2分服务器邮件
public static async addMail(params: {serverId: number, sendRoles: SendRole[], sendName: string, endTime: number, content: string, gmMailType: number, sendTime?: number, goods?: RewardInter[] }) {
public static async addMail(params: {serverId: number, sendRoles: SendRole[], sendName: string, endTime: number, content: string, gmMailType: number, sendTime?: number, goods?: RewardInter[] }, lean = true) {
const doc = new GMMailModel();
const mail = Object.assign(doc.toJSON(), params);
await GMMailModel.create(mail);
let mail = Object.assign(doc.toJSON(), params);
mail = await GMMailModel.findOneAndUpdate({ _id: mail._id }, { $set: mail }, {upsert: true, new: true}).lean(lean);
return mail;
}

View File

@@ -17,7 +17,7 @@ class SendRole {
@index({ sendRoles: 1 })
@index({ mailId: 1, type: 1 })
export default class GroupMail extends BaseModel {
@prop({ required: true })
@prop({ required: true, type: SendRole, default: [], _id: false })
sendRoles: SendRole[];
@prop({ required: true })
@@ -52,52 +52,52 @@ export default class GroupMail extends BaseModel {
}
public static async getGroupMailsByRoleId(roleId: string, lean = true) {
const result: GroupMailType[] = await GroupMailModel.findOne({ 'sendRoles.roleId': roleId, 'sendRoles.status': { $ne: -1}, endTime: { $gte: nowSeconds() }}).lean(lean);
const result: GroupMailType[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, 'sendRoles.status': { $ne: -1}, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async getMail( mailId: string, mailTemType: number, lean = true) {
const result: GroupMailType = await GroupMailModel.findOne({ mailId, mailTemType }).lean(lean);
const result: GroupMailType = await GroupMailModel.findOne({ mailId, mailTemType, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async pushRoleMail( roleId: string, mailId: string, mailTemType: number, lean = true) {
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ mailId, mailTemType }, {$push: {sendRoles: {roleId, status: 0}}}).lean(lean);
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ mailId, mailTemType, sendTime:{$lte: nowSeconds()} }, {$push: {sendRoles: {roleId, status: 0}}}).lean(lean);
return result;
}
public static async getMailById(_id: string, lean = true) {
const result: GroupMailType = await GroupMailModel.findOne({ _id }).lean(lean);
const result: GroupMailType = await GroupMailModel.findOne({ _id, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async updateMailByStatus(_id: string, roleId: string, status: number, conditions: number[], lean = true) {
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId, 'sendRoles.status': {$in: conditions} }, {$set:{ 'sendRoles.$.status': status }}, { new: true }).lean(lean);
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId,sendTime:{$lte: nowSeconds()}, 'sendRoles.status': {$in: conditions} }, {$set:{ 'sendRoles.$.status': status }}, { new: true }).lean(lean);
return result;
}
public static async deleteMail(_id: string, roleId: string, status: number, lean = true) {
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId, }, {$set:{ 'sendRoles.$.status': status }}, { new: true }).lean(lean);
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId, sendTime:{$lte: nowSeconds()}}, {$set:{ 'sendRoles.$.status': status }}, { new: true }).lean(lean);
return result;
}
public static async findReadAndRewardsMails(roleId: string, lean = true) {
const ids: string[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, $or:[ {$and: [{'sendRoles.status': MAIL_STATUS.READ, goods: []}]}, {'sendRoles.status': MAIL_STATUS.RECEIVED}] }).select('_id').lean(lean);
const ids: string[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, sendTime:{$lte: nowSeconds()}, $or:[ {$and: [{'sendRoles.status': MAIL_STATUS.READ, goods: []}]}, {'sendRoles.status': MAIL_STATUS.RECEIVED}] }).select('_id').lean(lean);
return ids;
}
public static async updateMailStatus(ids: string[], status: number, roleId: string) {
const result: GroupMailType[] = await GroupMailModel.update({_id: {$in: ids}, 'sendRoles.roleId': roleId}, { $set:{ 'sendRoles.$.status': status } });
const result = await GroupMailModel.update({_id: {$in: ids}, 'sendRoles.roleId': roleId, sendTime:{$lte: nowSeconds()}}, { $set:{ 'sendRoles.$.status': status } });
return result;
}
public static async delMail(_id: string, roleId: string, lean = true) {
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId, $or:[ {$and: [{'sendRoles.status': MAIL_STATUS.READ, goods: []}]}, {'sendRoles.status': MAIL_STATUS.RECEIVED}] }, { $set:{ 'sendRoles.$.status': MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
const result: GroupMailType = await GroupMailModel.findOneAndUpdate({ _id, 'sendRoles.roleId': roleId, $or:[ {$and: [{'sendRoles.status': MAIL_STATUS.READ, goods: []}]}, {'sendRoles.status': MAIL_STATUS.RECEIVED}], sendTime:{$lte: nowSeconds() }}, { $set:{ 'sendRoles.$.status': MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
return result;
}
public static async findRewardsMails(roleId: string, lean = true) {
const result: GroupMailType[] = await GroupMailModel.find({ 'sendRoles.roleId': roleId, $and: [{'sendRoles.status': MAIL_STATUS.READ, goods: {$ne: []}}] }).select('_id goods').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 mailTemType').lean(lean);
return result;
}
}

View File

@@ -104,6 +104,13 @@ export default class GuildTrain extends BaseModel {
const result: GuildTrainType[] = await GuildTrainModel.find({guildCode, 'trainInstances.endTime':{$gte: nowSeconds()}, locked: false});
return result;
}
public static async removeTrainRank(guildCode: string, roleId: string, trainId: number, locked = false, lean = true) {
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, locked },
{ $pull:{ ranks: { roleId } }}, {new: true}).lean(lean);
return guildTrain;
}
}

View File

@@ -3,9 +3,13 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
import { nowSeconds } from '../pubUtils/timeUtil';
import { MAIL_STATUS } from '../consts/constModules/mailConst';
class RewardInter {
@prop({ required: true })
id: number;
@prop({ required: true })
count: number;
}
@index({ roleId: 1 })
@index({ roleId: 1, mailId: 1, type: 1 })
@@ -17,12 +21,12 @@ export default class Mail extends BaseModel {
mailId: string;
@prop({ required: true, type: RewardInter, default: [], _id: false })
goods: RewardInter[];
goods: Array<RewardInter>;
@prop({ required: true, default: nowSeconds() })
sendTime: number;
@prop({ required: true })
@prop({ required: true, type: String, _id: false})
params: string[];
@prop({ required: true, default: MAIL_STATUS.CREATE })
@@ -48,32 +52,32 @@ export default class Mail extends BaseModel {
}
public static async getMailsByRoleId(roleId: string, lean = true) {
const result: MailType[] = await MailModel.find({ roleId, status: { $ne: -1 } }).lean(lean);
const result: MailType[] = await MailModel.find({ roleId, status: { $ne: -1 }, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async getMail(roleId: string, mailId: string, mailTemType: number, lean = true) {
const result: MailType = await MailModel.findOne({ roleId, mailId, mailTemType }).lean(lean);
const result: MailType = await MailModel.findOne({ roleId, mailId, mailTemType, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async getMailById(_id: string, lean = true) {
const result: MailType = await MailModel.findOne({ _id }).lean(lean);
const result: MailType = await MailModel.findOne({ _id, sendTime:{$lte: nowSeconds()} }).lean(lean);
return result;
}
public static async updateMailByStatus(_id: string, conditions: number[], update: MailTypeParam, lean = true) {
const result: MailType = await MailModel.findOneAndUpdate({ _id, status: { $in: conditions } }, { $set: update }, { new: true }).lean(lean);
const result: MailType = await MailModel.findOneAndUpdate({ _id, status: { $in: conditions }, sendTime:{$lte: nowSeconds()} }, { $set: update }, { new: true }).lean(lean);
return result;
}
public static async updateMail(_id: string, update: MailTypeParam, lean = true) {
const result: MailType = await MailModel.findOneAndUpdate({ _id }, { $set: update }, { new: true }).lean(lean);
const result: MailType = await MailModel.findOneAndUpdate({ _id, sendTime:{$lte: nowSeconds()} }, { $set: update }, { new: true }).lean(lean);
return result;
}
public static async findReadAndRewardsMails(roleId: string, lean = true) {
const ids: string[] = await MailModel.find({ roleId, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }] }).select('_id').lean(lean);
const ids: string[] = await MailModel.find({ roleId, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }], sendTime:{$lte: nowSeconds()} }).select('_id').lean(lean);
return ids;
}
@@ -82,12 +86,12 @@ export default class Mail extends BaseModel {
}
public static async delMail(_id: string, lean = true) {
const result: MailType = await MailModel.findOneAndUpdate({ _id, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }] }, { $set: { status: MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
const result: MailType = await MailModel.findOneAndUpdate({ _id, $or: [{ $and: [{ status: MAIL_STATUS.READ, goods: [] }] }, { status: MAIL_STATUS.RECEIVED }], sendTime:{$lte: nowSeconds()} }, { $set: { status: MAIL_STATUS.DELETE } }, { new: true }).lean(lean);
return result;
}
public static async findRewardsMails(roleId: string, lean = true) {
const result: MailType[] = await MailModel.find({ roleId, $and: [{ status: MAIL_STATUS.READ, goods: { $ne: [] } }] }).select('_id goods').lean(lean);
const result: MailType[] = await MailModel.find({ roleId, status: {$in: [ MAIL_STATUS.CREATE, MAIL_STATUS.READ ] }, sendTime:{$lte: nowSeconds()} }).select('_id goods mailTemType').lean(lean);
return result;
}
}

View File

@@ -504,6 +504,11 @@ export default class Role extends BaseModel {
const result = await RoleModel.findOneAndUpdate({ roleId, blockCnt: {$lte: maxBlockCnt - blockCnt}}, {$inc: { blockCnt, friendCnt }}, {new: true}).lean();
return result;
}
public static async updatedRoleMailAt(roleId: string, updatedMailAt: number, lean = true) {
const result = await RoleModel.findOneAndUpdate({ roleId }, {$set: { updatedMailAt }}, {new: true}).lean(lean);
return result;
}
}
export const RoleModel = getModelForClass(Role);

View File

@@ -24,6 +24,8 @@ class WishGood {
receiveCnt: number;
@prop({ required: true, default:0 })
drawCnt: number;
@prop({ required: true, type: String, default: [] })
donateNames: string[];
}
@@ -198,8 +200,8 @@ export default class UserGuild extends BaseModel {
return result;
}
public static async donateUpdate(roleId: string, id: string, select?: string) {
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, 'wishGoods.id': id }, { $inc: { 'wishGoods.$.receiveCnt': 1, 'wishGoods.$.drawCnt': 1} }, { new: true }).select(select).lean();
public static async donateUpdate(roleId: string, dntRoleName: string, id: string, select?: string) {
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, 'wishGoods.id': id }, { $inc: { 'wishGoods.$.receiveCnt': 1, 'wishGoods.$.drawCnt': 1}, $push:{'wishGoods.$.dntRoleNames': dntRoleName} }, { new: true }).select(select).lean();
return result;
}
}

View File

@@ -8,19 +8,37 @@ export async function init() {
export function getGmMails(updatedMailAt: number, serverId: number) {
let list = [];
let nowTime = nowSeconds();
let serverIds = [serverId, ALL_SERVER];
for (let serverId of serverIds) {
if (!gmData.mails.get(serverId))
let gmServerData = gmData.mails.get(serverId);
if (!gmServerData)
continue;
gmData.mails.get(serverId).map(({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType})=>{
if (updatedAt >= updatedMailAt || sendTime > updatedMailAt || endTime < nowSeconds() )
list.push({updatedAt, sendTime, endTime, id, sendRoles, goods, content, gmMailType});
gmServerData.forEach((gmMail)=>{
if (gmMail.updatedAt >= updatedMailAt || gmMail.sendTime > updatedMailAt || gmMail.endTime > nowTime )
list.push(gmMail);
});
}
return list;
}
export function getGmMailById(id: string, serverId: number) {
export function getUseGmMails(serverId: number) {
let list = new Map<string, GMMail>();
let serverIds = [serverId, ALL_SERVER];
let nowTime = nowSeconds();
for (let serverId of serverIds) {
let gmServerData = gmData.mails.get(serverId);
if (!gmServerData)
continue;
gmServerData.forEach((gmMail)=>{
if (gmMail.endTime > nowTime)
list.set(gmMail.id, gmMail);
});
}
return list;
}
export function getGmMailById(id: string, serverId: number, nowTime: number) {
let gmMail;
if (!!gmData.mails.get(serverId)) {
gmMail = gmData.mails.get(serverId).get(id);
@@ -30,9 +48,24 @@ export function getGmMailById(id: string, serverId: number) {
gmMail = gmData.mails.get(ALL_SERVER).get(id);
}
}
if (!gmMail || gmMail.endTime < nowTime)
return null;
return gmMail;
}
export function setGmMails(mails: GMMail[]) {
setMails(mails, gmData.mails);
}
export function getGmUseMails(serverId: number) {
let list = new Map<number, any>();
if (!!gmData.mails.get(serverId)) {
list = gmData.mails.get(serverId);
}
let serverMail = gmData.mails.get(ALL_SERVER);
if (!!serverMail) {
list = Object.assign(list, serverMail);
}
return list;
}

View File

@@ -34,12 +34,14 @@ export async function mailInit() {
let gmMail = new Map<number, any>();
let mails = await GMMailModel.getMails();
mails.map((o:any)=>{
o.id = o._id;
let id:string = JSON.stringify(o._id);
o.id = id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
o.sendName = o.sendName||'系统';
mail.set(o.id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
return gmMail;
@@ -48,12 +50,14 @@ export async function mailInit() {
export function setMails(mails:GMMail[], gmMail) {
mails.map((o:any)=>{
o.id = o._id;
let id:string = JSON.stringify(o._id);
o.id = id;
o.updatedAt = Math.floor(o.updatedAt.getTime()/1000);
o.sendName = o.sendName||'系统';
let mail = gmMail.get(o.serverId);
if (!mail)
mail = new Map<string, GMMail>();
mail.set(o._id, _.pick(o, Object.keys(GMMailKeys)));
mail.set(o.id, _.pick(o, Object.keys(GMMailKeys)));
gmMail.set(o.serverId, mail);
});
}

View File

@@ -110,7 +110,6 @@ export interface pushMail {
export interface mailData {
id: string;
mailId: string;
goods: RewardInter[];
sendTime: number;
endTime: number;