diff --git a/game-server/app/servers/battle/handler/guildTrainHandler.ts b/game-server/app/servers/battle/handler/guildTrainHandler.ts index e18808979..a07163915 100644 --- a/game-server/app/servers/battle/handler/guildTrainHandler.ts +++ b/game-server/app/servers/battle/handler/guildTrainHandler.ts @@ -4,7 +4,7 @@ import { STATUS, TASK_TYPE } from '../../../consts'; import { GuildTrainModel } from '../../../db/GuildTrain'; import { BattleRecordModel } from '../../../db/BattleRecord'; import { nowSeconds, getTimeFun, getZeroPoint } from '../../../pubUtils/timeUtil'; -import { getUserGuild, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance } from '../../../services/guildTrainService'; +import { getUserGuild, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance, getTrainBoxRewardsResult } from '../../../services/guildTrainService'; import { findIndex, findWhere } from 'underscore' import { lockData } from '../../../services/redLockService'; import { GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst'; @@ -75,26 +75,7 @@ export class GuildTrainHandler { if (!userGuild) return resResult(STATUS.WRONG_PARMS); const { guildCode: code } = userGuild; - let guildTrains = await GuildTrainModel.findGuildTrain(code);//获得未失效的宝箱奖励 - let resTrainBoxs = []; - guildTrains.forEach(({ trainInstances, trainId }) => { - let { trainInstances: instances } = getArmyTrainJuDian(trainId); - let flag = false; - let boxRewards = []; - trainInstances.map(({ hid, progress, endTime, trainBoxs }) => { - let isComplete = false; - let instance = findWhere(instances, { hid }); - if (progress >= instance.progress) { - isComplete = true; - if (endTime > nowSeconds()) - flag = true; - } - boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete }); - }); - if (flag) { - resTrainBoxs.push({ trainId, boxRewards }); - } - }) + let resTrainBoxs = await getTrainBoxRewardsResult(code); return resResult(STATUS.SUCCESS, { trainBoxRewards: resTrainBoxs }); } /** diff --git a/game-server/app/services/connectorService.ts b/game-server/app/services/connectorService.ts index 68105becc..e59d1a1f1 100644 --- a/game-server/app/services/connectorService.ts +++ b/game-server/app/services/connectorService.ts @@ -24,7 +24,7 @@ import { getSchoolList } from './roleService'; import { addRoleToGuildChannel } from './chatChannelService'; import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool } from './guildService'; import { getAuction } from './auctionService'; -import { getGuildTrainInstance } from './guildTrainService'; +import { getGuildTrainInstance, getTrainBoxRewardsResult } from './guildTrainService'; import { BossInstanceModel } from '../db/BossInstance'; import { getBossInstanceInfo } from './guildBossService'; import { getEvent } from './eventSercive'; @@ -109,7 +109,11 @@ export async function pushData(role: RoleType, session: FrontendOrBackendSession case 'auction': return hasGuild? await getAuction(guildCode, session): null; case 'train': - return hasGuild? await getGuildTrainInstance(roleId, guild, userGuild): null; + if(hasGuild) { + let trainInstance = await getGuildTrainInstance(roleId, guild, userGuild); + let trainBoxRewards = await getTrainBoxRewardsResult(guildCode); + return { trainInstance, trainBoxRewards } + } case 'boss': if(hasGuild) { const bossInstance = await BossInstanceModel.findBossInstance(guild.code); diff --git a/game-server/app/services/guildTrainService.ts b/game-server/app/services/guildTrainService.ts index 6f951f731..e0272de9a 100644 --- a/game-server/app/services/guildTrainService.ts +++ b/game-server/app/services/guildTrainService.ts @@ -35,6 +35,31 @@ export async function getUserGuild(roleId: string, serverId: number) { return userGuild; } +export async function getTrainBoxRewardsResult(guildCode: string) { + + let guildTrains = await GuildTrainModel.findGuildTrain(guildCode);//获得未失效的宝箱奖励 + let resTrainBoxs = []; + guildTrains.forEach(({ trainInstances, trainId }) => { + let { trainInstances: instances } = getArmyTrainJuDian(trainId); + let flag = false; + let boxRewards = []; + trainInstances.map(({ hid, progress, endTime, trainBoxs }) => { + let isComplete = false; + let instance = findWhere(instances, { hid }); + if (progress >= instance.progress) { + isComplete = true; + if (endTime > nowSeconds()) + flag = true; + } + boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete }); + }); + if (flag) { + resTrainBoxs.push({ trainId, boxRewards }); + } + }) + return resTrainBoxs +} + /** * 获得未失效的试炼宝箱奖励 * @param guildTrain