添加天梯排行榜,修复setHour有时差的bug

This commit is contained in:
luying
2020-11-06 17:31:23 +08:00
parent bd93d9dc1c
commit 04ecef03b5
29 changed files with 285 additions and 148 deletions
+7 -4
View File
@@ -1,5 +1,8 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
import { DAILY_CONST } from './../consts/consts';
import { setLocalHours } from './../pubUtils/util';
/**
* 战斗记录接口
@@ -27,11 +30,11 @@ export default class DailyRecord extends BaseModel {
const dailyRecord = await DailyRecordModel.findOne({ roleId, type }).lean(lean);
let {count = 0, refTime = 0, buyCount = 0} = dailyRecord||{};
let now = new Date();
let today = now.setHours(0, 0, 0, 0);
let today = setLocalHours(DAILY_CONST.REFRESH_TIME, now);
console.log('******dailyTime*******', today, now, new Date(), refTime);
if(today > refTime) {
refTime = today;
count = 0;
buyCount = 0;
refTime = today; count = 0; buyCount = 0;
}
let result = await DailyRecordModel.findOneAndUpdate({roleId, type}, {$set: {refTime, count, buyCount}}, {new: true, upsert: true});
return result;