🐞 fix(guild): 捐赠宝箱重复领取&领取之后展示问题修复

This commit is contained in:
dingchaolin
2023-03-16 12:42:13 +08:00
parent 739ea2da6b
commit 36c81751bd
5 changed files with 125 additions and 127 deletions

View File

@@ -4,7 +4,7 @@ import { resResult } from '../../../pubUtils/util';
import { DATA_NAME, ITEM_CHANGE_REASON, STATUS, TASK_TYPE } from '../../../consts'; import { DATA_NAME, ITEM_CHANGE_REASON, STATUS, TASK_TYPE } from '../../../consts';
import { DonationModel } from '../../../db/Donation'; import { DonationModel } from '../../../db/Donation';
import { getZeroPoint, nowSeconds } from '../../../pubUtils/timeUtil'; 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 { GuildModel } from '../../../db/Guild';
import { handleCost, addItems } from '../../../services/role/rewardService'; import { handleCost, addItems } from '../../../services/role/rewardService';
import { CHAT_SERVER, GUILD_POINT_WAYS } from '../../../consts'; 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 { guildInter } from '../../../pubUtils/interface';
import { lockData } from '../../../services/redLockService'; import { lockData } from '../../../services/redLockService';
import { getVipDonateConsume } from '../../../services/activity/monthlyTicketService'; import { getVipDonateConsume } from '../../../services/activity/monthlyTicketService';
import { changeReceiveBoxIdByLvAndIndex } from '../../../services/donateService';
export default function (app: Application) { export default function (app: Application) {
new HandlerService(app, {}); new HandlerService(app, {});
@@ -44,7 +45,9 @@ export class DonationHandler {
} }
const { guildCode: code, donateCnt, receiveBoxs } = userGuild; const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
let { donateFund, reports, donationLv } = await getDonation(code, guild); 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); return resResult(STATUS.WRONG_PARMS);
} }
// 捐献宝箱-每级有4个 // 领取限制: 一天内相同index的箱子不允许重复领取
const TOTAL_BOX_COUNT = 4; // 当前要领取的箱子index
const {index: curBoxIndex} = getArmyDonateBoxBaseById(id);
for (let haveGotId of resReceiveBoxs) { 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); return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
} }
} }
@@ -144,6 +150,8 @@ export class DonationHandler {
resReceiveBoxs.push(id); resReceiveBoxs.push(id);
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs'); let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
let goods = await addItems(roleId, roleName, sid, boxRewards, ITEM_CHANGE_REASON.DONATE_BOX); 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 });
} }
} }

View File

