✨ feat(重阳集会): 新增重阳集会活动
This commit is contained in:
75
shared/db/ActivityChongYangRec.ts
Normal file
75
shared/db/ActivityChongYangRec.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
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 })
|
||||
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 gameRecord(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecords: ChongYangGameRecord) {
|
||||
let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, dayIndex: number, count: number) {
|
||||
let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': dayIndex }, { $inc: { 'buyRecords.$.buyCnt': count }, $setOnInsert: { gameRecord: [] } }, { 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<DocumentType<Activity_ChongYang_Rec>, keyof Activity_ChongYang_Rec> { }
|
||||
export type ActivityChongYangRecModelTypeParam = Partial<ActivityChongYangRecModelType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user