用户信息增加返回rank

This commit is contained in:
zhl 2021-01-28 22:30:38 +08:00
parent 483af1973c
commit 41ca21e2ca
3 changed files with 27 additions and 1 deletions

View File

@ -4,7 +4,12 @@ import { Card } from '../models/subdoc/Card'
import { BaseConst } from '../constants/BaseConst' import { BaseConst } from '../constants/BaseConst'
import { BagItem, ItemType } from '../models/BagItem' import { BagItem, ItemType } from '../models/BagItem'
import { RedisClient } from '../redis/RedisClient' import { RedisClient } from '../redis/RedisClient'
import { checkGameing, setGameing, usersByScore } from '../service/rank' import {
checkGameing,
getRankScore,
setGameing,
usersByScore
} from '../service/rank'
import { fetchAccount } from '../dao/AccountDao' import { fetchAccount } from '../dao/AccountDao'
import { generateId } from '../utils/security.util' import { generateId } from '../utils/security.util'
import { getRandom } from '../utils/number.util' import { getRandom } from '../utils/number.util'
@ -32,6 +37,12 @@ export default class AccountController extends BaseController {
result.season_score = account.season_score result.season_score = account.season_score
result.season_data = account.season_data result.season_data = account.season_data
result.match_score = account.getMatchScore() result.match_score = account.getMatchScore()
let rank = await getRankScore(accountid)
if (typeof rank === 'string') {
result.rank = parseInt(rank)
} else {
result.rank = rank
}
return result return result
} }
@router('get /svr/:accountid/uinfo') @router('get /svr/:accountid/uinfo')

View File

@ -170,6 +170,15 @@ export class RedisClient {
}); });
} }
public async zrevrank(key: string, member: string) {
return new Promise((resolve, reject) => {
this.pub.zrevrank(key, member, (err, data) => {
if (err) { return reject(err); }
resolve(data);
});
});
}
public async hset(key: string, field: string, value: string) { public async hset(key: string, field: string, value: string) {
return new Promise((resolve) => { return new Promise((resolve) => {
this.pub.hset(key, field, value, resolve); this.pub.hset(key, field, value, resolve);

View File

@ -20,3 +20,9 @@ export async function checkGameing(accountid: string) {
return await new RedisClient().get('gameing_' + accountid) return await new RedisClient().get('gameing_' + accountid)
} }
export async function getRankScore(accountid: string) {
return await new RedisClient().zrevrank(BaseConst.RANK_SCORE, accountid)
}