活动:自选礼包接口

This commit is contained in:
qiaoxin
2021-05-08 19:09:58 +08:00
parent 43bca3a5b7
commit 6f03a96c51
7 changed files with 387 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ export enum ACTIVITY_TYPE {
GROWTH_FUND_MAIN_ELITE = 10, // 精英成长基金
GROWTH_FUND_MAIN_ELITE_VIP = 11, // 精英成长基金(高阶)
THIRTY_DAYS = 12, // 30日目标活动
SELF_SERVICE_SHOP = 13, // 自选商店
}
/**
@@ -36,4 +37,12 @@ export enum GIFT_PACKAGE_TYPE {
ALL = 1, // 全部
SELECTED_X = 2, // 多选*
RANDOM_X = 3, // 多随*
}
/**
* 活动自助商店坑位类型
*/
export enum SELF_SERVICE_SHOP_CELL_TYPE {
SPECIAL = 1, // 特殊
NORMAL = 2, // 普通
}

View File

@@ -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>; // 将所有字段变成可选项

View File

@@ -0,0 +1,60 @@
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>; // 将所有字段变成可选项

View File

@@ -0,0 +1,79 @@
import { SELF_SERVICE_SHOP_CELL_TYPE, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivitySelfServiceShopModelType } from '../../db/ActivitySelfServiceShop';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 自助商店数据坑位数据
export class SelfServiceShopItemInfo {
cellIndex: number; // 第几个坑位从1开始
cellType: number; //坑位类型 SELF_SERVICE_SHOP_CELL_TYPE 1.特殊 2.普通
gift: number; //礼包内容
constructor(data: any) {
this.cellIndex = data.cellIndex;
this.cellType = data.cellType;
this.gift = data.gift;
}
}
// 自助商店数据
export class SelfServiceShopItem {
index: number; // 第几个货架从1开始
name: string; //名称
countMax: number = 0; // 最大可购买次数 0表示无限
price: number; //价格
priceType: number; //价格类型 ACTIVITY_RESOURCES_TYPE 2.物品表 3.RMB
data: Array<SelfServiceShopItemInfo> = [];
buyCount: number = 0; //已经购买次数
constructor(cellData: any) {
this.index = cellData.index;
this.name = cellData.name;
this.countMax = cellData.countMax;
this.price = cellData.price;
this.priceType = cellData.priceType;
this.data = [];
for (let obj of cellData.data) {
this.data.push(new SelfServiceShopItemInfo(obj))
}
}
}
// 自选商店
export class SelfServiceShopData extends ActivityBase {
list: Array<SelfServiceShopItem> = [];//货架
days: number = 20;//刷新周期天数
roundIndex: number = 0; //第几周期 从1开始
public getItem(index: number) {
let listIndex = this.list.findIndex(obj => { return obj.index == index });
return (listIndex != -1) ? this.list[listIndex] : null;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivitySelfServiceShopModelType[]) {
for (let item of this.list) {
let buyData = data.filter(obj => { return obj.index === item.index })
item.buyCount = buyData.length
}
}
public initData(data: string) {
console.log('ddddddd', data)
let dataObj = JSON.parse(data);
this.days = dataObj.days;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new SelfServiceShopItem(obj))
}
this.roundIndex = Math.ceil(this.todayIndex / this.days);
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}