活动:签到
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, REFRESH_TIME, SERVER_OPEN_TIME, SIGNIN_CLOSE, SIGNIN_OPEN } from '../../consts';
|
||||
import { ACTIVITY_TYPE, REFRESH_TIME, SERVER_OPEN_TIME, SHOP_REFRESH_TYPE, SIGNIN_CLOSE, SIGNIN_OPEN } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivitySignInModelType } from '../../db/ActivitySignIn';
|
||||
import { getZeroPoint, getZeroPointOfTime } from '../../pubUtils/timeUtil';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -21,6 +22,10 @@ export class SignInItem {
|
||||
public canReceive(): boolean {
|
||||
return !this.isReceive;
|
||||
}
|
||||
|
||||
public setReceive(isReceive: boolean) {
|
||||
this.isReceive = isReceive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +33,7 @@ export class SignInItem {
|
||||
export class SignInData extends ActivityBase {
|
||||
list: Array<SignInItem> = [];
|
||||
roundIndex: number = 0;//活动周期
|
||||
todayIndex: number = 1;
|
||||
price: number = 0;//vip价格,普通签到为0
|
||||
// rebet: number = 0;
|
||||
productID: string = '';//商品ID
|
||||
@@ -36,6 +42,8 @@ export class SignInData extends ActivityBase {
|
||||
startDate: number = 1;//月卡开启
|
||||
endDate: number = 30;//月卡关闭
|
||||
days: number = 8;//新手签到使用,持续的天数
|
||||
signBeginTime: number = 0;
|
||||
signEndTime: number = 0;
|
||||
|
||||
//第几天的签到奖励
|
||||
public findDayItem(dayIndex: number) {
|
||||
@@ -50,54 +58,42 @@ export class SignInData extends ActivityBase {
|
||||
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;
|
||||
let day: number[] = [];
|
||||
for(let obj of records) {
|
||||
let item = this.findDayItem(obj.dayIndex);
|
||||
console.log('setPlayerRecords0', obj.dayIndex, item)
|
||||
if(item) {
|
||||
item.setReceive(true);
|
||||
let time = getZeroPointOfTime(obj.time, SHOP_REFRESH_TYPE.DAILY, 0)
|
||||
let today = getZeroPoint(SHOP_REFRESH_TYPE.DAILY, 0);
|
||||
console.log('setPlayerRecords', time, today)
|
||||
if(day.indexOf(time) == -1 && time < today) {
|
||||
this.todayIndex++;
|
||||
day.push(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.isVip = true
|
||||
}
|
||||
|
||||
//设置新手签到时间
|
||||
public setNewPlayerDate(beginTime: Date, endTime: Date) {
|
||||
this.beginTime = moment(beginTime).valueOf();
|
||||
this.endTime = moment(endTime).valueOf();
|
||||
this.roundIndex = 1;
|
||||
let date = new Date();
|
||||
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / (24 * 60 * 60 * 1000));
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.price = dataObj.price;
|
||||
this.productID = dataObj.productID;
|
||||
this.consume = dataObj.consume;
|
||||
// this.rebet = dataObj.rebet;
|
||||
this.signBeginTime = this.beginTime;
|
||||
this.signEndTime = this.endTime;
|
||||
|
||||
let date = new Date();
|
||||
|
||||
if (this.type === ACTIVITY_TYPE.COMMON_SIGN_IN) {//通用签到
|
||||
this.beginTime = moment(this.beginTime).startOf('day').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(this.endTime).endOf('day').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.roundIndex = moment(this.beginTime).diff(moment(SERVER_OPEN_TIME).startOf('months'), 'months') + 1;
|
||||
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / (24 * 60 * 60 * 1000));
|
||||
} else {
|
||||
if(this.type == ACTIVITY_TYPE.SIGN_IN||this.type == ACTIVITY_TYPE.SIGN_IN_VIP) {
|
||||
this.startDate = dataObj.startDate ? dataObj.startDate : SIGNIN_OPEN;
|
||||
this.endDate = dataObj.endDate ? dataObj.endDate : SIGNIN_CLOSE;
|
||||
|
||||
this.days = dataObj.days ? dataObj.days : 0;
|
||||
this.beginTime = moment(date.setDate(this.startDate)).startOf('day').add(REFRESH_TIME, 'h').valueOf();
|
||||
if (this.startDate > this.endDate) {//跨度下个月
|
||||
this.endTime = moment(date.setDate(this.endDate)).endOf('day').add(REFRESH_TIME, 'h').add(1, 'month').valueOf();
|
||||
} else {
|
||||
this.endTime = moment(date.setDate(this.endDate)).endOf('day').add(REFRESH_TIME, 'h').valueOf();
|
||||
}
|
||||
this.roundIndex = moment(this.beginTime).diff(moment(SERVER_OPEN_TIME).startOf('months'), 'months') + 1;
|
||||
if (this.type === ACTIVITY_TYPE.NEW_PLAYER_SIGN_IN) {
|
||||
this.roundIndex = 1;
|
||||
}
|
||||
this.todayIndex = Math.ceil((moment().valueOf() - this.beginTime) / (24 * 60 * 60 * 1000));
|
||||
this.signBeginTime = moment().startOf('M').valueOf();
|
||||
this.signEndTime = moment().endOf('M').valueOf();
|
||||
|
||||
this.roundIndex = parseInt(moment().format('YYYYMM'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user