后台:武将、装备列表
This commit is contained in:
@@ -4,6 +4,7 @@ import { COUNTER } from '../consts';
|
||||
import { CounterModel } from './Counter';
|
||||
import { HeroModel } from './Hero';
|
||||
import { RoleModel } from './Role';
|
||||
import { SearchEquipParam } from '@domain/backEndField/search';
|
||||
|
||||
export class RandSe {
|
||||
@prop({ required: true })
|
||||
@@ -192,6 +193,36 @@ export default class Equip extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static getSearchObj(form: SearchEquipParam) {
|
||||
let searchObj = {};
|
||||
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: SearchEquipParam = {}) {
|
||||
|
||||
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: EquipType[] = await EquipModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: SearchEquipParam = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await EquipModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const EquipModel = getModelForClass(Equip);
|
||||
|
||||
+32
-14
@@ -5,6 +5,7 @@ import { CounterModel } from './Counter';
|
||||
import { COUNTER, EQUIP_TYPE, HERO_CE_RATIO } from '../consts';
|
||||
import { reduceCe } from '../pubUtils/util';
|
||||
import Skin from './Skin';
|
||||
import { SearchHeroParam } from '@domain/backEndField/search';
|
||||
|
||||
type CeAttrUpdate = Partial<CeAttrData>;
|
||||
export class CeAttrData {
|
||||
@@ -300,20 +301,6 @@ export default class Hero extends BaseModel {
|
||||
return hero;
|
||||
}
|
||||
|
||||
public static async findByField(field: string, value?: number | string, lean = true) {
|
||||
let searchObj = {};
|
||||
if (field != 'all') {
|
||||
if (field == 'roleName') {
|
||||
searchObj['roleName'] = { $regex: new RegExp(value.toString(), 'i') }
|
||||
} else {
|
||||
searchObj[field] = value;
|
||||
}
|
||||
}
|
||||
//.select('uid tel username')
|
||||
const user: HeroType[] = await HeroModel.find(searchObj, {_id: 0}).lean(lean);
|
||||
return user;
|
||||
}
|
||||
|
||||
public static async getAllRank(serverId: number, select?: string, limit = 200) {
|
||||
let result: HeroType[] = await HeroModel.find({ serverId }, { _id: false }).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
|
||||
return result;
|
||||
@@ -328,6 +315,37 @@ export default class Hero extends BaseModel {
|
||||
let result: HeroType[] = await HeroModel.find({ serverId, hid }, { _id: false }).select(select).limit(limit).lean({ getters: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
private static getSearchObj(form: SearchHeroParam) {
|
||||
let searchObj = {};
|
||||
if(form.roleId) searchObj['roleId'] = form.roleId;
|
||||
if(form.roleName) searchObj['roleName'] = { $regex: new RegExp(form.roleName.toString(), 'i') };
|
||||
if(form.hid) searchObj['hid'] = form.hid;
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchHeroParam = {}) {
|
||||
|
||||
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: HeroType[] = await HeroModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: SearchHeroParam = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await HeroModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const HeroModel = getModelForClass(Hero);
|
||||
|
||||
@@ -8,4 +8,16 @@ export interface SearchRoleParam {
|
||||
uid?: number; // 玩家id
|
||||
roleId?: string; // 角色id
|
||||
roleName?: string; // 昵称
|
||||
}
|
||||
|
||||
export interface SearchHeroParam {
|
||||
roleId?: string;
|
||||
roleName?: string;
|
||||
hid?: number;
|
||||
}
|
||||
|
||||
export interface SearchEquipParam {
|
||||
roleId?: string;
|
||||
roleName?: string;
|
||||
id?: number;
|
||||
}
|
||||
Reference in New Issue
Block a user