diff --git a/game-server/app/servers/activity/handler/chongyangHandler.ts b/game-server/app/servers/activity/handler/chongyangHandler.ts index afb3691ce..0ae667f2a 100644 --- a/game-server/app/servers/activity/handler/chongyangHandler.ts +++ b/game-server/app/servers/activity/handler/chongyangHandler.ts @@ -102,7 +102,6 @@ export class ChongYangHandler { const sid = session.get('sid'); const serverId = session.get('serverId'); - console.log('---------xxxxxxxxxxxxxx------------------buyCnt') let playerData = await getPlayerChongYangData(activityId, serverId, roleId); if (!playerData || !playerData.sceneMap) return resResult(STATUS.ACTIVITY_MISSING); let scene = playerData.sceneMap.get(dayIndex); @@ -114,7 +113,7 @@ export class ChongYangHandler { if (dayIndex > playerData.dayIndexUnlock) return resResult(STATUS.ACTIVITY_CHONGYANG_LOCK); // 保存数据 - let playerRecord = await ActivityChongYangRecModel.buyCnt(serverId, activityId, playerData.roundIndex, roleId, dayIndex, count); + let playerRecord = await ActivityChongYangRecModel.buyCnt(serverId, activityId, playerData.roundIndex, roleId, { dayIndex, buyCnt: count }, scene.isPushBuyRecord); if (!playerRecord) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_NOT_FOUND); playerData = await getPlayerChongYangData(activityId, serverId, roleId); diff --git a/shared/db/ActivityChongYangRec.ts b/shared/db/ActivityChongYangRec.ts index 289a12bbd..6fef4148b 100644 --- a/shared/db/ActivityChongYangRec.ts +++ b/shared/db/ActivityChongYangRec.ts @@ -53,13 +53,18 @@ export default class Activity_ChongYang_Rec extends BaseModel { return result; } - public static async gameRecord(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecords: ChongYangGameRecord) { - let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean(); + public static async gameRecord(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecord: ChongYangGameRecord) { + let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords: gameRecord } }, { new: true, upsert: true }).lean(); return result; } - public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, dayIndex: number, count: number) { - let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': dayIndex }, { $inc: { 'buyRecords.$.buyCnt': count }, $setOnInsert: { gameRecord: [] } }, { new: true, upsert: true }).lean(); + public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, buyRecord: ChongYangBuyRecord, isPushBuyRecord: boolean) { + let result: ActivityChongYangRecModelType; + if (isPushBuyRecord) { + result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { buyRecords: buyRecord } }, { new: true, upsert: true }).lean(); + } else { + result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': buyRecord.dayIndex }, { $inc: { 'buyRecords.$.buyCnt': buyRecord.buyCnt } }, { new: true, upsert: true }).lean(); + } return result; } diff --git a/shared/domain/activityField/chongyangField.ts b/shared/domain/activityField/chongyangField.ts index 0775fa66f..a5695b294 100644 --- a/shared/domain/activityField/chongyangField.ts +++ b/shared/domain/activityField/chongyangField.ts @@ -21,6 +21,7 @@ interface ChongYangDataReturn extends ChongYangSceneDataInDb { buyCnt: number; // 累积到现在已经购买了的次数,buyCnt < maxBuyCnt 的时候才能购买 playCnt: number; // 累计到现在游戏的次数 maxPlayCnt: number; // 累计到现在可以游戏的最大次数 + isPushBuyRecord?: boolean; // } @@ -43,7 +44,7 @@ export class ChongYangData extends ActivityBase { const { dayIndex, dailyFreeCnt, dailyBuyCnt } = obj; let maxFreeCnt = dailyFreeCnt; - this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt }); + this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt, isPushBuyRecord: true }); } } @@ -54,23 +55,29 @@ export class ChongYangData extends ActivityBase { public updatePlayerRecord(playerData: ActivityChongYangRecModelType) { if (!playerData) return; let dayIndexUnlockAndSuccess = 1; - let buyRecordMap = new Map() - if (playerData.buyRecords) buyRecordMap = playerData.buyRecords.reduce((map, cur) => { map.set(cur.dayIndex, { ...cur }); return map; }, new Map()); if (playerData.gameRecords) { this.gameRecords = playerData.gameRecords; - for (let data of playerData.gameRecords) { - let { isSuccess, dayIndex } = data; + for (const { isSuccess, dayIndex } of playerData.gameRecords) { if (isSuccess) { dayIndexUnlockAndSuccess = Math.max(dayIndexUnlockAndSuccess, dayIndex); + let scene = this.sceneMap.get(dayIndex); - scene.buyCnt = buyRecordMap.get(dayIndex)?.buyCnt || 0; scene.playCnt += 1; - scene.maxPlayCnt = scene.buyCnt + scene.dailyFreeCnt; this.sceneMap.set(dayIndex, scene); }; + this.dayIndexUnlock = Math.max(this.dayIndexUnlock, dayIndex); } } + if (playerData.buyRecords) { + for (const { dayIndex, buyCnt = 0 } of playerData.buyRecords) { + let scene = this.sceneMap.get(dayIndex); + scene.isPushBuyRecord = false; + scene.buyCnt = buyCnt; + scene.maxPlayCnt = scene.buyCnt + scene.dailyFreeCnt; + this.sceneMap.set(dayIndex, scene); + } + } if (this.todayIndex > this.dayIndexUnlock && this.dayIndexUnlock == dayIndexUnlockAndSuccess) { this.dayIndexUnlock += 1;