后台:添加武将,装备,道具
This commit is contained in:
@@ -11,11 +11,22 @@ export default class UserController extends Controller {
|
||||
|
||||
public async createRole() {
|
||||
const { ctx } = this;
|
||||
const { uid, roleName } = ctx.request.body;
|
||||
const serverId = 1;
|
||||
const { uid, roleName, serverId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.createRole(uid, serverId, roleName);
|
||||
}
|
||||
|
||||
public async addAuth() {
|
||||
const { ctx } = this;
|
||||
const { uid, auth } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.addAuth(uid, auth);
|
||||
}
|
||||
|
||||
public async fixSms() {
|
||||
const { ctx } = this;
|
||||
const { tel } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.fixSms(tel);
|
||||
}
|
||||
|
||||
public async deleteRole() {
|
||||
const { ctx } = this;
|
||||
const { roleId } = ctx.request.body;
|
||||
@@ -59,8 +70,20 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getHeroList() {
|
||||
const { ctx } = this;
|
||||
const { roleId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getHeroList(roleId);
|
||||
const { field, value } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getHeroList(field, value);
|
||||
}
|
||||
|
||||
public async deleteHero() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndHids } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteHero(roleIdAndHids);
|
||||
}
|
||||
|
||||
public async setHeroLv() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndHids, lv } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.setHeroLv(roleIdAndHids, lv);
|
||||
}
|
||||
|
||||
public async saveHeroToDefense() {
|
||||
@@ -74,4 +97,34 @@ export default class UserController extends Controller {
|
||||
const { roleId, hid } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.removeHeroFromDefense(roleId, hid);
|
||||
}
|
||||
|
||||
public async getEquipList() {
|
||||
const { ctx } = this;
|
||||
const { field, value } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getEquipList(field, value);
|
||||
}
|
||||
|
||||
public async getItemList() {
|
||||
const { ctx } = this;
|
||||
const { field, value } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getItemList(field, value);
|
||||
}
|
||||
|
||||
public async deleteEquip() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndSeqIds } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteEquip(roleIdAndSeqIds);
|
||||
}
|
||||
|
||||
public async deleteItem() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndIds } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteItem(roleIdAndIds);
|
||||
}
|
||||
|
||||
public async setItemCount() {
|
||||
const { ctx } = this;
|
||||
const { selectedRowKeys: roleIdAndIds, count } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.setItemCount(roleIdAndIds, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,20 @@ export default (app: Application) => {
|
||||
|
||||
router.post('/api/users/getuserlist',tokenParser, controller.users.getuserlist);
|
||||
router.post('/api/users/createrole',tokenParser, controller.users.createRole);
|
||||
router.post('/api/users/addauth', controller.users.addAuth);
|
||||
router.post('/api/users/fixsms', controller.users.fixSms);
|
||||
router.post('/api/users/deleterole',tokenParser, controller.users.deleteRole);
|
||||
router.post('/api/users/getrolelist',tokenParser, controller.users.getrolelist);
|
||||
router.post('/api/users/createroledata',tokenParser, controller.users.createRoleData);
|
||||
router.post('/api/users/getpvpdefense',tokenParser, controller.users.getPveDefense);
|
||||
router.post('/api/users/getherolist',tokenParser, controller.users.getHeroList);
|
||||
router.post('/api/users/deletehero', controller.users.deleteHero);
|
||||
router.post('/api/users/setherolv', controller.users.setHeroLv);
|
||||
router.post('/api/users/saveherotodefense',tokenParser, controller.users.saveHeroToDefense);
|
||||
router.post('/api/users/removeherofromdefense',tokenParser, controller.users.removeHeroFromDefense);
|
||||
|
||||
|
||||
|
||||
router.post('/api/users/getequiplist', controller.users.getEquipList);
|
||||
router.post('/api/users/getitemlist', controller.users.getItemList);
|
||||
router.post('/api/users/deleteequip', controller.users.deleteEquip);
|
||||
router.post('/api/users/deleteitem', controller.users.deleteItem);
|
||||
router.post('/api/users/setitemcount', controller.users.setItemCount);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UserModel } from '@db/User';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import Hero, { HeroModel } from '@db/Hero';
|
||||
import { HeroModel } from '@db/Hero';
|
||||
import { EquipModel } from '@db/Equip';
|
||||
import { ActionPointModel } from '@db/ActionPoint';
|
||||
import { BattleDropModel } from '@db/BattleDrop';
|
||||
@@ -24,9 +24,11 @@ import { STATUS, HERO_SYSTEM_TYPE } from '@consts';
|
||||
import { ITID, COUNTER } from '@consts';
|
||||
import { ItemModel } from '@db/Item';
|
||||
import { gameData, getHeroExpByLv } from '@pubUtils/data';
|
||||
import { calPlayerCeAndSave } from '@pubUtils/playerCe';
|
||||
import { calPlayerCeAndSave, calculateTopFive, calEquipSeids } from '@pubUtils/playerCe';
|
||||
import { SchoolModel } from '@db/School';
|
||||
import { CeAttrNumber } from '@db/generalField';
|
||||
import { smsModel } from '@db/Sms';
|
||||
import { isString } from 'underscore';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -36,12 +38,13 @@ export default class GMUsers extends Service {
|
||||
/**
|
||||
* 根据类型等搜索玩家
|
||||
*/
|
||||
public async getuserlist(field, value) {
|
||||
public async getuserlist(field: string = 'all', value: string = '') {
|
||||
const {ctx} = this;
|
||||
|
||||
let arr = new Array(), flag = 0;
|
||||
value = value.split(',');
|
||||
for(let i of value) {
|
||||
if(value == '') field = 'all';
|
||||
let valueArr = value.split(',');
|
||||
for(let i of valueArr) {
|
||||
if(field == 'uid') {
|
||||
let d = parseInt(i);
|
||||
if(isNaN(d)) {
|
||||
@@ -62,13 +65,15 @@ export default class GMUsers extends Service {
|
||||
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let users = await UserModel.findUserByField(field, value);
|
||||
let users = await UserModel.findUserByField(field, valueArr);
|
||||
|
||||
if(users) {
|
||||
let list = new Array();
|
||||
for(let user of users) {
|
||||
let role = await RoleModel.findByUid(user.uid, 1);
|
||||
list.push({...user, hasRole: role?true: false, role});
|
||||
let role = await RoleModel.findAllByUid(user.uid);
|
||||
let sms = await smsModel.findByTel(user.tel);
|
||||
|
||||
list.push({...user, role, isFixed: sms?sms.isFixed: false, code: sms?sms.code:""});
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {list})
|
||||
@@ -94,6 +99,45 @@ export default class GMUsers extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public async addAuth(uid:number, auth: number) {
|
||||
console.log('enter Auth addAuth');
|
||||
const ctx = this.ctx;
|
||||
|
||||
const user = await UserModel.addAuth(uid, auth);
|
||||
if (user) {
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
} else {
|
||||
console.error('add auth error');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
public checkTelNo(telNo: string) {
|
||||
if (!isString(telNo)) {
|
||||
return { status: 1, data: '参数类型错误' };
|
||||
}
|
||||
if (telNo.length !== 11) {
|
||||
return { status: 1, data: '手机号长度错误' };
|
||||
}
|
||||
return { status: 0, data: '手机号合法' };
|
||||
}
|
||||
|
||||
public async fixSms(tel: string) {
|
||||
console.log('enter Auth fix sms');
|
||||
const ctx = this.ctx;
|
||||
const checkTel = this.checkTelNo(tel);
|
||||
if(checkTel.status == 1) {
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, checkTel.data);
|
||||
}
|
||||
const sms = await smsModel.fixSms(tel);
|
||||
if (sms) {
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
} else {
|
||||
console.error('fix sms error');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteRole(roleId: string) {
|
||||
console.log('enter Auth deleteRole');
|
||||
const ctx = this.ctx;
|
||||
@@ -126,12 +170,13 @@ export default class GMUsers extends Service {
|
||||
/**
|
||||
* 根据类型等搜索玩家
|
||||
*/
|
||||
public async getrolelist(field, value) {
|
||||
public async getrolelist(field: string = 'all', value: string = '') {
|
||||
const {ctx} = this;
|
||||
|
||||
let arr = new Array(), flag = 0;
|
||||
value = value.split(',');
|
||||
for(let i of value) {
|
||||
let valueArr = value.split(',');
|
||||
if(value == '') field = 'all';
|
||||
for(let i of valueArr) {
|
||||
if(field == 'uid') {
|
||||
let d = parseInt(i);
|
||||
if(isNaN(d)) {
|
||||
@@ -156,7 +201,7 @@ export default class GMUsers extends Service {
|
||||
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let roles = await RoleModel.findRoleByField(field, value);
|
||||
let roles = await RoleModel.findRoleByField(field, valueArr);
|
||||
|
||||
if(roles) {
|
||||
|
||||
@@ -355,28 +400,28 @@ export default class GMUsers extends Service {
|
||||
})
|
||||
}
|
||||
|
||||
public async getHeroList(roleId: string) {
|
||||
const {ctx} = this;
|
||||
let herolist = await HeroModel.findByRole(roleId);
|
||||
let defense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
// public async getHeroList(roleId: string) {
|
||||
// const {ctx} = this;
|
||||
// let herolist = await HeroModel.findByRole(roleId);
|
||||
// let defense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
|
||||
let result = Array<Hero>();
|
||||
for(let hero of herolist) {
|
||||
if(defense) {
|
||||
let {heroes = []} = defense;
|
||||
let curHero = heroes.find(cur => cur.actorId == hero.hid);
|
||||
if(!curHero) {
|
||||
result.push(hero);
|
||||
}
|
||||
} else{
|
||||
result.push(hero);
|
||||
}
|
||||
}
|
||||
// let result = Array<Hero>();
|
||||
// for(let hero of herolist) {
|
||||
// if(defense) {
|
||||
// let {heroes = []} = defense;
|
||||
// let curHero = heroes.find(cur => cur.actorId == hero.hid);
|
||||
// if(!curHero) {
|
||||
// result.push(hero);
|
||||
// }
|
||||
// } else{
|
||||
// result.push(hero);
|
||||
// }
|
||||
// }
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
heroes: result
|
||||
})
|
||||
}
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
// heroes: result
|
||||
// })
|
||||
// }
|
||||
|
||||
public async saveHeroToDefense(roleId: string, _roleName: string, hid: number) {
|
||||
const {ctx} = this;
|
||||
@@ -434,4 +479,180 @@ export default class GMUsers extends Service {
|
||||
defense
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型等搜索玩家
|
||||
*/
|
||||
public async getHeroList(field: string, value: (string|number)) {
|
||||
const {ctx} = this;
|
||||
|
||||
let heroes = await HeroModel.findByField(field, value);
|
||||
|
||||
if(heroes) {
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list: heroes });
|
||||
} else {
|
||||
console.error('role list not found');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async deleteHero(roleIdAndHids: string[]) {
|
||||
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;
|
||||
await HeroModel.deleteHero(roleId, hid);
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
await calculateTopFive(role, hid, 0, null);
|
||||
await PvpDefenseModel.deleteHero(roleId, hid);
|
||||
await RoleModel.updateRoleInfo(roleId, { topFive: role.topFive, topFiveCe: role.topFiveCe, ce: role.ce - hero.ce });
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
public async deleteEquip(roleIdAndSeqIds: string[]) {
|
||||
console.log('enter Auth deleteEquip');
|
||||
const ctx = this.ctx;
|
||||
let seqIds = new Array<number>();
|
||||
for (let roleIdAndSeqId of roleIdAndSeqIds) {
|
||||
let [roleId, seqIdStr] = roleIdAndSeqId.split('|');
|
||||
if (isNaN(parseInt(seqIdStr))) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let seqId = parseInt(seqIdStr);
|
||||
console.log(seqId);
|
||||
let equip = await EquipModel.findbySeqId(seqId);
|
||||
if(equip.hid > 0) {
|
||||
let hero = await HeroModel.findByHidAndRole(equip.hid, roleId);
|
||||
let index = hero.ePlace.findIndex(cur => cur.id == equip.ePlaceId);
|
||||
if (index < 0) continue;
|
||||
hero.ePlace[index].equip = null;
|
||||
let args = calEquipSeids(hero);
|
||||
await calPlayerCeAndSave(roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
|
||||
}
|
||||
seqIds.push(seqId);
|
||||
}
|
||||
await EquipModel.deleteEquips(seqIds);
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
public async deleteItem(roleIdAndIds: string[]) {
|
||||
console.log('enter Auth deleteItem');
|
||||
const ctx = this.ctx;
|
||||
let map = new Map<string, number[]>();
|
||||
for (let roleIdAndId of roleIdAndIds) {
|
||||
let [roleId, idStr] = roleIdAndId.split('|');
|
||||
if (isNaN(parseInt(idStr))) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let id = parseInt(idStr);
|
||||
let cur = map.get(roleId);
|
||||
if(!cur) {
|
||||
cur = new Array<number>();
|
||||
map.set(roleId, cur);
|
||||
}
|
||||
cur.push(id);
|
||||
}
|
||||
|
||||
for(let [roleId, ids] of map) {
|
||||
await ItemModel.deletebyRoleAndIds(roleId, ids);
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
public async setItemCount(roleIdAndIds: string[], count: number) {
|
||||
console.log('enter Auth setItemCount');
|
||||
const ctx = this.ctx;
|
||||
let map = new Map<string, number[]>();
|
||||
for (let roleIdAndId of roleIdAndIds) {
|
||||
let [roleId, idStr] = roleIdAndId.split('|');
|
||||
if (isNaN(parseInt(idStr))) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let id = parseInt(idStr);
|
||||
let cur = map.get(roleId);
|
||||
if(!cur) {
|
||||
cur = new Array<number>();
|
||||
map.set(roleId, cur);
|
||||
}
|
||||
cur.push(id);
|
||||
}
|
||||
|
||||
for(let [roleId, ids] of map) {
|
||||
await ItemModel.updateCountByRoleAndIds(roleId, ids, count);
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
public async setHeroLv(roleIdAndHids: string[], _hlv: string) {
|
||||
|
||||
try {
|
||||
console.log('gm setHeroLv', roleIdAndHids, _hlv);
|
||||
const ctx = this.ctx;
|
||||
let hlv = parseInt(_hlv);
|
||||
if( isNaN(hlv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
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);
|
||||
console.log(hid, roleId, !!hero);
|
||||
if(!hero) continue;
|
||||
hero.lv = hlv;
|
||||
await calPlayerCeAndSave(roleId, [hero], HERO_SYSTEM_TYPE.LVUP, [hid]);
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
} catch(e) {
|
||||
console.error(e.stack)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型等搜索装备
|
||||
*/
|
||||
public async getEquipList(field: string, value: (string | number)) {
|
||||
const { ctx } = this;
|
||||
|
||||
let equips = await EquipModel.findByField(field, value);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据类型等搜索道具
|
||||
*/
|
||||
public async getItemList(field: string, value: (string | number)) {
|
||||
const { ctx } = this;
|
||||
|
||||
let items = await ItemModel.findByField(field, value);
|
||||
|
||||
if (items) {
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list: items });
|
||||
} else {
|
||||
console.error('role list not found');
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user