🐞 fix(guild): 练兵场-挑战奖励不能重复领取
This commit is contained in:
@@ -80,7 +80,17 @@ export class GuildTrainHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, trainBoxRewards = []} = userGuild;
|
||||
let resTrainBoxs = await getTrainBoxRewardsResultWithoutAlreadyGeted(code, trainBoxRewards);
|
||||
let alreadyGetTrainBoxReards: { [hid: number]: string[] } = {}; // {英雄id:[军团id]}
|
||||
trainBoxRewards.forEach(item => {
|
||||
if (typeof item != 'object' || !item.hid || !item.guildCode) {
|
||||
return;
|
||||
}
|
||||
if (!alreadyGetTrainBoxReards[item.hid]) {
|
||||
alreadyGetTrainBoxReards[item.hid] = [];
|
||||
}
|
||||
alreadyGetTrainBoxReards[item.hid].push(item.guildCode);
|
||||
});
|
||||
let resTrainBoxs = await getTrainBoxRewardsResultWithoutAlreadyGeted(code, alreadyGetTrainBoxReards);
|
||||
return resResult(STATUS.SUCCESS, { trainBoxRewards: resTrainBoxs });
|
||||
}
|
||||
/**
|
||||
@@ -309,7 +319,7 @@ 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);
|
||||
let resUserGuild = await UserGuildModel.receiveTrainBoxRewards(roleId, hid, resGuildTrain.guildCode);
|
||||
res.releaseCallback();//解锁
|
||||
|
||||
if (!resGuildTrain || !resUserGuild) {
|
||||
|
||||
@@ -65,10 +65,10 @@ export async function getTrainBoxRewardsResult(guildCode: string) {
|
||||
*
|
||||
* @export
|
||||
* @param {string} guildCode
|
||||
* @param {number[]} receivedTrainBox
|
||||
* @param {number[]} receivedTrainBox: {[英雄id]:[军团id]} 表示已经领取过该英雄奖励的军团
|
||||
* @return {*}
|
||||
*/
|
||||
export async function getTrainBoxRewardsResultWithoutAlreadyGeted(guildCode: string, receivedTrainBox:number[]) {
|
||||
export async function getTrainBoxRewardsResultWithoutAlreadyGeted(guildCode: string, receivedTrainBox: { [hid: number]: string[] }) {
|
||||
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(guildCode);//获得未失效的宝箱奖励
|
||||
let resTrainBoxs = [];
|
||||
@@ -84,9 +84,18 @@ export async function getTrainBoxRewardsResultWithoutAlreadyGeted(guildCode: str
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
}
|
||||
boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete });
|
||||
// 在任何军团都未领取过 || 在本军团领取过 ==> 全部正常展示
|
||||
if (!receivedTrainBox[hid] || (receivedTrainBox[hid] && receivedTrainBox[hid].length > 0 && receivedTrainBox[hid].indexOf(guildCode) != -1)) {
|
||||
boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete });
|
||||
} else {
|
||||
// 领取过,且不是在本军团领取的 ==> 置灰、奖励不可领取
|
||||
isComplete = false;
|
||||
endTime = 0;
|
||||
boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete });
|
||||
}
|
||||
|
||||
});
|
||||
if (flag && (receivedTrainBox.indexOf(trainId) == -1)) {
|
||||
if (flag) {
|
||||
resTrainBoxs.push({ trainId, boxRewards });
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user