✨ feat(节日活动): 宴请百家
This commit is contained in:
64
shared/db/ActivityEntertainRec.ts
Normal file
64
shared/db/ActivityEntertainRec.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
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 })
|
||||
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>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user