排行榜增加返回总人数

This commit is contained in:
zhl 2021-05-19 15:10:05 +08:00
parent b50c87cbb9
commit 665a69ff39
5 changed files with 18 additions and 10 deletions

View File

@ -179,8 +179,8 @@
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | 店铺id |
| level | 关卡id |
| mode | 游戏类型, 0: 单人, 1: 多人 |
| level | 关卡id |
| mode | 游戏类型, 0: 单人, 1: 多人, 2: 挑战 |
| skip | 数据开始的偏移值, 从0开始, 默认0 |
| limit | 每次返回的数量条数, 默认10 |
@ -196,7 +196,8 @@
'nickname', 昵称(暂无)
'avatar' 头像
]
]
],
rankTotal: 99 排行榜总人数
}
```

View File

@ -132,14 +132,15 @@ class ExamController extends BaseController {
level: history.activityId,
accountId: accountid,
score: statMap.score,
mode: 0,
mode: 2,
session: history.id
}
await history.save()
await updateExamRank(rankObj)
let {rankList, userRank } = await getRank({shop: history.shop, level: history.activityId, accountId: accountid, mode: 0, skip: 0, limit: 20})
let {rankList, userRank, rankTotal } = await getRank({shop: history.shop, level: history.activityId, accountId: accountid, mode: 2, skip: 0, limit: 20})
rspData.rankList = rankList
rspData.userRank = userRank
rspData.rankTotal = rankTotal
}
rspData.gameResult = gameResult
return rspData

View File

@ -291,11 +291,11 @@ class PuzzleController extends BaseController {
@role('anon')
@router('post /api/:accounid/puzzle/rank')
async singleRank(req, res) {
async singleRank(req) {
let {shop, level, accountid, mode, skip, limit} = req.params
skip = skip || 0
limit = limit || 10
let {rankList, userRank } = await getRank({shop, level, accountId: accountid, mode, skip, limit})
return {rankList, userRank}
let {rankList, userRank, rankTotal} = await getRank({shop, level, accountId: accountid, mode, skip, limit})
return {rankList, userRank, rankTotal}
}
}

View File

@ -14,7 +14,7 @@ import { GameEnv } from '../config/GameEnv'
import { Shop } from '../models/shop/Shop'
import { mission_vo } from '../config/parsers/mission_vo'
import { ShopActivity } from '../models/shop/ShopActivity'
import { getAccountRank, getRankList, updateRank } from './Rank'
import { getAccountRank, getRankCount, getRankList, updateRank } from './Rank'
import { PuzzleRank } from '../models/match/PuzzleRank'
@ -185,7 +185,9 @@ export async function getRank({shop, level, accountId, mode, skip, limit }
rankList.push([datas[i], datas[i + 1] << 0])
}
let userRank = (await getAccountRank(accountId, key)) || 999
return {rankList, userRank}
let rankTotal = (await getRankCount(key))
return {rankList, userRank, rankTotal}
}
/**

View File

@ -72,6 +72,10 @@ export async function getRankList(start: number, end: number, subKey?: string) {
return await new RedisClient().zrevrange(generateRankKey(subKey), start, end)
}
export async function getRankCount(subKey?: string) {
return await new RedisClient().zcard(generateRankKey(subKey))
}
/**
*
* @param {string} accountId