只有周一才重置周榜
This commit is contained in:
parent
12c78ab264
commit
fb82166f64
@ -93,8 +93,8 @@ class RankController extends BaseController {
|
||||
@role('anon')
|
||||
@router('post /api/svr/games/rank/init')
|
||||
async update(req: any) {
|
||||
let { gameId, channelId } = req.params
|
||||
await new RankSchedule().initRankData({ gameId, channelId })
|
||||
let { gameId, channelId, refresh } = req.params
|
||||
await new RankSchedule().initRankData({ gameId, channelId, refresh })
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import logger from '../logger/logger'
|
||||
import { RankUser } from '../models/RankUser'
|
||||
import { delRankList, rankKey, updateRank } from '../services/rank.svr'
|
||||
import { fetchRankCfg, randomUsers } from '../services/jcfw.svr'
|
||||
import { getThisWeekData } from '../utils/time.util'
|
||||
|
||||
// 每天晚上1点更新
|
||||
const WORLD_RANK_TASK = '1 0 1 * * *'
|
||||
@ -16,15 +17,18 @@ export default class RankSchedule {
|
||||
* 移除n个, 同时补充n个机器人
|
||||
* 补充的n个机器人更新至总榜
|
||||
*/
|
||||
async initRankData({ gameId, channelId }) {
|
||||
async initRankData({ gameId, channelId, refresh }: { gameId: string; channelId: string; refresh?: boolean }) {
|
||||
let oldList = await RankUser.find({ gameId, channelId, isBot: true, type: 1 })
|
||||
const { startDay } = getThisWeekData()
|
||||
const today = new Date().format('yyyy-M-d')
|
||||
const needRest = today === startDay || refresh
|
||||
if (oldList.length > 0) {
|
||||
const removeCount = Math.random2(5, 10) | 0
|
||||
const maxRemoveCount = needRest ? Math.random2(5, 10) | 0 : Math.random2(2, 6) | 0
|
||||
let deleteCount = 0
|
||||
let tmpList = []
|
||||
for (let i = 0, l = oldList.length; i < l; i++) {
|
||||
let record = oldList[i]
|
||||
if (Math.random() > 0.5 && deleteCount <= removeCount) {
|
||||
if (Math.random() > 0.5 && deleteCount < maxRemoveCount) {
|
||||
record.type = 0
|
||||
await record.save()
|
||||
deleteCount++
|
||||
@ -50,7 +54,10 @@ export default class RankSchedule {
|
||||
}
|
||||
|
||||
let weekKey = rankKey(gameId, channelId, false)
|
||||
await delRankList(weekKey)
|
||||
if (needRest) {
|
||||
await delRankList(weekKey)
|
||||
}
|
||||
|
||||
let totalKey = rankKey(gameId, channelId, true)
|
||||
const { min, max, valType } = await fetchRankCfg(gameId, channelId)
|
||||
for (let record of oldList) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user