@@ -8,6 +8,7 @@ import { gameData } from '../pubUtils/data';
import { shouldRefresh } from '../pubUtils/util'; import { shouldRefresh } from '../pubUtils/util';
import { recordGuildFund } from './activity/timeLimitRankService'; import { recordGuildFund } from './activity/timeLimitRankService';
import { pushGuildInfoUpdate } from './guildService'; import { pushGuildInfoUpdate } from './guildService';
import { getArmyDonateBoxBaseById, getArmyDonateBoxBaseByLvAndIndex } from '../pubUtils/data';
/** /**
* 获得军团捐献,并检查是否刷新捐献数据 * 获得军团捐献,并检查是否刷新捐献数据
* @param code * @param code
@@ -65,4 +66,23 @@ export async function addFund(code: string, serverId: number, fund: number) {
return null 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;
} }

View File

@@ -43,7 +43,7 @@ import { dicTrainSoloReward, loadTrainSoloReward } from './dictionary/DicTrainSo
import { RewardInter } from "./interface"; import { RewardInter } from "./interface";
import { dicArmyDevelopConsume, loadArmyDevelopConsume } from './dictionary/DicArmyDevelopConsume'; import { dicArmyDevelopConsume, loadArmyDevelopConsume } from './dictionary/DicArmyDevelopConsume';
import { dicArmyBossRank, loadArmyBossRank } from './dictionary/DicArmyBossRank'; import { dicArmyBossRank, loadArmyBossRank } from './dictionary/DicArmyBossRank';
import { dicArmyDonate, loadArmyDonate } from './dictionary/DicArmyDonateBoxReward'; import { dicArmyDonate, loadArmyDonate, dicArmyDonateBoxIdByIndexAndLv } from './dictionary/DicArmyDonateBoxReward';
import { dicRoleFriend, DicRoleFriend, loadRoleFriend } from "./dictionary/DicRoleFriend"; import { dicRoleFriend, DicRoleFriend, loadRoleFriend } from "./dictionary/DicRoleFriend";
import { dicRoleFriendLv, loadRoleFriendLv } from "./dictionary/DicRoleFriendLv"; import { dicRoleFriendLv, loadRoleFriendLv } from "./dictionary/DicRoleFriendLv";
import { AttributeCal } from "../domain/roleField/attribute"; import { AttributeCal } from "../domain/roleField/attribute";
@@ -208,6 +208,7 @@ export const gameData = {
armyDevelopConsume: dicArmyDevelopConsume, armyDevelopConsume: dicArmyDevelopConsume,
armyBossRank: dicArmyBossRank, armyBossRank: dicArmyBossRank,
armyDonateBox: dicArmyDonate, armyDonateBox: dicArmyDonate,
armyDonateBoxByIndexAndLv: dicArmyDonateBoxIdByIndexAndLv,
roleFriend: dicRoleFriend, roleFriend: dicRoleFriend,
roleFriendLv: dicRoleFriendLv, roleFriendLv: dicRoleFriendLv,
figureCondition: figureCondition, figureCondition: figureCondition,
@@ -679,6 +680,11 @@ export function getArmyDonateBaseByLv(lv: number) {
export function getArmyDonateBoxBaseById(id: number) { export function getArmyDonateBoxBaseById(id: number) {
return gameData.armyDonateBox.get(id); return gameData.armyDonateBox.get(id);
} }
export function getArmyDonateBoxBaseByLvAndIndex(lv: number, index: number) {
return gameData.armyDonateBoxByIndexAndLv.get(`${lv}_${index}`);
}
export function getFriendLvByExp(exp: number) { export function getFriendLvByExp(exp: number) {
let resultLv = 1; let resultLv = 1;
for (let [lv, { sum }] of gameData.roleFriendLv.entries()) { for (let [lv, { sum }] of gameData.roleFriendLv.entries()) {

View File

@@ -6,6 +6,7 @@ const _ = require('lodash');
export interface DicArmyDonate { export interface DicArmyDonate {
readonly id: number; readonly id: number;
readonly index: number;
readonly level: number; readonly level: number;
readonly fund: number; readonly fund: number;
readonly boxRewards: Array<RewardInter>; readonly boxRewards: Array<RewardInter>;
@@ -13,12 +14,14 @@ export interface DicArmyDonate {
const DicArmyDonateKeys: KeysEnum<DicArmyDonate> = { const DicArmyDonateKeys: KeysEnum<DicArmyDonate> = {
id: true, id: true,
index: true,
level: true, level: true,
fund: true, fund: true,
boxRewards: true boxRewards: true
}; };
export const dicArmyDonate = new Map<number, DicArmyDonate>(); export const dicArmyDonate = new Map<number, DicArmyDonate>();
export const dicArmyDonateBoxIdByIndexAndLv = new Map<string, DicArmyDonate>();
export function loadArmyDonate() { export function loadArmyDonate() {
dicArmyDonate.clear(); dicArmyDonate.clear();
let arr = readFileAndParse(FILENAME.DIC_ARMY_DONATE_BOX_REWARD); let arr = readFileAndParse(FILENAME.DIC_ARMY_DONATE_BOX_REWARD);
@@ -26,6 +29,7 @@ export function loadArmyDonate() {
arr.forEach(o => { arr.forEach(o => {
o.boxRewards = parseGoodStr(o.boxReward); o.boxRewards = parseGoodStr(o.boxReward);
dicArmyDonate.set(o.id, _.pick(o, Object.keys(DicArmyDonateKeys))); dicArmyDonate.set(o.id, _.pick(o, Object.keys(DicArmyDonateKeys)));
dicArmyDonateBoxIdByIndexAndLv.set(`${o.level}_${o.index}`, _.pick(o, Object.keys(DicArmyDonateKeys)));
}); });
arr = undefined; arr = undefined;
} }

View File

@@ -1,322 +1,282 @@
[ [
{ {
"id": 1, "id": 1,
"index": 1,
"level": 1, "level": 1,
"fund": 10000, "fund": 10000,
"boxReward": "40005&500", "boxReward": "40005&500"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 2, "id": 2,
"index": 2,
"level": 1, "level": 1,
"fund": 20000, "fund": 20000,
"boxReward": "17052&250", "boxReward": "17052&250"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 3, "id": 3,
"index": 3,
"level": 1, "level": 1,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1000", "boxReward": "40005&1000"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 4, "id": 4,
"index": 4,
"level": 1, "level": 1,
"fund": 60000, "fund": 60000,
"boxReward": "17053&5", "boxReward": "17053&5"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 5, "id": 5,
"index": 1,
"level": 2, "level": 2,
"fund": 10000, "fund": 10000,
"boxReward": "40005&550", "boxReward": "40005&550"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 6, "id": 6,
"index": 2,
"level": 2, "level": 2,
"fund": 20000, "fund": 20000,
"boxReward": "17052&275", "boxReward": "17052&275"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 7, "id": 7,
"index": 3,
"level": 2, "level": 2,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1100", "boxReward": "40005&1100"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 8, "id": 8,
"index": 4,
"level": 2, "level": 2,
"fund": 60000, "fund": 60000,
"boxReward": "17053&6", "boxReward": "17053&6"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 9, "id": 9,
"index": 1,
"level": 3, "level": 3,
"fund": 10000, "fund": 10000,
"boxReward": "40005&600", "boxReward": "40005&600"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 10, "id": 10,
"index": 2,
"level": 3, "level": 3,
"fund": 20000, "fund": 20000,
"boxReward": "17052&300", "boxReward": "17052&300"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 11, "id": 11,
"index": 3,
"level": 3, "level": 3,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1200", "boxReward": "40005&1200"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 12, "id": 12,
"index": 4,
"level": 3, "level": 3,
"fund": 60000, "fund": 60000,
"boxReward": "17053&7", "boxReward": "17053&7"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 13, "id": 13,
"index": 1,
"level": 4, "level": 4,
"fund": 10000, "fund": 10000,
"boxReward": "40005&650", "boxReward": "40005&650"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 14, "id": 14,
"index": 2,
"level": 4, "level": 4,
"fund": 20000, "fund": 20000,
"boxReward": "17052&325", "boxReward": "17052&325"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 15, "id": 15,
"index": 3,
"level": 4, "level": 4,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1300", "boxReward": "40005&1300"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 16, "id": 16,
"index": 4,
"level": 4, "level": 4,
"fund": 60000, "fund": 60000,
"boxReward": "17053&8", "boxReward": "17053&8"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 17, "id": 17,
"index": 1,
"level": 5, "level": 5,
"fund": 10000, "fund": 10000,
"boxReward": "40005&700", "boxReward": "40005&700"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 18, "id": 18,
"index": 2,
"level": 5, "level": 5,
"fund": 20000, "fund": 20000,
"boxReward": "17052&350", "boxReward": "17052&350"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 19, "id": 19,
"index": 3,
"level": 5, "level": 5,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1400", "boxReward": "40005&1400"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 20, "id": 20,
"index": 4,
"level": 5, "level": 5,
"fund": 60000, "fund": 60000,
"boxReward": "17053&9", "boxReward": "17053&9"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 21, "id": 21,
"index": 1,
"level": 6, "level": 6,
"fund": 10000, "fund": 10000,
"boxReward": "40005&750", "boxReward": "40005&750"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 22, "id": 22,
"index": 2,
"level": 6, "level": 6,
"fund": 20000, "fund": 20000,
"boxReward": "17052&375", "boxReward": "17052&375"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 23, "id": 23,
"index": 3,
"level": 6, "level": 6,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1500", "boxReward": "40005&1500"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 24, "id": 24,
"index": 4,
"level": 6, "level": 6,
"fund": 60000, "fund": 60000,
"boxReward": "17053&10", "boxReward": "17053&10"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 25, "id": 25,
"index": 1,
"level": 7, "level": 7,
"fund": 10000, "fund": 10000,
"boxReward": "40005&800", "boxReward": "40005&800"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 26, "id": 26,
"index": 2,
"level": 7, "level": 7,
"fund": 20000, "fund": 20000,
"boxReward": "17052&400", "boxReward": "17052&400"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 27, "id": 27,
"index": 3,
"level": 7, "level": 7,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1600", "boxReward": "40005&1600"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 28, "id": 28,
"index": 4,
"level": 7, "level": 7,
"fund": 60000, "fund": 60000,
"boxReward": "17053&11", "boxReward": "17053&11"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 29, "id": 29,
"index": 1,
"level": 8, "level": 8,
"fund": 10000, "fund": 10000,
"boxReward": "40005&850", "boxReward": "40005&850"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 30, "id": 30,
"index": 2,
"level": 8, "level": 8,
"fund": 20000, "fund": 20000,
"boxReward": "17052&425", "boxReward": "17052&425"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 31, "id": 31,
"index": 3,
"level": 8, "level": 8,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1700", "boxReward": "40005&1700"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 32, "id": 32,
"index": 4,
"level": 8, "level": 8,
"fund": 60000, "fund": 60000,
"boxReward": "17053&12", "boxReward": "17053&12"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 33, "id": 33,
"index": 1,
"level": 9, "level": 9,
"fund": 10000, "fund": 10000,
"boxReward": "40005&900", "boxReward": "40005&900"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 34, "id": 34,
"index": 2,
"level": 9, "level": 9,
"fund": 20000, "fund": 20000,
"boxReward": "17052&450", "boxReward": "17052&450"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 35, "id": 35,
"index": 3,
"level": 9, "level": 9,
"fund": 40000, "fund": 40000,
"boxReward": "40005&1800", "boxReward": "40005&1800"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 36, "id": 36,
"index": 4,
"level": 9, "level": 9,
"fund": 60000, "fund": 60000,
"boxReward": "17053&13", "boxReward": "17053&13"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 37, "id": 37,
"index": 1,
"level": 10, "level": 10,
"fund": 10000, "fund": 10000,
"boxReward": "40005&1000", "boxReward": "40005&1000"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 38, "id": 38,
"index": 2,
"level": 10, "level": 10,
"fund": 20000, "fund": 20000,
"boxReward": "17052&500", "boxReward": "17052&500"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 39, "id": 39,
"index": 3,
"level": 10, "level": 10,
"fund": 40000, "fund": 40000,
"boxReward": "40005&2000", "boxReward": "40005&2000"
"__EMPTY": 0,
"__EMPTY_1": 0
}, },
{ {
"id": 40, "id": 40,
"index": 4,
"level": 10, "level": 10,
"fund": 60000, "fund": 60000,
"boxReward": "17053&15", "boxReward": "17053&15"
"__EMPTY": 0,
"__EMPTY_1": 0
} }
] ]