85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import moment = require('moment');
|
||
import { ACTIVITY_RESOURCES_TYPE, SIGNIN_CLOSE, SIGNIN_OPEN } from '../../consts';
|
||
import { ActivityModelType } from '../../db/Activity';
|
||
import { ActivitySignInModelType } from '../../db/ActivitySignIn';
|
||
import { ActivityBase } from './activityField';
|
||
|
||
|
||
// 每天签到配置数据
|
||
export class SignInItem {
|
||
dayIndex: number; // 第几天,从1开始
|
||
reward: string; // 签到奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||
|
||
isReceive: boolean = false; //是否领取
|
||
|
||
constructor(data: any) {
|
||
this.dayIndex = data.dayIndex;
|
||
this.reward = data.reward;
|
||
this.isReceive = false;
|
||
}
|
||
|
||
public canReceive(): boolean {
|
||
return !this.isReceive;
|
||
}
|
||
}
|
||
|
||
|
||
// 签到活动数据
|
||
export class SignInData extends ActivityBase {
|
||
list: Array<SignInItem> = [];
|
||
roundIndex: number = 0;//活动周期
|
||
price: number = 0;//vip价格,普通签到为0
|
||
productID: string = '';//商品ID
|
||
consume: string = ''//补签消耗
|
||
isVip: boolean = false;//是否购买了当前的vip活动
|
||
startDate: number = 1;//月卡开启
|
||
endDate: number = 30;//月卡关闭
|
||
|
||
//第几天的签到奖励
|
||
public findDayItem(dayIndex: number) {
|
||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex })
|
||
return (index != -1) ? this.list[index] : null;
|
||
}
|
||
|
||
//解析玩家签到记录
|
||
public setPlayerRecords(data: ActivitySignInModelType) {
|
||
this.isVip = false;
|
||
if (!data) {
|
||
return;
|
||
}
|
||
let records = data.records ? data.records : [];
|
||
for (let obj of this.list) {
|
||
let index = records.findIndex(record => { return obj.dayIndex == record.dayIndex })
|
||
if (index != -1) {
|
||
obj.isReceive = true;
|
||
}
|
||
}
|
||
this.isVip = true
|
||
}
|
||
|
||
public initData(data: string) {
|
||
let dataObj = JSON.parse(data);
|
||
this.startDate = dataObj.startDate ? dataObj.startDate : SIGNIN_OPEN;
|
||
this.endDate = dataObj.endDate ? dataObj.endDate : SIGNIN_CLOSE;
|
||
|
||
let date = new Date();
|
||
this.beginTime = moment(date.setDate(this.startDate)).startOf('day').valueOf();
|
||
this.endTime = moment(date.setDate(this.endDate)).endOf('day').valueOf();
|
||
|
||
this.price = dataObj.price;
|
||
this.productID = dataObj.productID;
|
||
this.consume = dataObj.consume;
|
||
this.roundIndex = moment().diff(moment(this.beginTime).startOf('months'), 'months') + 1;
|
||
this.todayIndex = moment(Date.now()).date() - this.startDate + 1;
|
||
|
||
let arr = dataObj.data
|
||
for (let obj of arr) {
|
||
this.list.push(new SignInItem(obj))
|
||
}
|
||
}
|
||
|
||
constructor(activityData: ActivityModelType) {
|
||
super(activityData)
|
||
this.initData(activityData.data)
|
||
}
|
||
} |