排行榜增加昵和头像的返回
This commit is contained in:
parent
4fb46bb48d
commit
1f4663ecb5
@ -43,6 +43,15 @@ class GameUserClass extends BaseModule {
|
|||||||
let records = await this.find({accountId}).limit(1)
|
let records = await this.find({accountId}).limit(1)
|
||||||
return records.length > 0 ? records[0] : null
|
return records.length > 0 ? records[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async userMapByAccountIDS(this: ReturnModelType<typeof GameUserClass>, accountIds: string[]) {
|
||||||
|
const records = await this.find({accountId: {$in: accountIds}})
|
||||||
|
let map: Map<string, any> = new Map()
|
||||||
|
for (let record of records) {
|
||||||
|
map.set(record.accountId, record)
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GameUser = getModelForClass(GameUserClass, {existingConnection: GameUserClass.db});
|
export const GameUser = getModelForClass(GameUserClass, {existingConnection: GameUserClass.db});
|
||||||
|
@ -17,6 +17,7 @@ import { ShopActivity } from '../models/shop/ShopActivity'
|
|||||||
import { getAccountRank, getRankCount, getRankList, updateRank } from './Rank'
|
import { getAccountRank, getRankCount, getRankList, updateRank } from './Rank'
|
||||||
import { PuzzleRank } from '../models/match/PuzzleRank'
|
import { PuzzleRank } from '../models/match/PuzzleRank'
|
||||||
import { UserReward } from '../models/UserReward'
|
import { UserReward } from '../models/UserReward'
|
||||||
|
import { GameUser } from '../models/GameUser'
|
||||||
|
|
||||||
|
|
||||||
export function transformRecord(records: any[]) {
|
export function transformRecord(records: any[]) {
|
||||||
@ -208,14 +209,24 @@ export async function getRank({shop, level, accountId, mode, skip, limit }
|
|||||||
level: number | string,
|
level: number | string,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
mode: number, skip: number, limit: number}) {
|
mode: number, skip: number, limit: number}) {
|
||||||
// let records = await PuzzleRank.find({shop, level, mode}).limit(limit).skip(skip).sort({'score': -1})
|
|
||||||
const key = rankKey(shop, level, mode)
|
const key = rankKey(shop, level, mode)
|
||||||
let datas: any = await getRankList(skip, limit, key)
|
let datas: any = await getRankList(skip, limit, key)
|
||||||
// let scoreMap: Map<any, number> = new Map()
|
|
||||||
let rankList: any[][] = []
|
let rankList: any[][] = []
|
||||||
|
let accountIDS: string[] = []
|
||||||
for (let i = 0, l = datas.length; i < l; i += 2) {
|
for (let i = 0, l = datas.length; i < l; i += 2) {
|
||||||
// scoreMap.set(datas[i], datas[i + 1] << 0)
|
|
||||||
rankList.push([datas[i], datas[i + 1] << 0])
|
rankList.push([datas[i], datas[i + 1] << 0])
|
||||||
|
accountIDS.push(datas[i])
|
||||||
|
}
|
||||||
|
const userMap = await GameUser.userMapByAccountIDS(accountIDS)
|
||||||
|
for (let d of rankList) {
|
||||||
|
if (userMap.has(d[0])) {
|
||||||
|
let u = userMap.get(d[0])
|
||||||
|
d.push(u.nickname || '')
|
||||||
|
d.push(u.avatar || '')
|
||||||
|
} else {
|
||||||
|
d.push('')
|
||||||
|
d.push('')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let userRank = (await getAccountRank(accountId, key)) || 999
|
let userRank = (await getAccountRank(accountId, key)) || 999
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user