import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; /** * 重阳集会 */ export class ChongYangGameRecord { @prop({ required: true }) todayIndex: number; // 今天index @prop({ required: true }) gameCode: string; // 唯一挑战id @prop({ required: true }) time: Date; // 时间 @prop({ required: true }) rewards: string; // 奖励 @prop({ required: true }) isSuccess: boolean; // 是否通过 @prop({ required: true }) isSkip: boolean // 是否纯净召唤 @prop({ required: true }) dayIndex: number; //第几天(层) } export class ChongYangBuyRecord { @prop({ required: true }) dayIndex: number; //第几天(层) @prop({ required: true }) buyCnt: number; // 购买次数 } @index({ roleId: 1, activityId: 1 }) export default class Activity_ChongYang_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, type: ChongYangBuyRecord, default: [], _id: false }) buyRecords: ChongYangBuyRecord[]; // 购买次数 @prop({ required: true, type: ChongYangGameRecord, _id: false }) gameRecords: ChongYangGameRecord[]; // 记录 public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) { let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOne({ serverId, roleId, activityId, roundIndex }).lean(); return result; } public static async gameRecords(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecord: ChongYangGameRecord[]) { let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords: { $each: gameRecord } } }, { new: true, upsert: true }).lean(); return result; } public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, buyRecord: ChongYangBuyRecord, isPushBuyRecord: boolean) { let result: ActivityChongYangRecModelType; if (isPushBuyRecord) { result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { buyRecords: buyRecord } }, { new: true, upsert: true }).lean(); } else { result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': buyRecord.dayIndex }, { $inc: { 'buyRecords.$.buyCnt': buyRecord.buyCnt } }, { new: true, upsert: true }).lean(); } return result; } public static async gameEnd(serverId: number, activityId: number, roundIndex: number, roleId: string, gameCode: string, isSuccess: boolean, time: Date, rewards: string) { let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'gameRecords.gameCode': gameCode }, { $set: { 'gameRecords.$.time': time, 'gameRecords.$.hasPass': true, 'gameRecords.$.isSuccess': isSuccess, 'gameRecords.$.rewards': rewards } }, { new: true }).lean(); return result; } } export const ActivityChongYangRecModel = getModelForClass(Activity_ChongYang_Rec); export interface ActivityChongYangRecModelType extends Pick, keyof Activity_ChongYang_Rec> { } export type ActivityChongYangRecModelTypeParam = Partial; // 将所有字段变成可选项