diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 4276d59..fd33d68 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -4,7 +4,12 @@ import { Card } from '../models/subdoc/Card' import { BaseConst } from '../constants/BaseConst' import { BagItem, ItemType } from '../models/BagItem' 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 { generateId } from '../utils/security.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_data = account.season_data result.match_score = account.getMatchScore() + let rank = await getRankScore(accountid) + if (typeof rank === 'string') { + result.rank = parseInt(rank) + } else { + result.rank = rank + } return result } @router('get /svr/:accountid/uinfo') diff --git a/src/redis/RedisClient.ts b/src/redis/RedisClient.ts index 891db0b..ab0d6d4 100644 --- a/src/redis/RedisClient.ts +++ b/src/redis/RedisClient.ts @@ -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) { return new Promise((resolve) => { this.pub.hset(key, field, value, resolve); diff --git a/src/service/rank.ts b/src/service/rank.ts index dea3ca4..d090fa5 100644 --- a/src/service/rank.ts +++ b/src/service/rank.ts @@ -20,3 +20,9 @@ export async function checkGameing(accountid: string) { return await new RedisClient().get('gameing_' + accountid) } +export async function getRankScore(accountid: string) { + return await new RedisClient().zrevrank(BaseConst.RANK_SCORE, accountid) +} + + +