背包:装备邮件处理

This commit is contained in:
luying
2021-08-03 14:00:42 +08:00
parent e4f3a932f9
commit 76aedd5425
7 changed files with 112 additions and 41 deletions
+6 -2
View File
@@ -1,6 +1,7 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { findIndex } from 'underscore';
import { BAG } from '../pubUtils/dicParam';
// const Transaction = require("mongoose-transactions");
@index({ roleId: 1, id: 1 })
@index({ seqId: 1 })
@@ -43,10 +44,13 @@ export default class Item extends BaseModel {
return items;
}
public static async increaseItem(roleId: string, id: number, count: number, itemInfo: { roleId: string, roleName: string, id: number, itemName: string, type: number, hid?: number }, lean = true) {
public static async increaseItem(roleId: string, id: number, count: number, itemInfo: { roleId: string, roleName: string, id: number, itemName: string, type: number, hid?: number }) {
const doc = new ItemModel();
const setOnInsert = Object.assign(doc.toJSON(), itemInfo);
const items: ItemType = await ItemModel.findOneAndUpdate({ roleId, id }, { $setOnInsert: setOnInsert, $inc: { count } }, { new: true, upsert: true }).lean(lean);
let items: ItemType = await ItemModel.findOneAndUpdate({ roleId, id }, { $setOnInsert: setOnInsert, $inc: { count } }, { new: true, upsert: true }).lean();
if(items.count > BAG.BAG_GOODS_UPLIMITED) {
items = await ItemModel.findOneAndUpdate({ roleId, id, count: { $gte: BAG.BAG_GOODS_UPLIMITED } }, { $set: { count: BAG.BAG_GOODS_UPLIMITED } }, { new: true }).lean();
}
return items;
}
+5
View File
@@ -38,6 +38,11 @@ export default class ServerMail extends MailTemp {
return result;
}
public static async getMailById(_id: string, lean = true) {
const result: ServerMailType = await ServerMailModel.findOne({ _id }).lean(lean);
return result;
}
/**
* @description 创建邮件
* @param params