活动:首充活动接口
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { FIRST_GIFT_STATE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityFirstGiftModelType } from '../../db/ActivityFirstGift';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
// 首充礼包的数据
|
||||
export class FirstGiftItem {
|
||||
index: number; // 第几天,从1开始
|
||||
name: string; //名称
|
||||
gift: number; //礼包id
|
||||
|
||||
isReceive: boolean = false; //是否领取过奖励
|
||||
|
||||
constructor(data: any) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.gift = data.gift;
|
||||
}
|
||||
}
|
||||
|
||||
// 30天任务活动数据
|
||||
export class FirstGiftData extends ActivityBase {
|
||||
state: number = FIRST_GIFT_STATE.NOT_OPEN;//活动状态
|
||||
list: Array<FirstGiftItem> = [];//奖励
|
||||
days: number = 0;//展示天数
|
||||
|
||||
//全部领取完成
|
||||
public isComplete() {
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
if (!this.list[i].isReceive) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//奖励内容
|
||||
public findFirstGiftItem(index: number): FirstGiftItem {
|
||||
let listIndex = this.list.findIndex(obj => { return obj && obj.index == index });
|
||||
if (listIndex != -1) {
|
||||
return this.list[listIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//解析玩家任务领取记录
|
||||
public setPlayerRecords(data: ActivityFirstGiftModelType) {
|
||||
this.todayIndex = 0;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
this.todayIndex = deltaDays(data.createdAt, new Date) + 1;
|
||||
this.state = (this.todayIndex <= this.days) ? FIRST_GIFT_STATE.OPEN : FIRST_GIFT_STATE.CLOSED;
|
||||
|
||||
let daysNum = data.days ? data.days : [];
|
||||
for (let obj of this.list) {
|
||||
if (daysNum.indexOf(obj.index) !== -1) {
|
||||
obj.isReceive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.days = dataObj.days;
|
||||
|
||||
let arr = dataObj.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new FirstGiftItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user