后台:军团管理

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);
+27 -9
View File
@@ -2,6 +2,7 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { findIndex } from 'underscore';
import { BAG } from '../pubUtils/dicParam';
import { SearchItemParam } from '../domain/backEndField/search';
// const Transaction = require("mongoose-transactions");
@index({ roleId: 1, id: 1 })
@index({ seqId: 1 })
@@ -101,18 +102,35 @@ export default class Item extends BaseModel {
return result;
}
public static async findByField(field: string, value?: number|string, lean = true) {
private static getSearchObj(form: SearchItemParam) {
let searchObj = {};
if(field != 'all') {
if(field == 'roleName') {
searchObj['roleName'] = { $regex: new RegExp(value.toString(), 'i') }
} else {
searchObj[field] = value;
if (form.roleId) searchObj['roleId'] = form.roleId;
if (form.roleName) searchObj['roleName'] = { $regex: new RegExp(form.roleName.toString(), 'i') };
if (form.id) searchObj['id'] = form.id;
return searchObj
}
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchItemParam = {}) {
let searchObj = this.getSearchObj(form);
let sort = {};
if (sortField && sortOrder) {
if (sortOrder == 'ascend') {
sort[sortField] = 1;
} else if (sortOrder == 'descend') {
sort[sortField] = -1;
}
}
//.select('uid tel username')
const user: ItemType[] = await ItemModel.find(searchObj).lean(lean);
return user;
const result: ItemType[] = await ItemModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).select('-_id -__v -createdAt -updatedAt').lean({ getters: true, virtuals: true });
return result;
}
public static async countByCondition(form: SearchItemParam = {}) {
let searchObj = this.getSearchObj(form);
const result = await ItemModel.count(searchObj);
return result;
}
}
+37
View File
@@ -225,4 +225,41 @@ export class UpdateGiftCode {
if(!isNumber(this.codeLen) || this.codeLen <= 0) return false;
return true;
}
}
export class GuildFormParam {
code: string;
name: string;
notice: string;
fund: number;
lv: number;
equipProduce: number;
boss: number;
train: number;
wishPool: number;
store: number;
donate: number;
constructor(obj?: any) {
if(obj) {
for(let key in obj) {
this[key] = obj[key];
}
}
}
checkParams() {
if(!this.code || !isString(this.code)) return false;
if(this.name && !isString(this.name)) return false;
if(this.notice && !isString(this.notice)) return false;
if(this.fund && !isNumber(this.fund)) return false;
if(this.lv && !isNumber(this.lv)) return false;
if(this.equipProduce && !isNumber(this.equipProduce)) return false;
if(this.boss && !isNumber(this.boss)) return false;
if(this.train && !isNumber(this.train)) return false;
if(this.wishPool && !isNumber(this.wishPool)) return false;
if(this.store && !isNumber(this.store)) return false;
if(this.donate && !isNumber(this.donate)) return false;
return true;
}
}
+11
View File
@@ -24,6 +24,17 @@ export interface SearchEquipParam {
id?: number;
}
export interface SearchItemParam {
roleId?: string;
roleName?: string;
id?: number;
}
export interface SearchGuildParam {
serverId?: number;
name?: string;
}
export interface SearchMailParam {
createTimeStart?: number;
createTimeEnd?: number;