diff --git a/game-server/app/servers/activity/handler/dailyCoinHandler.ts b/game-server/app/servers/activity/handler/dailyCoinHandler.ts index 6935fa305..a170700d7 100644 --- a/game-server/app/servers/activity/handler/dailyCoinHandler.ts +++ b/game-server/app/servers/activity/handler/dailyCoinHandler.ts @@ -121,13 +121,13 @@ export class DailyCoinHandler { //免费期间 let time = moment(new Date()).valueOf(); let result = await addReward(roleId, roleName, sid, serverId, newReward, ITEM_CHANGE_REASON.DAILY_COIN_EXCHANGE); - let record = await ActivityDailyCoinModel.addExchangeRecord(serverId, activityId, roleId, playerData.roundIndex, count, addCoin, `${count}&${consumeGold}&${addCoin}&${time}`); - let extraReward = playerData.setAllBoxStatus(record); - let exchangeCount = playerData.exchangeCount + count; + let extraReward = playerData.addExchangeCount(count); + await ActivityDailyCoinModel.addExchangeRecord(serverId, activityId, roleId, playerData.roundIndex, count, addCoin, `${count}&${consumeGold}&${addCoin}&${time}`, playerData.hasNotReceivedBox()); + return resResult(STATUS.SUCCESS, Object.assign(result, { param: { activityId, count, extraReward }, - item: { exchangeCount, recordMsg: `${count}&${consumeGold}&${addCoin}&${time}`, rateArray }, + item: { exchangeCount: playerData.exchangeCount, recordMsg: `${count}&${consumeGold}&${addCoin}&${time}`, rateArray }, })); } @@ -155,8 +155,8 @@ export class DailyCoinHandler { let rewardArray = stringToRewardParam(box.reward) let result = await addReward(roleId, roleName, sid, serverId, rewardArray, ITEM_CHANGE_REASON.ACT_DAILY_COIN_RECEIVE_BOX); - let record = await ActivityDailyCoinModel.receiveBox(serverId, activityId, roleId, playerData.roundIndex, cellIndex); - let item = playerData.setBoxStatus(cellIndex, record); + let item = playerData.receiveBox(cellIndex); + await ActivityDailyCoinModel.receiveBox(serverId, activityId, roleId, playerData.roundIndex, cellIndex, playerData.hasNotReceivedBox()); return resResult(STATUS.SUCCESS, Object.assign(result, { item, diff --git a/game-server/app/services/activity/dailyCoinService.ts b/game-server/app/services/activity/dailyCoinService.ts index 7209ffc47..d90fbf2be 100644 --- a/game-server/app/services/activity/dailyCoinService.ts +++ b/game-server/app/services/activity/dailyCoinService.ts @@ -1,9 +1,13 @@ -import { ACTIVITY_TYPE } from '../../consts'; +import { ACTIVITY_TYPE, MAIL_TYPE, REFRESH_TIME } from '../../consts'; import { ActivityModel, ActivityModelType } from '../../db/Activity'; import { ActivityDailyCoinModel, ActivityDailyCoinModelType } from '../../db/ActivityDailyCoin'; import { RoleModel } from '../../db/Role'; -import { ServerlistModel } from '../../db/Serverlist'; +import { ServerlistModel, ServerlistType } from '../../db/Serverlist'; import { DailyCoinData } from '../../domain/activityField/dailyCoinField'; +import { RewardInter } from '../../pubUtils/interface'; +import { stringWithTypeToRewardInter } from '../../pubUtils/roleUtil'; +import { getZeroPointD, getZeroPointOfTimeD } from '../../pubUtils/timeUtil'; +import { sendMailByContent } from '../mailService'; import { getRoleCreateTime, getServerCreateTime } from '../redisService'; import { getActivitiesByType, getActivityById } from './activityService'; @@ -27,6 +31,40 @@ export async function getPlayerDailyCoinData(activityId: number, serverId: numbe return playerData; } +export async function sendUnReceivedActivityDailyCoin(servers: ServerlistType[]) { + let today = new Date().setHours(REFRESH_TIME, 0, 0, 0); + let yesterday = today - 86400000; + let unreceivedRecord = await ActivityDailyCoinModel.findUnreceivedBox(new Date(yesterday), new Date(today)); + for(let { serverId } of servers) { + let serverTime = await getServerCreateTime(serverId); + let activities = await getActivitiesByType(serverId, ACTIVITY_TYPE.DAILY_COIN); + for(let activityData of activities) { + for(let playerRecord of unreceivedRecord) { + if(playerRecord.activityId != activityData.activityId) continue; + if(playerRecord.serverId != serverId) continue; + await sendUnReceivedRecor(activityData, playerRecord, serverTime); + } + } + } +} + +async function sendUnReceivedRecor(activityData: ActivityModelType, playerRecord: ActivityDailyCoinModelType, serverTime: number) { + let createTime = await getRoleCreateTime(playerRecord.roleId); + + let playerData = new DailyCoinData(activityData, createTime, serverTime); + playerData.setPlayerRecords(playerRecord); + let unreceivedRecord = playerData.getUnReceivedBox(); + if(unreceivedRecord.length > 0) { + let rewards: RewardInter[] = [], boxIds: number[] = []; + for(let { cellIndex, reward } of unreceivedRecord) { + rewards.push(...stringWithTypeToRewardInter(reward)); + boxIds.push(cellIndex); + } + await sendMailByContent(MAIL_TYPE.DAILY_COIN, playerRecord.roleId, { goods: rewards }); + await ActivityDailyCoinModel.repaireBox(playerRecord._id, boxIds); + } +} + export function mergeData(data: any[]) { let newDate = []; for (let item of data) { diff --git a/game-server/app/services/guildActivity/guildActivityService.ts b/game-server/app/services/guildActivity/guildActivityService.ts index c46f9cd70..901c8b234 100644 --- a/game-server/app/services/guildActivity/guildActivityService.ts +++ b/game-server/app/services/guildActivity/guildActivityService.ts @@ -1,4 +1,4 @@ -import { ServerlistModel } from "../../db/Serverlist"; +import { ServerlistModel, ServerlistType } from "../../db/Serverlist"; import { RoleModel } from "../../db/Role"; import { GUILDACTIVITY } from "../../pubUtils/dicParam"; import { gameData, getGuildAuctionRewards, getCityActivityRewards } from "../../pubUtils/data"; @@ -54,8 +54,7 @@ export function getRaceActivityObj() { /** * 定时任务,获得前一天的活跃玩家中位数武将战力 */ -export async function setPreDayActiveData() { - let servers = await ServerlistModel.findByEnv(pinus.app.get('env')); +export async function setPreDayActiveData(servers: ServerlistType[]) { for (let server of servers) { let roles = await RoleModel.getActivePlayers(server.id); diff --git a/game-server/app/services/timeTaskService.ts b/game-server/app/services/timeTaskService.ts index 080789c4c..db3c1d804 100644 --- a/game-server/app/services/timeTaskService.ts +++ b/game-server/app/services/timeTaskService.ts @@ -38,6 +38,7 @@ import { sendMessageToServer } from './pushService'; import { resResult } from '../pubUtils/util'; import { checkPopUpConditionWhenGuildActivityEnd } from './activity/popUpShopService'; import { pushRefreshTime } from './connectorService'; +import { sendUnReceivedActivityDailyCoin } from './activity/dailyCoinService'; const PER_SECOND = 1 * 1000; const PER_DAY = 24 * 60 * 60; @@ -99,9 +100,11 @@ export async function init() { // 每日刷新 export async function everydayRefresh() { + let servers = await ServerlistModel.findByEnv(pinus.app.get('env')); pushRefreshTime(); - setPreDayActiveData(); + setPreDayActiveData(servers); sendUngotDividendJob(); + sendUnReceivedActivityDailyCoin(servers); } diff --git a/shared/consts/constModules/mailConst.ts b/shared/consts/constModules/mailConst.ts index e64b2876b..a3416fc74 100644 --- a/shared/consts/constModules/mailConst.ts +++ b/shared/consts/constModules/mailConst.ts @@ -54,6 +54,7 @@ export enum MAIL_TYPE { GUILD_FUND_BOX = 25, // 军团每日捐献宝箱补领 GUILD_BOSS = 26, // 军团boss奖励 PVP_BOX = 27, // pvp巅峰之路宝箱 + DAILY_COIN = 28, // 招财进宝宝箱 }; export const SEND_NAME = '系统'; diff --git a/shared/db/ActivityDailyCoin.ts b/shared/db/ActivityDailyCoin.ts index a98cf7b25..079061100 100644 --- a/shared/db/ActivityDailyCoin.ts +++ b/shared/db/ActivityDailyCoin.ts @@ -25,20 +25,25 @@ export default class Activity_Daily_Coin extends BaseModel { @prop({ required: true }) roundIndex: number; // 周期数 @prop({ required: true, type: Number }) - receivedBox: number[]; // 周期数 + receivedBox: number[]; // 已领取宝箱 + @prop({ required: true }) + hasNotReceivedBox: boolean; // 是否有没有领取的宝箱 + + @prop({ required: true }) + repaireBoxed: number[]; // 是否有没有领取的宝箱 //兑换记录 - public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, count: number, coinCount: number, msg: string) { + public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, count: number, coinCount: number, msg: string, hasNotReceivedBox: boolean) { let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, roundIndex }, - { $inc: { exchangeCount: count, coinCount: coinCount }, $push: { recordMsg: msg } }, { upsert: true, new: true }).lean(true) + { $inc: { exchangeCount: count, coinCount: coinCount }, $push: { recordMsg: msg }, $set: { hasNotReceivedBox } }, { upsert: true, new: true }).lean(true) return result; } // 领取宝箱 - public static async receiveBox(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) { + public static async receiveBox(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, hasNotReceivedBox: boolean) { let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, roundIndex }, - { $push: { receivedBox: cellIndex } }, { upsert: true, new: true }).lean(true) + { $push: { receivedBox: cellIndex }, $set: { hasNotReceivedBox } }, { upsert: true, new: true }).lean(true) return result; } @@ -50,6 +55,21 @@ export default class Activity_Daily_Coin extends BaseModel { return result; } + // 未发放完 + public static async findUnreceivedBox(beginTime: Date, endTime: Date) { + let result: ActivityDailyCoinModelType[] = await ActivityDailyCoinModel.find({ + createdAt: { $gte: beginTime, $lte: endTime }, hasNotReceivedBox: true + }).lean(true); + return result; + } + + // 凌晨5点补发邮箱 + public static async repaireBox(_id: string, boxIds: number[]) { + let result = await ActivityDailyCoinModel.findByIdAndUpdate({ _id }, + { $push: { repaireBoxed: { $each: boxIds } } }, { upsert: true, new: true }).lean(true) + return result; + } + //删除活动兑换记录 public static async deleteActivity(serverId: number, activityId: number, roleId: string, roundIndex: number) { await ActivityDailyCoinModel.deleteMany({ serverId, roleId, activityId, roundIndex }); diff --git a/shared/domain/activityField/dailyCoinField.ts b/shared/domain/activityField/dailyCoinField.ts index c249bd659..3bf9847b2 100644 --- a/shared/domain/activityField/dailyCoinField.ts +++ b/shared/domain/activityField/dailyCoinField.ts @@ -73,6 +73,16 @@ export class ExtraRewardItem { if(count >= this.exchangeCount) this.status = DAILY_COIN_BOX_STATUS.CAN_OPEN; if(receivedBox.indexOf(this.cellIndex) != -1) this.status = DAILY_COIN_BOX_STATUS.RECEIVED; } + + addExchangeCount(exchangeCount: number) { + if(this.status == DAILY_COIN_BOX_STATUS.CAN_NOT_OPEN && exchangeCount >= this.exchangeCount) { + this.status = DAILY_COIN_BOX_STATUS.CAN_OPEN; + } + } + + receiveBox() { + this.status = DAILY_COIN_BOX_STATUS.RECEIVED; + } } // 每日兑换铜币活动数据 @@ -122,27 +132,41 @@ export class DailyCoinData extends ActivityBase { this.exchangeCount = data.exchangeCount||0; this.coinCount = data.coinCount || 0; this.recordMsg = data.recordMsg || []; - this.setAllBoxStatus(data); + for(let box of this.extraReward) { + box.setRecord(this.exchangeCount, data.receivedBox||[]); + } } public findBoxByCellIndex(cellIndex: number) { return this.extraReward.find(cur => cur.cellIndex == cellIndex); } - public setAllBoxStatus(data: ActivityDailyCoinModelType) { + public addExchangeCount(count: number) { + this.exchangeCount += count; for(let box of this.extraReward) { - box.setRecord(this.exchangeCount, data.receivedBox||[]); + box.addExchangeCount(this.exchangeCount); } return this.extraReward; } - public setBoxStatus(cellIndex: number, data: ActivityDailyCoinModelType) { + public receiveBox(cellIndex: number) { let item = this.extraReward.find(cur => cur.cellIndex == cellIndex); if(!item) return null; - item.setRecord(data.exchangeCount, data.receivedBox||[]); + item.receiveBox(); return item } + public hasNotReceivedBox(): boolean { + for(let box of this.extraReward) { + if(box.status == DAILY_COIN_BOX_STATUS.CAN_OPEN) return true; + } + return false; + } + + public getUnReceivedBox() { + return this.extraReward.filter(cur => cur.status == DAILY_COIN_BOX_STATUS.CAN_OPEN); + } + public initData(data: string) { this.exchangeCount = 0; this.coinCount = 0; diff --git a/shared/resource/jsons/dic_email_content.json b/shared/resource/jsons/dic_email_content.json index a0ab4763f..081f8c95c 100644 --- a/shared/resource/jsons/dic_email_content.json +++ b/shared/resource/jsons/dic_email_content.json @@ -194,5 +194,12 @@ "sendName": "&", "content": "竞技新赛季开始啦,您在上赛季的巅峰之路中有奖励尚未领取,现已发送至您邮箱,请查收", "time": 720 + }, + { + "id": 28, + "title": "&", + "sendName": "&", + "content": "您昨日在招财进宝中有宝箱没有领取,现已发送至您的邮箱,请查收", + "time": 720 } ] \ No newline at end of file