Files
ZYZ/shared/db/ActivitySelfServiceGoods.ts
2021-05-25 17:21:29 +08:00

55 lines
2.6 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 Activity_Self_Service_Goods extends BaseModel {
@prop({ required: true })
activityId: number; // 活动Id
@prop({ required: true })
roundIndex: number; // 活动第几周期 从1开始根据活动开始时间计算
@prop({ required: true })
roleId: string; // 用户Id
@prop({ required: true })
index: number; // 第几个货架从1开始
@prop({ required: true })
cellIndex: number; // 第几个坑位从1开始
@prop({ required: true })
gift: number; // 礼包id
@prop({ required: true })
rewardIndex: number; // 礼包中第几项奖励
//添加选中的物品
public static async addGoods(activityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number) {
let result: ActivitySelfServiceGoodsModelType = await ActivitySelfServiceGoodsModel.findOneAndUpdate({ roleId, activityId, roundIndex, index, cellIndex },
{ $set: { gift, rewardIndex } }, { upsert: true, new: true }).lean(true);
return result;
}
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, activityId, roundIndex }, {
index: 1, cellIndex: 1, gift: 1, rewardIndex: 1, _id: -1
}).lean(lean);
return result;
}
//查询第几个货架数据
public static async findDataByIndex(activityId: number, roleId: string, roundIndex: number, index: number, lean = true) {
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, activityId, roundIndex, index }).lean(lean);
return result;
}
//删除活动领取记录
public static async deleteActivity(activityId: number, roleId: string, roundIndex: number, index: number,) {
await ActivitySelfServiceGoodsModel.deleteMany({ roleId, activityId, index, roundIndex });
}
}
export const ActivitySelfServiceGoodsModel = getModelForClass(Activity_Self_Service_Goods);
export interface ActivitySelfServiceGoodsModelType extends Pick<DocumentType<Activity_Self_Service_Goods>, keyof Activity_Self_Service_Goods> { }
export type ActivitySelfServiceGoodsModelTypeParam = Partial<ActivitySelfServiceGoodsModelType>; // 将所有字段变成可选项