redis 排行榜分区

This commit is contained in:
luying
2020-11-23 16:29:21 +08:00
parent d8e2c609cb
commit aa5dc07b86
8 changed files with 72 additions and 23 deletions
+9
View File
@@ -55,6 +55,15 @@ export default class Game extends BaseModel {
@prop({ required: true })
versionCode: number;
public static async getAllServerList() {
let game = await GameModel.findOne().lean();
if(game) {
return game.serverList;
} else {
return []
}
}
public static async getServerListByType(serverType: string) {
let game = await GameModel.findOne().lean();
if (!game) {
+2 -2
View File
@@ -339,13 +339,13 @@ export default class Role extends BaseModel {
}
// 获取排行榜
public static async getRank(type: string, fields: Array<string>, page = 1, limit = 100, lean = true) {
public static async getRank(type: string, serverId: number, fields: Array<string>, page = 1, limit = 100, lean = true) {
let sortBy = {};
if(type == 'tower') {
sortBy['towerLv'] = -1;
sortBy['towerUpTime'] = 1;
}
const ranks = await RoleModel.find().select(fields.join(' ')).sort(sortBy).limit(limit).skip((page - 1) * limit).lean(lean);
const ranks = await RoleModel.find({serverId}).select(fields.join(' ')).sort(sortBy).limit(limit).skip((page - 1) * limit).lean(lean);
return ranks;
}