Files
ZYZ/shared/db/ActivityTreasureHuntShop.ts
2022-11-18 14:46:46 +08:00

37 lines
1.6 KiB
TypeScript

import ActivityShop from './ActivityShop';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 活动系统 - 寻宝猎人-商店
*/
@index({ roleId: 1, activityId: 1 })
export default class Activity_Treasure_Hunt_Shop extends ActivityShop {
@prop({ required: true })
dayIndex: number; // 第几天
//根据活动id查询活动数据
public static async findTreasureData(activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOne({ roleId, activityId, roundIndex, dayIndex }).lean(true);
return result;
}
//购买领取奖励的记录
public static async buyShopRecord(activityId: number, roleId: string, roundIndex: number, dayIndex: number, id: number, count: number) {
let records = [];
for(let i = 0; i < count; i++) {
records.push({ id, time: new Date() });
}
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOneAndUpdate({ roleId, activityId, roundIndex, dayIndex },
{ $push: { records: { $each: records } } }, { upsert: true, new: true }).lean(true);
return result;
}
}
export const ActivityTreasureHuntShopModel = getModelForClass(Activity_Treasure_Hunt_Shop);
export interface ActivityTreasureHuntShopModelType extends Pick<DocumentType<Activity_Treasure_Hunt_Shop>, keyof Activity_Treasure_Hunt_Shop> { }
export type ActivityTreasureHuntShopModelTypeParam = Partial<ActivityTreasureHuntShopModelType>; // 将所有字段变成可选项