Files
ZYZ/shared/db/ActivityMonthlyFund.ts
2023-03-24 16:18:34 +08:00

66 lines
2.6 KiB
TypeScript

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_Monthly_Fund extends BaseModel {
@prop({ required: true })
serverId: number; // 服Id
@prop({ required: true })
activityId: number; // 活动Id
@prop({ required: true })
roleId: string; // 用户Id
@prop({ required: true })
roundIndex: number; // 第几轮
@prop({ required: true })
pageIndex: number; // 第几页
@prop({ required: true })
productID: string; // 商品id
@prop({ required: true, type: SignRecord, _id: false })
record: SignRecord[]; // 铸造记录
public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) {
let result: ActivityMonthlyFundModelType[] = await ActivityMonthlyFundModel.find({ serverId, roleId, activityId, roundIndex }).lean();
return result;
}
public static async buy(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, productID: string) {
let result: ActivityMonthlyFundModelType = await ActivityMonthlyFundModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex }, { $setOnInsert: { record: [], productID } }, { new: true, upsert: true }).lean();
return result;
}
public static async sign(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, dayIndex: number, todayIndex: number) {
let result: ActivityMonthlyFundModelType = await ActivityMonthlyFundModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, 'record.dayIndex': { $ne: dayIndex } }, { $push: { record: new SignRecord(dayIndex, todayIndex)} }, { new: true }).lean();
return result;
}
}
export const ActivityMonthlyFundModel = getModelForClass(Activity_Monthly_Fund);
export interface ActivityMonthlyFundModelType extends Pick<DocumentType<Activity_Monthly_Fund>, keyof Activity_Monthly_Fund> { }
export type ActivityMonthlyFundModelTypeParam = Partial<ActivityMonthlyFundModelType>; // 将所有字段变成可选项