后台添加武将批量添加

This commit is contained in:
luying
2020-11-11 13:42:38 +08:00
parent 894f1dc9d5
commit b792f22f94
+12 -4
View File
@@ -179,14 +179,18 @@ 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) {
for(let hid of hids) {
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(hero) {
flag = 1, msg = "角色" + roleId + "已拥有武将" + hid;
@@ -209,7 +213,8 @@ export default class GMUsers extends Service {
lv: hlv,
ce
}
await HeroModel.createHero(heroInfo);
heroInfos.push(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 });
}
}