Files
ZYZ/shared/domain/activityField/dailyRMBGiftsField.ts
2021-05-19 15:36:50 +08:00

89 lines
3.0 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 { ActivityDailyRMBGiftsModelType } from '../../db/ActivityDailyRMBGifts';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 商品数据
export class DailyRMBGiftsItem {
id: number; // 第几个从1开始
productID: string; // 商品id支付时使用
name: string; // 名字
price: number; //价格
reward: string; //奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
isBuy: boolean = false; //是否已经购买
isReceive: boolean = false; //是否领取过奖励
constructor(data: any) {
this.id = data.id;
this.productID = data.productID;
this.name = data.name;
this.price = data.price;
this.reward = data.reward;
}
}
// 每日特惠礼包RMB购买4挡,一次性支付购买7天活动数据
export class DailyRMBGiftsData extends ActivityBase {
name: string = '';//活动名称
day: number = DAILYRMBGIFTS_DAYS;//一次购买几天
price: number = 0;//一次性购买的价格
productID: string = '';//一次性购买的商品id
list: Array<DailyRMBGiftsItem> = [];//每件商品信息
receiveCount: number = 0;//已经领取次数(一次性购买)
public findTodayItem() {
let index = this.list.findIndex(obj => { return obj.productID == '' });
return (index != -1) ? this.list[index] : null
}
public findProduct(productID: string) {
let index = this.list.findIndex(obj => { return obj.productID == productID });
return (index != -1) ? this.list[index] : null
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType[], endTime: Date) {
let isOver = true;
for (let item of this.list) {
let index = data.findIndex(obj => { obj.id == item.id });
if (index != -1) {
item.isBuy = true;
item.isReceive = true;
} else {
item.isBuy = false;
item.isReceive = false;
isOver = false;
}
}
if (endTime) {//DAILYRMBGIFTS_DAYS天内有购买过一次性礼包结束时间
// if (moment(new Date()).toDate() < endTime) {
// for (let item of this.list) {
// item.isBuy = true;
// }
// }
this.receiveCount = deltaDays(new Date, endTime) + (isOver ? 0 : 1);
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
this.name = dataObj.name;
this.day = dataObj.day;
this.price = dataObj.price;
this.productID = dataObj.productID;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new DailyRMBGiftsItem(obj))
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}