Files
ZYZ/shared/domain/activityField/yuanBaoShopField.ts
2021-06-30 11:41:38 +08:00

69 lines
2.1 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 { ActivityModelType } from '../../db/Activity';
import { UserOrderModelType } from '../../db/UserOrder';
import { ActivityBase } from './activityField';
// 商品的数据
export class YuanBaoShopItem {
id: number; // 第几个从1开始
price: number; // 价格RMB
productID: string; // 商品id
name: string; //名称
baseReward: string; //购买即可获得的基础奖励
firstReward: string; //首充时,赠送的奖励
extraReward: string; //不是首冲时,赠送的奖励
imageName: string;
buyCount: number = 0; //购买过的次数
constructor(data: any) {
this.id = data.id;
this.price = data.price;
this.productID = data.productID;
this.name = data.name;
this.baseReward = data.baseReward;
this.firstReward = data.firstReward;
this.extraReward = data.extraReward;
this.imageName = data.imageName;
this.buyCount = 0;
}
}
// 元宝充值商店数据
export class YuanBaoShopData extends ActivityBase {
list: Array<YuanBaoShopItem> = [];//商品
//商品
public findItem(productID: string): YuanBaoShopItem {
let listIndex = this.list.findIndex(obj => { return obj && obj.productID == productID });
if (listIndex != -1) {
return this.list[listIndex];
}
return null;
}
//解析玩家购买记录
public setPlayerRecords(data: UserOrderModelType[]) {
this.todayIndex = 0;
if (!data) {
return;
}
for (let obj of this.list) {
let arr = data.filter(order => { return order.productID === obj.productID })
obj.buyCount = arr.length;
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new YuanBaoShopItem(obj))
}
}
constructor(activityData: ActivityModelType, createTime: number) {
super(activityData, createTime)
this.initData(activityData.data)
}
}