Files
ZYZ/shared/db/ActivitySelfServiceShop.ts
2021-05-08 19:09:58 +08:00

60 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<DocumentType<ActivitySelfServiceShop>, keyof ActivitySelfServiceShop> { }
export type ActivitySelfServiceShopModelTypeParam = Partial<ActivitySelfServiceShopModelType>; // 将所有字段变成可选项