🐞 fix(guild): 捐赠宝箱重复领取&领取之后展示问题修复
This commit is contained in:
@@ -4,7 +4,7 @@ import { resResult } from '../../../pubUtils/util';
|
||||
import { DATA_NAME, ITEM_CHANGE_REASON, STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { DonationModel } from '../../../db/Donation';
|
||||
import { getZeroPoint, nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById, getArmyDonateBoxBaseByLvAndIndex } from '../../../pubUtils/data';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { handleCost, addItems } from '../../../services/role/rewardService';
|
||||
import { CHAT_SERVER, GUILD_POINT_WAYS } from '../../../consts';
|
||||
@@ -16,6 +16,7 @@ import { checkTask, checkTaskInDonate } from '../../../services/task/taskService
|
||||
import { guildInter } from '../../../pubUtils/interface';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { getVipDonateConsume } from '../../../services/activity/monthlyTicketService';
|
||||
import { changeReceiveBoxIdByLvAndIndex } from '../../../services/donateService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -44,7 +45,9 @@ export class DonationHandler {
|
||||
}
|
||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||
let { donateFund, reports, donationLv } = await getDonation(code, guild);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
|
||||
// 根据donationLv, 和index, 转化成对应的箱子id
|
||||
let haveGotBoxIds: number[] = changeReceiveBoxIdByLvAndIndex(receiveBoxs, donationLv);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs: haveGotBoxIds, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
|
||||
}
|
||||
/**
|
||||
* 捐献
|
||||
@@ -129,10 +132,13 @@ export class DonationHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
// 捐献宝箱-每级有4个
|
||||
const TOTAL_BOX_COUNT = 4;
|
||||
// 领取限制: 一天内,相同index的箱子不允许重复领取
|
||||
// 当前要领取的箱子index
|
||||
const {index: curBoxIndex} = getArmyDonateBoxBaseById(id);
|
||||
for (let haveGotId of resReceiveBoxs) {
|
||||
if ((haveGotId % TOTAL_BOX_COUNT) === (id % TOTAL_BOX_COUNT)) {
|
||||
// 已领取箱子index
|
||||
let {index: haveGotIndex} = getArmyDonateBoxBaseById(haveGotId);
|
||||
if (haveGotIndex === curBoxIndex) {
|
||||
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
|
||||
}
|
||||
}
|
||||
@@ -144,6 +150,8 @@ export class DonationHandler {
|
||||
resReceiveBoxs.push(id);
|
||||
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
|
||||
let goods = await addItems(roleId, roleName, sid, boxRewards, ITEM_CHANGE_REASON.DONATE_BOX);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
|
||||
// 根据donationLv, 和index, 转化成对应的箱子id
|
||||
let haveGotBoxIds: number[] = changeReceiveBoxIdByLvAndIndex(receiveBoxs, donationLv);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs: haveGotBoxIds, goods });
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { gameData } from '../pubUtils/data';
|
||||
import { shouldRefresh } from '../pubUtils/util';
|
||||
import { recordGuildFund } from './activity/timeLimitRankService';
|
||||
import { pushGuildInfoUpdate } from './guildService';
|
||||
import { getArmyDonateBoxBaseById, getArmyDonateBoxBaseByLvAndIndex } from '../pubUtils/data';
|
||||
/**
|
||||
* 获得军团捐献,并检查是否刷新捐献数据
|
||||
* @param code
|
||||
@@ -65,4 +66,23 @@ export async function addFund(code: string, serverId: number, fund: number) {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将已经领取的其他等级捐赠宝箱id转为donationLv对应等级相同index的宝箱id
|
||||
*
|
||||
* @export
|
||||
* @param {number[]} receiveBoxs 已领取的宝箱id
|
||||
* @param {number} donationLv 当前捐赠等级
|
||||
*/
|
||||
export function changeReceiveBoxIdByLvAndIndex(receiveBoxs: number[], donationLv: number) {
|
||||
let haveGotBoxIds: number[] = [];
|
||||
receiveBoxs.forEach((boxId) => {
|
||||
// 获取已领取箱子的index
|
||||
let { index } = getArmyDonateBoxBaseById(boxId);
|
||||
// 获取donationLv等级,第index个箱子的id
|
||||
let { id } = getArmyDonateBoxBaseByLvAndIndex(donationLv, index);
|
||||
haveGotBoxIds.push(id);
|
||||
});
|
||||
return haveGotBoxIds;
|
||||
}
|
||||
Reference in New Issue
Block a user