升级建筑物

This commit is contained in:
luying
2021-01-21 16:25:32 +08:00
parent b5ba00f1cf
commit 48ee9267ab
6 changed files with 111 additions and 16 deletions
+15
View File
@@ -145,6 +145,21 @@ export default class Guild extends BaseModel {
const result = await GuildModel.findOneAndUpdate({ code }, { $set: update, $inc: incParam }, { new: true }).select(select).lean();
return result;
}
public static async upStructure(code: string, id: number, select?: string) {
if (id == GUILD_STRUCTURE.ARMY_CENTER) {
const result = await GuildModel.findOneAndUpdate({ code, 'structure.id': id }, { $inc: { 'structure.$.lv': 1, lv: 1 }, $set: { isMemberMax: false } }, { new: true }).select(select).lean();
return result;
} else {
const result = await GuildModel.findOneAndUpdate({ code, 'structure.id': id }, { $inc: { 'structure.$.lv': 1 } }, { new: true }).select(select).lean();
return result;
}
}
public static async costFund(code: string, cost: number) {
const result = await GuildModel.findOneAndUpdate({ code, fund: {$gte: cost}}, { $inc: { fund: -1 * cost } }, {new: true}).lean();
return result;
}
}
export const GuildModel = getModelForClass(Guild);