🐞 fix(guild): 修复周一加入无活人军团领奖励问题
This commit is contained in:
@@ -225,9 +225,12 @@ export async function getUserGuildWithRefActive(roleId: string, select?: string)
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now);
|
||||
// console.log('####### isRefDaily', isRefDaily, refTimeDaily, now)
|
||||
if (isRefDaily) {
|
||||
userGuild = await UserGuildModel.resetDailyInfo(roleId);
|
||||
if (!userGuild) return false;
|
||||
if(refTimeDaily) {
|
||||
userGuild = await UserGuildModel.resetDailyInfoByRefTimeDaily(roleId, refTimeDaily);
|
||||
if (!userGuild) {
|
||||
userGuild = await UserGuildModel.getMyGuild(roleId, select ? select + ' wishGoods +refTimeDaily' : '+refTimeDaily');
|
||||
if (!userGuild) return false;
|
||||
};
|
||||
if (refTimeDaily) {
|
||||
await sendUnreceivedWishPool(wishGoods, roleId);
|
||||
await sendUnreceivedActiveBox(roleId, guildCode, refTimeDaily, receivedActive);
|
||||
await sendUnreceivedDonateBox(roleId, guildCode, refTimeDaily, receiveBoxs);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UserGuildModel, UserGuildType } from '../db/UserGuild';
|
||||
import { getArmyTrainJuDian, getGuildTrainGkInfo, getTrainBaseByLv } from '../pubUtils/data';
|
||||
import { nowSeconds, getZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { nowSeconds, getZeroPoint, isToday, getSeconds } from '../pubUtils/timeUtil';
|
||||
import { GUILD_STRUCTURE, PUSH_ROUTE } from '../consts';
|
||||
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
|
||||
import { GuildModel, GuildType } from '../db/Guild';
|
||||
@@ -165,11 +165,16 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
if (!guild) {//不满足重置条件,结束并解锁
|
||||
return trainId;
|
||||
}
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'trainRewards roleId', {});
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'trainRewards roleId createdAt', {});
|
||||
const guildTrains = await GuildTrainModel.getGuildTrainBoxs(code);
|
||||
|
||||
//结算未领取的宝箱奖励发送到邮件中
|
||||
userGuildList.forEach(async function ({roleId, trainRewards}) {
|
||||
userGuildList.forEach(async function ({roleId, trainRewards, createdAt}) {
|
||||
if (isToday(getSeconds(createdAt))) {
|
||||
// 此处发放的奖励是昨天该军团的奖励
|
||||
// 今天加入军团的玩家,不发放
|
||||
return;
|
||||
}
|
||||
let goods: { id: number, count: number }[] = [];
|
||||
guildTrains.forEach(guildTrain=>{
|
||||
guildTrain.trainInstances.forEach(({ trainBoxs, hid })=>{
|
||||
|
||||
@@ -175,8 +175,6 @@ export default class UserGuild extends BaseModel {
|
||||
update.receivedWishPool = [];
|
||||
update.wishGoods = [];
|
||||
update.wishDntCnt = 0;
|
||||
update.refTimeDaily = null;
|
||||
update.refBossTime = null;
|
||||
update.trainCount = 0;
|
||||
update.buyTrainCount = 0;
|
||||
update.trainTime = 0;
|
||||
@@ -192,7 +190,7 @@ export default class UserGuild extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findMyLastGuild(roleId: string, select: string) {
|
||||
const userGuild = await UserGuildModel.findOne({ roleId, status: { $ne: USER_GUILD_STATUS.ON } }).select(select).sort({ updatedAt: -1 }).lean();
|
||||
const userGuild = await UserGuildModel.findOne({ roleId, status: { $ne: USER_GUILD_STATUS.ON } }).select(select).sort({ createdAt: -1 }).lean();
|
||||
return userGuild;
|
||||
}
|
||||
|
||||
@@ -278,6 +276,13 @@ export default class UserGuild extends BaseModel {
|
||||
} }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async resetDailyInfoByRefTimeDaily(roleId: string, refTimeDaily: Date | null) {
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, refTimeDaily }, { $set: {
|
||||
receivedActive: [], refTimeDaily: new Date(), activeDaily: 0, activeRecord: [], wishGoods: [], receivedWishPool: [], receiveBoxs: [], wishDntCnt: 0, donateCnt: 0
|
||||
} }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
@@ -570,6 +570,22 @@ export function getFutureTime() {
|
||||
return moment('2100-01-01').unix();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是不是今天
|
||||
* 不是标准的0点-24点,时间区间是: 今天5点-明天5点
|
||||
*
|
||||
* @export
|
||||
* @param {number} time 单位:秒
|
||||
* @return {*} {Boolean}
|
||||
*/
|
||||
export function isToday(time: number): Boolean {
|
||||
return moment().format('YYYYMMDD') === moment(time * 1000).format('YYYYMMDD');
|
||||
// 今天5点
|
||||
const startSeconds = getSeconds(getZeroPointD());
|
||||
// 明天5点
|
||||
const endSeconds = startSeconds + DAY_TO_SECOND;
|
||||
if ((time > startSeconds) && (time < endSeconds)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user