fix,修复后台批量添加武将bug
This commit is contained in:
@@ -186,22 +186,16 @@ export default class GMUsers extends Service {
|
|||||||
if(isNaN(hid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
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) {
|
for(let roleId of uids) {
|
||||||
let role = await RoleModel.findByRoleId(roleId);
|
let role = await RoleModel.findByRoleId(roleId);
|
||||||
if(role) {
|
if(role) {
|
||||||
for(let hid of hids) {
|
for(let hid of hids) {
|
||||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
if(hero) {
|
if(hero) continue;
|
||||||
flag = 1, msg = "角色" + roleId + "已拥有武将" + hid;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const seqId = await CounterModel.getNewCounter('hid')||-1;
|
const seqId = await CounterModel.getNewCounter('hid')||-1;
|
||||||
let dicHero = ctx.service.utils.getHeroById(hid);
|
let dicHero = ctx.service.utils.getHeroById(hid);
|
||||||
if(!dicHero) {
|
if(!dicHero) continue;
|
||||||
flag = 1, msg = "未找到武将" + hid;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let ce = ctx.service.utils.calculateCE({hid: hid, lv: hlv});
|
let ce = ctx.service.utils.calculateCE({hid: hid, lv: hlv});
|
||||||
|
|
||||||
const heroInfo = {
|
const heroInfo = {
|
||||||
@@ -216,17 +210,18 @@ export default class GMUsers extends Service {
|
|||||||
heroInfos.push(heroInfo);
|
heroInfos.push(heroInfo);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
flag = 1, msg = '未找到角色' + roleId;
|
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, '未找到角色' + roleId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag) {
|
try {
|
||||||
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, msg);
|
console.log
|
||||||
} else {
|
|
||||||
for(let heroInfo of heroInfos) {
|
for(let heroInfo of heroInfos) {
|
||||||
await HeroModel.createHero(heroInfo);
|
await HeroModel.createHero(heroInfo);
|
||||||
}
|
}
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ export default class Hero extends BaseModel {
|
|||||||
public static async createHero(heroInfo: {roleId: string, roleName: string, hid: number, hName: string, seqId: number, lv?:number, ce: number}, lean = true) {
|
public static async createHero(heroInfo: {roleId: string, roleName: string, hid: number, hName: string, seqId: number, lv?:number, ce: number}, lean = true) {
|
||||||
const doc = new HeroModel();
|
const doc = new HeroModel();
|
||||||
const update = Object.assign(doc.toJSON(), heroInfo);
|
const update = Object.assign(doc.toJSON(), heroInfo);
|
||||||
|
delete update._id;
|
||||||
const hero = await HeroModel.findOneAndUpdate({roleId: heroInfo.roleId, hid: heroInfo.hid}, update, {upsert: true, new: true}).lean(lean);
|
const hero = await HeroModel.findOneAndUpdate({roleId: heroInfo.roleId, hid: heroInfo.hid}, update, {upsert: true, new: true}).lean(lean);
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user