时间:整理时间方法

This commit is contained in:
luying
2021-05-08 19:13:44 +08:00
parent 6f03a96c51
commit 78e3c26a7a
51 changed files with 662 additions and 411 deletions
+5 -5
View File
@@ -1,10 +1,10 @@
import { HANG_UP_CONSTS, ROLE_TERAPH, ROLE_SELECT, ABI_TYPE } from './../consts';
import { HANG_UP_CONSTS, ROLE_TERAPH, ROLE_SELECT, ABI_TYPE, TIME_OUTPUT_TYPE } from './../consts';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref, mongoose } from '@typegoose/typegoose';
import User from './User';
import { shouldRefresh, reduceCe } from '../pubUtils/util';
import { initRoleAtrr } from '../pubUtils/playerCe';
import { nowSeconds, getBeforeDayDate } from '../pubUtils/timeUtil';
import { nowSeconds, getTimeFunD } from '../pubUtils/timeUtil';
import { Figure } from '../domain/dbGeneral';
import { EXTERIOR } from '../pubUtils/dicParam';
import Hero from './Hero';
@@ -360,7 +360,7 @@ export default class Role extends BaseModel {
const result = await RoleModel.findOne({ roleId }).lean(lean);
const lastSpdUpTime = result?.lastSpdUpTime;
let role: RoleType;
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && cnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime) && cnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
role = await RoleModel.findOneAndUpdate({ roleId }, { hangUpSpdUpCnt: HANG_UP_CONSTS.MAX_SPD_UP_CNT - cnt, lastSpdUpTime: curTime }, { new: true }).lean(lean);
} else {
role = await RoleModel.findOneAndUpdate({ roleId, hangUpSpdUpCnt: { $gte: cnt } }, { $inc: { hangUpSpdUpCnt: -cnt }, lastSpdUpTime: curTime }, { new: true }).lean(lean);
@@ -634,8 +634,8 @@ export default class Role extends BaseModel {
// 获取战力在中位数的玩家
public static async getMedianRole(serverId: number) {
let yesterday = getBeforeDayDate(1);
const roles: RoleType[] = await RoleModel.find({ serverId, updatedAt: { $gte: new Date(yesterday) } })
let yesterday = <Date>getTimeFunD().getBeforeDayWithHour(1);
const roles: RoleType[] = await RoleModel.find({ serverId, updatedAt: { $gte: yesterday } })
.select('topLineup')
.sort({ ce: -1 }).lean();
return roles[Math.floor(roles.length / 2)]