后台:军团管理

This commit is contained in:
luying
2021-12-15 19:54:43 +08:00
parent 05e410d28f
commit 15b9d9f97a
19 changed files with 318 additions and 39 deletions
+38 -1
View File
@@ -5,6 +5,7 @@ import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, REDIS_KEY,
import { getZeroPoint, getZeroPointD, nowSeconds } from '../pubUtils/timeUtil';
import { reduceCe } from '../pubUtils/util';
import { gameData } from '../pubUtils/data';
import { SearchGuildParam } from '../domain/backEndField/search';
class Structure {
@prop({ required: true })
@@ -132,7 +133,7 @@ export default class Guild extends BaseModel {
return result;
}
public static async findByCondition(page: number, showPeopleMax: boolean, name: string, serverId: number) {
public static async getGuildList(page: number, showPeopleMax: boolean, name: string, serverId: number) {
const condition = { status: GUILD_STATUS.RUNNING, serverId };
if(!showPeopleMax) {
condition['isMemberMax'] = false;
@@ -193,6 +194,7 @@ export default class Guild extends BaseModel {
public static async dismiss(code: string, serverId: number) {
const result: GuildType = await GuildModel.findOneAndUpdate({ code, status: GUILD_STATUS.RUNNING, serverId }, { status: GUILD_STATUS.DISMISSED }, { new: true })
.populate('leader', {roleId: 1, _id: 0}, 'Role')
.select('+members').lean();
return result;
}
@@ -277,6 +279,41 @@ export default class Guild extends BaseModel {
const role: RoleType = await GuildModel.findOneAndUpdate({ code, serverId }, { $set: { sdkMark: true } }, { new: true }).select(select).lean({ getters, virtuals: true });
return role;
}
private static getSearchObj(form: SearchGuildParam) {
let searchObj = {};
if (form.serverId) searchObj['serverId'] = form.serverId;
if (form.name) searchObj['name'] = { $regex: new RegExp(form.name.toString(), 'i') };
return searchObj
}
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchGuildParam = {}) {
let searchObj = this.getSearchObj(form);
let sort = {};
if (sortField && sortOrder) {
if (sortOrder == 'ascend') {
sort[sortField] = 1;
} else if (sortOrder == 'descend') {
sort[sortField] = -1;
}
}
const result: GuildType[] = await GuildModel
.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort)
.select('-_id -__v -createdAt -updatedAt +serverId')
.populate('leader', { roleId: 1, roleName: 1, _id: 0 }, 'Role')
.lean({ getters: true, virtuals: true });
return result;
}
public static async countByCondition(form: SearchGuildParam = {}) {
let searchObj = this.getSearchObj(form);
const result = await GuildModel.count(searchObj);
return result;
}
}
export const GuildModel = getModelForClass(Guild);