后台:武将、装备列表
This commit is contained in:
@@ -72,14 +72,14 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getHeroList() {
|
||||
const { ctx } = this;
|
||||
const { field, value } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getHeroList(field, value);
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getHeroList(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
public async deleteHero() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndHids } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteHero(roleIdAndHids);
|
||||
const { roleId, hid } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteHero(roleId, parseInt(hid));
|
||||
}
|
||||
|
||||
public async setHeroLv() {
|
||||
@@ -114,8 +114,8 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getEquipList() {
|
||||
const { ctx } = this;
|
||||
const { field, value } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getEquipList(field, value);
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getEquipList(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
public async getItemList() {
|
||||
|
||||
@@ -34,9 +34,9 @@ export default (app: Application) => {
|
||||
router.post('/api/users/getpvpdefense',tokenParser, controller.users.getPveDefense);
|
||||
router.post('/api/users/getherolist',tokenParser, controller.users.getHeroList);
|
||||
router.post('/api/users/deletehero', tokenParser, controller.users.deleteHero);
|
||||
router.post('/api/users/setherolv', tokenParser, controller.users.setHeroLv);
|
||||
router.post('/api/users/setheroparam', controller.users.setHeroParam);
|
||||
router.post('/api/users/setherojob', controller.users.setHeroJob);
|
||||
// router.post('/api/users/setherolv', tokenParser, controller.users.setHeroLv);
|
||||
// router.post('/api/users/setheroparam', controller.users.setHeroParam);
|
||||
// router.post('/api/users/setherojob', controller.users.setHeroJob);
|
||||
// router.post('/api/users/saveherotodefense',tokenParser, controller.users.saveHeroToDefense);
|
||||
// router.post('/api/users/removeherofromdefense',tokenParser, controller.users.removeHeroFromDefense);
|
||||
router.post('/api/users/getequiplist', tokenParser, controller.users.getEquipList);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { CreateHeroes, deletRole } from '@pubUtils/roleUtil';
|
||||
import { RScriptRecordModel } from '@db/RScriptRecord';
|
||||
import { DicWar } from '@pubUtils/dictionary/DicWar';
|
||||
import { SkinModel } from '@db/Skin';
|
||||
import { SearchUserParam } from '@domain/backEndField/search';
|
||||
import { SearchEquipParam, SearchHeroParam, SearchUserParam } from '@domain/backEndField/search';
|
||||
|
||||
// import { resResult } from '@pubUtils/util';
|
||||
|
||||
@@ -390,12 +390,12 @@ export default class GMUsers extends Service {
|
||||
/**
|
||||
* 根据类型等搜索玩家
|
||||
*/
|
||||
public async getHeroList(field: string, value: (string | number)) {
|
||||
public async getHeroList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchHeroParam) {
|
||||
const { ctx } = this;
|
||||
|
||||
let heroes = await HeroModel.findByField(field, value);
|
||||
const heroes = await HeroModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await HeroModel.countByCondition( form )
|
||||
|
||||
if (heroes) {
|
||||
let roleMap = new Map<string, CeAttrDataRole[]>();
|
||||
for(let { roleId } of heroes) {
|
||||
if(!roleMap.has(roleId)) {
|
||||
@@ -406,35 +406,26 @@ export default class GMUsers extends Service {
|
||||
let list = heroes.map(cur => {
|
||||
let cal = new AttributeCal();
|
||||
cal.setByDbData(roleMap.get(cur.roleId), cur.attr);
|
||||
return {...cur, calculatedAttr: cal.getReduceAttributesToArr()}
|
||||
return {...cur, calculatedAttr: cal.getReduceAttributesToArr(), env: ctx.app.config.realEnv}
|
||||
})
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list });
|
||||
} else {
|
||||
console.error('role list not found');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
}
|
||||
|
||||
|
||||
public async deleteHero(roleIdAndHids: string[]) {
|
||||
public async deleteHero(roleId: string, hid: number) {
|
||||
console.log('enter Auth deleteRole');
|
||||
const ctx = this.ctx;
|
||||
for (let roleIdAndHid of roleIdAndHids) {
|
||||
let [roleId, hidStr] = roleIdAndHid.split('|');
|
||||
if (isNaN(parseInt(hidStr))) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let hid = parseInt(hidStr);
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) continue;
|
||||
if (!hero) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
await HeroModel.deleteHero(roleId, hid);
|
||||
await SkinModel.deleteByHero(roleId, hid);
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
await calculatetopLineup(role, hid, 0, null);
|
||||
await PvpDefenseModel.deleteHero(roleId, hid);
|
||||
await RoleModel.updateRoleInfo(roleId, { topLineup: role.topLineup, topLineupCe: role.topLineupCe, ce: role.ce - hero.ce });
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -595,19 +586,25 @@ export default class GMUsers extends Service {
|
||||
/**
|
||||
* 根据类型等搜索装备
|
||||
*/
|
||||
public async getEquipList(field: string, value: (string | number)) {
|
||||
public async getEquipList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchEquipParam) {
|
||||
const { ctx } = this;
|
||||
|
||||
let equips = await EquipModel.findByField(field, value);
|
||||
const heroes = await EquipModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await EquipModel.countByCondition( form )
|
||||
|
||||
if (equips) {
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list: equips });
|
||||
} else {
|
||||
console.error('role list not found');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
let roleMap = new Map<string, CeAttrDataRole[]>();
|
||||
for(let { roleId } of heroes) {
|
||||
if(!roleMap.has(roleId)) {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'attr');
|
||||
roleMap.set(roleId, role.attr);
|
||||
}
|
||||
}
|
||||
let list = heroes.map(cur => {
|
||||
return {...cur, env: ctx.app.config.realEnv}
|
||||
})
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,3 +9,15 @@ export interface SearchRoleParam {
|
||||
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