import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; /** * 自助商店 */ @index({ roleId: 1 }) export default class ActivitySelfServiceShop extends BaseModel { @prop({ required: true }) acvitityId: number; // 活动Id @prop({ required: true }) roundIndex: number; // 活动第几周期 从1开始,根据活动开始时间计算 @prop({ required: true }) roleId: string; // 用户Id @prop({ required: true }) index: number; // 第几个货架从1开始 @prop({ required: true }) price: number; //购买价格 @prop({ required: true }) priceType: number; //1.虚拟货币,2.RMB @prop({ required: true }) goods: string; // 商品信息 //添加购买记录 public static async addBuyRecord(acvitityId: number, roleId: string, roundIndex: number, index: number, price: number, priceType: number, goods: string) { await ActivitySelfServiceShopModel.insertMany([ { roleId, acvitityId, roundIndex, index, price, priceType, goods } ]) } //根据活动id查询活动数据 public static async findData(acvitityId: number, roleId: string, roundIndex: number, lean = true) { let result: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.find({ roleId, acvitityId, roundIndex }).lean(lean); return result; } //查询第几个货架数据 public static async findDataByIndex(acvitityId: number, roleId: string, roundIndex: number, index: number, lean = true) { let result: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.find({ roleId, acvitityId, roundIndex, index }).lean(lean); return result; } //查询购买价格类型的数据 public static async findDataByPriceType(acvitityId: number, roleId: string, roundIndex: number, priceType: number, lean = true) { let result: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.find({ roleId, acvitityId, priceType, roundIndex }).lean(lean); return result; } //删除活动领取记录 public static async deleteActivity(acvitityId: number, roleId: string, roundIndex: number, index: number,) { await ActivitySelfServiceShopModel.deleteMany({ roleId, acvitityId, index, roundIndex }); } } export const ActivitySelfServiceShopModel = getModelForClass(ActivitySelfServiceShop); export interface ActivitySelfServiceShopModelType extends Pick, keyof ActivitySelfServiceShop> { } export type ActivitySelfServiceShopModelTypeParam = Partial; // 将所有字段变成可选项