添加一个物品消耗通用方法

This commit is contained in:
luying
2020-12-08 19:36:02 +08:00
parent 28bc9118bc
commit 758f1dad01
6 changed files with 110 additions and 8 deletions
+5
View File
@@ -242,6 +242,11 @@ export default class Role extends BaseModel {
return result;
}
public static async costCoin(roleId: string, cnt: number, lean = true) {
let result = await RoleModel.findOneAndUpdate({roleId, coin: {$gte: cnt}}, { $inc: { coin: -cnt } }, { "new": true}).lean(lean);
return result;
}
public static async costGold(roleId: string, cnt: number, lean = true) {
let result = await RoleModel.findOneAndUpdate({roleId, gold: {$gte: cnt}}, { $inc: { gold: -cnt, totalCost: cnt } }, { "new": true}).lean(lean);
return result;