活动:招财进宝宝箱5点未领取发放邮箱
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 = '系统';
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -194,5 +194,12 @@
|
||||
"sendName": "&",
|
||||
"content": "竞技新赛季开始啦,您在上赛季的巅峰之路中有奖励尚未领取,现已发送至您邮箱,请查收",
|
||||
"time": 720
|
||||
},
|
||||
{
|
||||
"id": 28,
|
||||
"title": "&",
|
||||
"sendName": "&",
|
||||
"content": "您昨日在招财进宝中有宝箱没有领取,现已发送至您的邮箱,请查收",
|
||||
"time": 720
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user