70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
|
|
|
|
|
/**
|
|
* 活动系统 - 弹出商店
|
|
*/
|
|
@index({ roleId: 1 })
|
|
|
|
export default class ActivityPopUpShop extends BaseModel {
|
|
@prop({ required: true })
|
|
serverId: number; // 服id
|
|
@prop({ required: true })
|
|
activityId: number; // 活动Id
|
|
@prop({ required: true })
|
|
roleId: string; // 用户Id
|
|
@prop({ required: true })
|
|
beginTime: Date; // 开始时间
|
|
@prop({ required: true })
|
|
endTime: Date; // 结束时间
|
|
@prop({ required: true })
|
|
id: number; // 任务id
|
|
@prop({ required: true })
|
|
isBuy: boolean; // 是否购买
|
|
|
|
//购买奖励的记录
|
|
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
|
|
let nowDate = new Date();
|
|
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({
|
|
serverId, roleId, activityId, id,
|
|
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
|
},
|
|
{ $set: { isBuy: true } }, { upsert: true, new: true }).lean(true);
|
|
return result;
|
|
}
|
|
|
|
//查询现在正在进行的活动数据
|
|
public static async findAllOpenData(serverId: number, activityId: number, roleId: string) {
|
|
let nowDate = new Date();
|
|
let result: ActivityPopUpShopModelType[] = await ActivityPopUpShopModel.find({
|
|
serverId, roleId, activityId,
|
|
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
|
}).lean(true);
|
|
return result;
|
|
}
|
|
|
|
//根据活动taskId查询现在正在进行的活动数据
|
|
public static async findOpenDataByTaskId(serverId: number, activityId: number, roleId: string, id: number) {
|
|
let nowDate = new Date();
|
|
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOne({
|
|
serverId, roleId, activityId, id,
|
|
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
|
}).lean(true);
|
|
return result;
|
|
}
|
|
|
|
//删除活动领取记录
|
|
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number) {
|
|
let nowDate = new Date();
|
|
await ActivityPopUpShopModel.deleteMany({
|
|
roleId, activityId, id,
|
|
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
|
});
|
|
}
|
|
}
|
|
|
|
export const ActivityPopUpShopModel = getModelForClass(ActivityPopUpShop);
|
|
|
|
export interface ActivityPopUpShopModelType extends Pick<DocumentType<ActivityPopUpShop>, keyof ActivityPopUpShop> { }
|
|
export type ActivityPopUpShopModelTypeParam = Partial<ActivityPopUpShopModelType>; // 将所有字段变成可选项
|