Files
ZYZ/shared/domain/activityField/popUpShopField.ts
2021-05-20 11:19:20 +08:00

80 lines
2.5 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 { 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开始
consume: string; //消耗资源(这里优先rmb的price价格其次资源消耗)
price: number; // 商品价格
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.consume = data.consume ? data.consume : '';
this.price = data.price ? data.price : 0;
this.productID = data.productID ? data.productID : '';
this.name = data.name;
}
}
// 弹框商店
export class PopUpShopData {
name: string = '';//活动名称
taskId: number = 0;//id
list: Array<PopUpShopItem> = [];//每件商品信息
public findItemByProductID(productID: string) {
let index = this.list.findIndex(obj => { return obj && obj.productID === productID });
return (index != -1) ? this.list[index] : null
}
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)
}
}