import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; /** * 周基金 */ class SignRecord { @prop({ required: true }) dayIndex: number; // 第几天的签到 @prop({ required: true }) todayIndex: number; // 签到当天是第几天 @prop({ required: true }) time: Date; // 时间戳 constructor(dayIndex: number, todayIndex: number) { this.dayIndex = dayIndex; this.todayIndex = todayIndex; this.time = new Date(); } } @index({ roleId: 1, activityId: 1 }) export default class Activity_Weekly_Fund extends BaseModel { @prop({ required: true }) serverId: number; // 服Id @prop({ required: true }) activityId: number; // 活动Id @prop({ required: true }) roleId: string; // 用户Id @prop({ required: true }) productID: string; // 商品id @prop({ required: true, type: SignRecord, _id: false }) record: SignRecord[]; // 铸造记录 public static async findData(serverId: number, activityId: number, roleId: string) { let result: ActivityWeeklyFundModelType = await ActivityWeeklyFundModel.findOne({ serverId, roleId, activityId }).lean(); return result; } public static async buy(serverId: number, activityId: number, roleId: string, productID: string) { let result: ActivityWeeklyFundModelType = await ActivityWeeklyFundModel.findOneAndUpdate({ serverId, roleId, activityId }, { $setOnInsert: { record: [], productID } }, { new: true, upsert: true }).lean(); return result; } public static async sign(serverId: number, activityId: number, roleId: string, dayIndex: number, todayIndex: number) { let result: ActivityWeeklyFundModelType = await ActivityWeeklyFundModel.findOneAndUpdate({ serverId, roleId, activityId, 'record.dayIndex': { $ne: dayIndex } }, { $push: { record: new SignRecord(dayIndex, todayIndex)} }, { new: true }).lean(); return result; } } export const ActivityWeeklyFundModel = getModelForClass(Activity_Weekly_Fund); export interface ActivityWeeklyFundModelType extends Pick, keyof Activity_Weekly_Fund> { } export type ActivityWeeklyFundModelTypeParam = Partial; // 将所有字段变成可选项