活动:自选礼包接口
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 自助商店货架上的商品
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class ActivitySelfServiceGoods 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 })
|
||||
cellIndex: number; // 第几个坑位从1开始
|
||||
@prop({ required: true })
|
||||
gift: number; // 礼包id
|
||||
@prop({ required: true })
|
||||
rewardIndex: number; // 礼包中第几项奖励
|
||||
|
||||
|
||||
//添加选中的物品
|
||||
public static async addGoods(acvitityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number) {
|
||||
let result: ActivitySelfServiceGoodsModelType = await ActivitySelfServiceGoodsModel.findOneAndUpdate({ roleId, acvitityId, roundIndex, index, cellIndex },
|
||||
{ $set: { gift, rewardIndex } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findData(acvitityId: number, roleId: string, roundIndex: number, lean = true) {
|
||||
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, acvitityId, roundIndex }, {
|
||||
index: 1, cellIndex: 1, gift: 1, rewardIndex: 1, _id: -1
|
||||
}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几个货架数据
|
||||
public static async findDataByIndex(acvitityId: number, roleId: string, roundIndex: number, index: number, lean = true) {
|
||||
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, acvitityId, roundIndex, index }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(acvitityId: number, roleId: string, roundIndex: number, index: number,) {
|
||||
await ActivitySelfServiceGoodsModel.deleteMany({ roleId, acvitityId, index, roundIndex });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivitySelfServiceGoodsModel = getModelForClass(ActivitySelfServiceGoods);
|
||||
|
||||
export interface ActivitySelfServiceGoodsModelType extends Pick<DocumentType<ActivitySelfServiceGoods>, keyof ActivitySelfServiceGoods> { }
|
||||
export type ActivitySelfServiceGoodsModelTypeParam = Partial<ActivitySelfServiceGoodsModelType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user