Files
ZYZ/shared/db/BattleBlueprtDrop.ts
2020-12-15 18:08:29 +08:00

44 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 藏宝图掉落记录
*/
@index({ roleId: 1, battleId: 1 })
export default class BattleBlueprtDrop extends BaseModel {
@prop({ required: true })
roleId: string; // 角色 id
@prop({ required: true })
refTime: Date; // 刷新日期
@prop({ required: true, default: 0 })
getNum: number; // 获取次数当curCostAp超过ap重置
@prop({ required: true })
curCostAp: number; // 这一轮消耗的ap单独设置出了以防以后修改PER_AP
@prop({ required: true, default: 0 })
getSum: number; // 获取道具的全部次数
@prop({ required: true })
costAp: number; // 当天消耗的ap
public static async findByTime(roleId: string, refTime: Date, lean = true) {
const result: BattleBlueprtDropType = await BattleBlueprtDropModel.findOneAndUpdate({ roleId, refTime }, {}, {new: true, upsert: true}).lean(lean);
return result;
}
public static async updateByTime(roleId: string, refTime: Date, params: {getNum: number, curCostAp: number, getSum: number, costAp: number}, lean = true) {
const result: BattleBlueprtDropType = await BattleBlueprtDropModel.findOneAndUpdate({roleId, refTime}, {$set: params}).lean(lean);
return result;
}
public static async deleteAccount(roleId: string) {
let result = await BattleBlueprtDropModel.deleteMany({roleId});
return result;
}
}
export const BattleBlueprtDropModel = getModelForClass(BattleBlueprtDrop);
export interface BattleBlueprtDropType extends Pick<DocumentType<BattleBlueprtDrop>, keyof BattleBlueprtDrop>{}