后台添加武将批量添加
This commit is contained in:
@@ -179,37 +179,42 @@ export default class GMUsers extends Service {
|
||||
public async createHero(uids: Array<string>, _hid: string, _hlv: string) {
|
||||
const {ctx} = this;
|
||||
console.log('gm createHero', uids, _hid, _hlv);
|
||||
let hid = parseInt(_hid);
|
||||
let hlv = parseInt(_hlv);
|
||||
if(isNaN(hid) || isNaN(hlv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if( isNaN(hlv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let hids = (_hid as string).split('&').map(cur => parseInt(cur));
|
||||
for(let hid of hids) {
|
||||
if(isNaN(hid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let flag = 0, msg = '创建失败';
|
||||
let flag = 0, msg = '创建失败',heroInfos = new Array();
|
||||
for(let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(role) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if(hero) {
|
||||
flag = 1, msg = "角色" + roleId + "已拥有武将" + hid;
|
||||
break;
|
||||
for(let hid of hids) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if(hero) {
|
||||
flag = 1, msg = "角色" + roleId + "已拥有武将" + hid;
|
||||
break;
|
||||
}
|
||||
const seqId = await CounterModel.getNewCounter('hid')||-1;
|
||||
let dicHero = ctx.service.utils.getHeroById(hid);
|
||||
if(!dicHero) {
|
||||
flag = 1, msg = "未找到武将" + hid;
|
||||
break;
|
||||
}
|
||||
let ce = ctx.service.utils.calculateCE({hid: hid, lv: hlv});
|
||||
|
||||
const heroInfo = {
|
||||
roleId,
|
||||
roleName: role.roleName,
|
||||
hid: hid,
|
||||
hName: dicHero.name,
|
||||
seqId,
|
||||
lv: hlv,
|
||||
ce
|
||||
}
|
||||
heroInfos.push(heroInfo);
|
||||
}
|
||||
const seqId = await CounterModel.getNewCounter('hid')||-1;
|
||||
let dicHero = ctx.service.utils.getHeroById(hid);
|
||||
if(!dicHero) {
|
||||
flag = 1, msg = "未找到武将" + hid;
|
||||
break;
|
||||
}
|
||||
let ce = ctx.service.utils.calculateCE({hid: hid, lv: hlv});
|
||||
|
||||
const heroInfo = {
|
||||
roleId,
|
||||
roleName: role.roleName,
|
||||
hid: hid,
|
||||
hName: dicHero.name,
|
||||
seqId,
|
||||
lv: hlv,
|
||||
ce
|
||||
}
|
||||
await HeroModel.createHero(heroInfo);
|
||||
} else {
|
||||
flag = 1, msg = '未找到角色' + roleId;
|
||||
}
|
||||
@@ -218,6 +223,9 @@ export default class GMUsers extends Service {
|
||||
if (flag) {
|
||||
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, msg);
|
||||
} else {
|
||||
for(let heroInfo of heroInfos) {
|
||||
await HeroModel.createHero(heroInfo);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user