活动:修改活动的时间配置规则

This commit is contained in:
qiaoxin
2021-06-29 20:57:57 +08:00
parent 04d72a1956
commit 5e732e6d05
14 changed files with 174 additions and 112 deletions

View File

@@ -1,4 +1,5 @@
import moment = require('moment');
import { ACTIVITY_TIME_TYPE, REFRESH_TIME, SERVER_OPEN_TIME } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { deltaDays } from '../../pubUtils/util';
@@ -9,6 +10,10 @@ export abstract class ActivityBase {
endTime: number = 0;
type: number = 0;
todayIndex: number = 0;//从1开始
delayDay: number = 0;//延迟多少天开启0表示按照原计划开启
roundIndex: number = 0;//周期活动第几个周期从1开始
nextRefreshTime: number = 0;//周期活动下次刷新时间
abstract initData(data: string): void;
@@ -19,11 +24,52 @@ export abstract class ActivityBase {
constructor(activityData: ActivityModelType) {
this.activityId = activityData.activityId;
this.beginTime = moment(activityData.beginTime).valueOf();
this.endTime = moment(activityData.endTime).valueOf();
this.delayDay = activityData.delayDay ? activityData.delayDay : 0;
this.beginTime = moment(activityData.beginTime).add(this.delayDay, 'd').valueOf();
this.endTime = moment(activityData.endTime).add(this.delayDay, 'd').valueOf();
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
this.type = activityData.type;
// this.data = activityData.data;
this.todayIndex = deltaDays(moment(activityData.beginTime).startOf('d').toDate(), new Date) + 1;
// console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
switch (activityData.timeType) {
case ACTIVITY_TIME_TYPE.SERVER_OPEN_TIME: {
this.beginTime = moment(SERVER_OPEN_TIME).add(this.delayDay, 'd').startOf('d').add(REFRESH_TIME, 'h').valueOf();
if (activityData.days > 0) {
this.endTime = moment(this.beginTime).add(activityData.days, 'd').valueOf();
} else {
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
}
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
console.log('活动时间数据11...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
break;
}
case ACTIVITY_TIME_TYPE.ROLE_REGISTER_TIME: {
this.beginTime = moment(SERVER_OPEN_TIME).add(this.delayDay, 'd').startOf('d').add(REFRESH_TIME, 'h').valueOf();
if (activityData.days > 0) {
this.endTime = moment(this.beginTime).add(activityData.days, 'd').valueOf();
} else {
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
}
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
console.log('活动时间数据22...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
break;
}
case ACTIVITY_TIME_TYPE.DATE_TIME: {
console.log('活动时间数据33...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
break;
}
default: {
break;
}
}
if (activityData.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (activityData.interval * 1000));
this.nextRefreshTime = moment(this.beginTime).add(activityData.interval * this.roundIndex, 'second').valueOf();
this.todayIndex = Math.ceil(((moment(new Date).valueOf() - this.beginTime) % (activityData.interval * 1000)) / 24 * 60 * 60 * 1000);
}
console.log('活动时间数据...', '活动id:', activityData.activityId, '类型:', activityData.timeType, '开始时间:', this.beginTime, moment(this.beginTime).toDate(),
'结束:', this.endTime, moment(this.endTime).toDate(),
'今天第几天:', this.todayIndex, '回合:', this.roundIndex, '下次刷新:', this.nextRefreshTime, moment(this.nextRefreshTime).toDate())
}
}

View File

@@ -100,14 +100,16 @@ export class DailyCoinData extends ActivityBase {
for (let obj of dataObj.coinRewardFormula) {
this.coinRewardFormulaItem.push(new CoinRewardFormulaItem(obj))
}
let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) {
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
} else {
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
}
// let curDate = moment(new Date());
// if (curDate.hour() < REFRESH_TIME) {
// this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
// } else {
// this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
// }
// console.log('ddddddddddddbbbbbbb')
}
constructor(activityData: ActivityModelType) {

View File

@@ -56,14 +56,15 @@ export class DailyMealData extends ActivityBase {
for (let obj of arr) {
this.list.push(new DailyMealItem(obj))
}
let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) {
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
} else {
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
}
// let curDate = moment(new Date());
// if (curDate.hour() < REFRESH_TIME) {
// this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
// } else {
// this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
// }
// console.log('ddddddddddddbbbbbbb')
}
constructor(activityData: ActivityModelType) {

View File

@@ -84,14 +84,16 @@ export class DailyRMBGiftsData extends ActivityBase {
this.day = dataObj.day;
this.price = dataObj.price;
this.productID = dataObj.productID;
let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) {
this.beginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
} else {
this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
}
// let curDate = moment(new Date());
// if (curDate.hour() < REFRESH_TIME) {
// this.beginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
// } else {
// this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
// this.endTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
// }
// console.log('ddddddddddddbbbbbbb', this.activityId, this.beginTime, this.endTime)
let arr = dataObj.data;
for (let obj of arr) {

View File

@@ -80,12 +80,12 @@ export class LimitShopData extends ActivityBase {
this.name = dataObj.name;
this.interval = dataObj.interval;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
}
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
// this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
// if (this.interval > 0) {
// this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
// this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
// }
// console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new ShopItem(obj))

View File

@@ -158,12 +158,12 @@ export class RefreshShopData extends ActivityBase {
this.name = dataObj.name;
this.interval = dataObj.interval;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
}
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
// this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
// if (this.interval > 0) {
// this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
// this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
// }
// console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new RefreshShopPage(obj))

View File

@@ -117,12 +117,12 @@ export class RefreshTaskData extends ActivityBase {
this.totalPoint = 0;
this.exchangePoint = 0;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
}
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
// this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
// if (this.interval > 0) {
// this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000));
// this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
// }
// console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex, this.nextRefreshTime)
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new RefreshTaskPage(obj))

View File

@@ -318,14 +318,6 @@ export class SevenDaysData extends ActivityBase {
this.growth = new SevenDaysGrowthData(objData.growth)
this.dailyGift = new SevenDaysDailyGiftsData(objData.dailyGift)
this.dailyChallenge = new SevenDaysDailyChallengesData(objData.dailyChallenge)
if (this.type === ACTIVITY_TYPE.SEVEN_DAY) {
this.todayIndex = deltaDays(moment(SERVER_OPEN_TIME).startOf('d').toDate(), new Date) + 1;
} else if (this.type === ACTIVITY_TYPE.FOURTEEN_DAY) {
this.todayIndex = deltaDays(moment(SERVER_OPEN_TIME).startOf('d').toDate(), new Date) + 1 - 7;
} else if (this.type === ACTIVITY_TYPE.COMMON_SEVEN_DAY) {
}
}
constructor(activityData: ActivityModelType) {