活动:弹出商店接口

This commit is contained in:
qiaoxin
2021-05-19 21:02:26 +08:00
parent 19d2021ac4
commit ca19f04282
4 changed files with 293 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import { DAILYRMBGIFTS_DAYS } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityPopUpShopModelType } from '../../db/ActivityPopUpShop';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 商品数据
export class PopUpShopItem {
id: number; // 第几个从1开始
productID: string; // 商品id支付时使用
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
countMax: number = 0; //可购买的最大次数0表示不限制
name: string; //名字
buyCount: number = 0; //购买过的次数
constructor(data: any) {
this.id = data.id;
this.reward = data.reward;
this.countMax = data.countMax;
this.productID = data.productID;
this.name = data.name;
}
}
// 弹框商店
export class PopUpShopData {
name: string = '';//活动名称
taskId: number = 0;//id
list: Array<PopUpShopItem> = [];//每件商品信息
public findItem(id: number) {
let index = this.list.findIndex(obj => { return obj && obj.id === id });
return (index != -1) ? this.list[index] : null
}
//全部领取完成
public isComplete() {
for (let item of this.list) {
if (item.countMax == 0 ||
(item.countMax > 0 && item.buyCount < item.countMax)) {
return false
}
}
return true;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityPopUpShopModelType) {
if (!data) {
return;
}
for (let item of this.list) {
let buyRecords = data.records.filter(obj => { return obj && obj.id === item.id });
item.buyCount = buyRecords.length;
}
}
public initData(data: any) {
this.taskId = data.taskId;
let arr = data.data;
for (let obj of arr) {
this.list.push(new PopUpShopItem(obj))
}
}
constructor(activityData: any) {
this.initData(activityData)
}
}