🐞 fix(guild): 试炼挑战奖励领取过的不允许再领
This commit is contained in:
@@ -4,7 +4,7 @@ import { DEBUG_MAGIC_WORD, ITEM_CHANGE_REASON, STATUS, TASK_TYPE, TRAIN_REWARD_T
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getTimeFun, getZeroPoint } from '../../../pubUtils/timeUtil';
|
||||
import { refreshTrain, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance, getTrainBoxRewardsResult, resetTrain } from '../../../services/guildTrainService';
|
||||
import { refreshTrain, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance, getTrainBoxRewardsResult, resetTrain, getTrainBoxRewardsResultWithoutAlreadyGeted } from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
|
||||
@@ -79,8 +79,8 @@ export class GuildTrainHandler {
|
||||
let userGuild = await refreshTrain(myUserGuild, roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let resTrainBoxs = await getTrainBoxRewardsResult(code);
|
||||
const { guildCode: code, trainBoxRewards} = userGuild;
|
||||
let resTrainBoxs = await getTrainBoxRewardsResultWithoutAlreadyGeted(code, trainBoxRewards);
|
||||
return resResult(STATUS.SUCCESS, { trainBoxRewards: resTrainBoxs });
|
||||
}
|
||||
/**
|
||||
@@ -309,9 +309,10 @@ export class GuildTrainHandler {
|
||||
let goods = await addItems(roleId, roleName, sid, [good], ITEM_CHANGE_REASON.TRAIN_BOX_REWARD);
|
||||
|
||||
let resGuildTrain = await GuildTrainModel.receiveBoxByIndex(code, roleId, trainId, hid, index, good);
|
||||
let resUserGuild = await UserGuildModel.receiveTrainBoxRewards(roleId, trainId);
|
||||
res.releaseCallback();//解锁
|
||||
|
||||
if (!resGuildTrain) {
|
||||
if (!resGuildTrain || !resUserGuild) {
|
||||
return resResult(STATUS.GUILD_GET_TRAIN_BOX_FAIL);
|
||||
}
|
||||
let result: any = getGuildTrainRewards(resGuildTrain);
|
||||
|
||||
@@ -60,6 +60,39 @@ export async function getTrainBoxRewardsResult(guildCode: string) {
|
||||
return resTrainBoxs
|
||||
}
|
||||
|
||||
/**
|
||||
* 领过的试炼宝箱不允许再领
|
||||
*
|
||||
* @export
|
||||
* @param {string} guildCode
|
||||
* @param {number[]} receivedTrainBox
|
||||
* @return {*}
|
||||
*/
|
||||
export async function getTrainBoxRewardsResultWithoutAlreadyGeted(guildCode: string, receivedTrainBox:number[]) {
|
||||
|
||||
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 && (receivedTrainBox.indexOf(trainId) == -1)) {
|
||||
resTrainBoxs.push({ trainId, boxRewards });
|
||||
}
|
||||
})
|
||||
return resTrainBoxs
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得未失效的试炼宝箱奖励
|
||||
* @param guildTrain
|
||||
|
||||
Reference in New Issue
Block a user