67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
|
|
|
/**
|
|
* 宴请百家
|
|
*/
|
|
class EntertainRecord {
|
|
@prop({ required: true })
|
|
todayIndex: number; // 第几天
|
|
|
|
@prop({ required: true })
|
|
id: number; // 唯一id
|
|
|
|
@prop({ required: true })
|
|
hid: number; // 冗余,武将id
|
|
|
|
@prop({ required: true })
|
|
index: number; // 冗余,武将id
|
|
|
|
@prop({ required: true })
|
|
reward: string; // 冗余,奖励
|
|
|
|
@prop({ required: true })
|
|
time: Date; // 时间
|
|
}
|
|
|
|
@index({ roleId: 1, activityId: 1 })
|
|
|
|
export default class Activity_Entertain_Rec extends BaseModel {
|
|
@prop({ required: true })
|
|
serverId: number; // 服Id
|
|
|
|
@prop({ required: true })
|
|
activityId: number; // 活动Id
|
|
|
|
@prop({ required: true })
|
|
roundIndex: number; // 第几轮
|
|
|
|
@prop({ required: true })
|
|
roleId: string; // 用户Id
|
|
|
|
@prop({ required: true })
|
|
buyCnt: number; // 购买次数
|
|
|
|
@prop({ required: true, type: EntertainRecord, _id: false })
|
|
record: EntertainRecord[]; // 宴请记录
|
|
|
|
public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) {
|
|
let result: ActivityEntertainRecModelType = await ActivityEntertainRecModel.findOne({ serverId, roleId, activityId, roundIndex }).lean();
|
|
return result;
|
|
}
|
|
|
|
public static async record(serverId: number, activityId: number, roundIndex: number, roleId: string, record: EntertainRecord) {
|
|
let result: ActivityEntertainRecModelType = await ActivityEntertainRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { record }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean();
|
|
return result;
|
|
}
|
|
|
|
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, count: number) {
|
|
let result: ActivityEntertainRecModelType = await ActivityEntertainRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $inc: { buyCnt: count }, $setOnInsert: { record: [] } }, { new: true, upsert: true }).lean();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
export const ActivityEntertainRecModel = getModelForClass(Activity_Entertain_Rec);
|
|
|
|
export interface ActivityEntertainRecModelType extends Pick<DocumentType<Activity_Entertain_Rec>, keyof Activity_Entertain_Rec> { }
|
|
export type ActivityEntertainRecModelTypeParam = Partial<ActivityEntertainRecModelType>; // 将所有字段变成可选项
|