fix,修复后台批量添加武将bug

This commit is contained in:
luying
2020-11-11 16:46:54 +08:00
parent b792f22f94
commit 7ad1b703d3
2 changed files with 9 additions and 13 deletions

View File

@@ -186,22 +186,16 @@ export default class GMUsers extends Service {
if(isNaN(hid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}
let flag = 0, msg = '创建失败',heroInfos = new Array();
let heroInfos = new Array();
for(let roleId of uids) {
let role = await RoleModel.findByRoleId(roleId);
if(role) {
for(let hid of hids) {
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(hero) {
flag = 1, msg = "角色" + roleId + "已拥有武将" + hid;
break;
}
if(hero) continue;
const seqId = await CounterModel.getNewCounter('hid')||-1;
let dicHero = ctx.service.utils.getHeroById(hid);
if(!dicHero) {
flag = 1, msg = "未找到武将" + hid;
break;
}
if(!dicHero) continue;
let ce = ctx.service.utils.calculateCE({hid: hid, lv: hlv});
const heroInfo = {
@@ -216,17 +210,18 @@ export default class GMUsers extends Service {
heroInfos.push(heroInfo);
}
} else {
flag = 1, msg = '未找到角色' + roleId;
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, '未找到角色' + roleId)
}
}
if (flag) {
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, msg);
} else {
try {
console.log
for(let heroInfo of heroInfos) {
await HeroModel.createHero(heroInfo);
}
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
} catch(e) {
console.error(e.stack)
}
}