🐞 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 });
|
||||
}
|
||||
})
|
||||
|
||||
@@ -35,6 +35,13 @@ class RefineRecord {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export class TrainBoxRewardRecord {
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
}
|
||||
|
||||
@index({ roleId: 1 })
|
||||
@index({ guildCode: 1 })
|
||||
export default class UserGuild extends BaseModel {
|
||||
@@ -86,8 +93,8 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true, default: [] })
|
||||
trainRewards: Array<number>;//领取过的进阶等级
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
trainBoxRewards: Array<number>;//领取过的挑战奖励
|
||||
@prop({ required: true, default: [], type: TrainBoxRewardRecord, _id: false })
|
||||
trainBoxRewards: Array<TrainBoxRewardRecord>;//领取过的挑战奖励
|
||||
|
||||
//捐献所
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
@@ -176,7 +183,7 @@ export default class UserGuild extends BaseModel {
|
||||
delete update._id;
|
||||
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, { $set: update }, { upsert: true, new: true })
|
||||
.select('activeDaily activeRecord activeWeekly activeUpdateTime job auth receivedActive guildCode')
|
||||
.select('activeDaily activeRecord activeWeekly activeUpdateTime job auth receivedActive guildCode trainBoxRewards')
|
||||
.lean();
|
||||
|
||||
return result;
|
||||
@@ -225,7 +232,7 @@ export default class UserGuild extends BaseModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录玩家领取过的试炼宝箱奖励(每个boss都有一个抽卡奖励)
|
||||
* 记录玩家领取过的试炼宝箱奖励(每个武将都有一个抽卡奖励)
|
||||
*
|
||||
* @static
|
||||
* @param {string} roleId
|
||||
@@ -234,9 +241,9 @@ export default class UserGuild extends BaseModel {
|
||||
* @return {*}
|
||||
* @memberof UserGuild
|
||||
*/
|
||||
public static async receiveTrainBoxRewards(roleId: string, trainId: number, lean = true) {
|
||||
public static async receiveTrainBoxRewards(roleId: string, hid: number, guildCode: string, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{ $push:{trainBoxRewards: trainId} },{new: true}).lean(lean);
|
||||
{ $push:{trainBoxRewards: {hid, guildCode}} },{new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user