活动:修改活动的时间配置规则
This commit is contained in:
@@ -25,9 +25,13 @@ export default class Activity extends BaseModel {
|
||||
|
||||
|
||||
@prop({ required: true })
|
||||
timeType: number; // 活动时间类型 ACTIVITY_TIME_TYPE
|
||||
timeType: number; // 活动时间类型 ACTIVITY_TIME_TYPE 1.服务器开启时间 2.角色创建时间 3.指定开启时间(beginTime,endTime)
|
||||
@prop({ required: true })
|
||||
days: number; // 活动持续天数 timeType=1、2
|
||||
@prop({ required: true })
|
||||
delayDay: number; // 迟几天开启活动,0表示按照规定时间开启
|
||||
@prop({ required: true })
|
||||
interval: number; // 周期性活动时间间隔,秒
|
||||
|
||||
|
||||
//根据活动类型查询开启的活动数据
|
||||
@@ -70,7 +74,7 @@ export default class Activity extends BaseModel {
|
||||
if (endTime != undefined) {
|
||||
update["endTime"] = endTime;
|
||||
}
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: {...update, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { ...update, updatedBy: uid }, $setOnInsert: { createdBy: uid } },
|
||||
{ new: true, upsert: true }).lean(true);
|
||||
result.push(rec);
|
||||
}
|
||||
@@ -102,8 +106,8 @@ export default class Activity extends BaseModel {
|
||||
searchObj['endTime'] = { $gte: new Date };
|
||||
}
|
||||
let sort = {};
|
||||
if(sortField && sortOrder) {
|
||||
if(sortOrder == 'ascend') {
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder == 'ascend') {
|
||||
sort[sortField] = 1;
|
||||
} else if (sortOrder == 'descend') {
|
||||
sort[sortField] = -1;
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 任务
|
||||
import { RewardInter } from '../interface';
|
||||
import { readFileAndParse, parseNumberList, parseGoodStr } from '../util';
|
||||
import { FILENAME, TASK_FUN_TYPE} from '../../consts';
|
||||
import { FILENAME, TASK_FUN_TYPE } from '../../consts';
|
||||
const _ = require('lodash');
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
@@ -53,6 +53,8 @@ export interface DicDailyTask extends DicTaskBase {
|
||||
readonly point: number;
|
||||
// 经验基数
|
||||
readonly exp: number;
|
||||
// 获得积分关联的活动id
|
||||
readonly addPointActivityId: number;
|
||||
}
|
||||
|
||||
const DicDailyTaskKeys: KeysEnum<DicDailyTask> = {
|
||||
@@ -63,7 +65,8 @@ const DicDailyTaskKeys: KeysEnum<DicDailyTask> = {
|
||||
condition: true,
|
||||
taskReward: true,
|
||||
point: true,
|
||||
exp: true
|
||||
exp: true,
|
||||
addPointActivityId: true
|
||||
};
|
||||
|
||||
// 成就
|
||||
@@ -89,7 +92,7 @@ export type DicTask = DicTaskBase & { type: number };
|
||||
export const dicMainTask = new Map<number, DicMainTask>(); // 主线任务
|
||||
export const dicDailyTask = new Map<number, DicDailyTask>(); // 每日任务
|
||||
export const dicAchievement = new Map<number, DicAchievement>(); // 成就
|
||||
export const taskMap = new Map<number, Map<number, DicMainTask|DicDailyTask|DicAchievement>>();
|
||||
export const taskMap = new Map<number, Map<number, DicMainTask | DicDailyTask | DicAchievement>>();
|
||||
taskMap.set(TASK_FUN_TYPE.MAIN, dicMainTask);
|
||||
taskMap.set(TASK_FUN_TYPE.DAILY, dicDailyTask);
|
||||
taskMap.set(TASK_FUN_TYPE.ACHIEVEMENT, dicAchievement);
|
||||
@@ -104,7 +107,7 @@ export function loadTask() {
|
||||
dicMainTask.set(o.id, _.pick(o, Object.keys(DicMainTaskKeys)));
|
||||
pushDicTaskType(o.taskType, TASK_FUN_TYPE.MAIN, o);
|
||||
});
|
||||
|
||||
|
||||
const arrDailyTask = readFileAndParse(FILENAME.DIC_DAILY_TASK);
|
||||
arrDailyTask.forEach(o => {
|
||||
o.taskParam = parseNumberList(o.taskParam);
|
||||
@@ -112,7 +115,7 @@ export function loadTask() {
|
||||
dicDailyTask.set(o.id, _.pick(o, Object.keys(DicDailyTaskKeys)));
|
||||
pushDicTaskType(o.taskType, TASK_FUN_TYPE.DAILY, o);
|
||||
});
|
||||
|
||||
|
||||
const arrAchievement = readFileAndParse(FILENAME.DIC_ACHIEVEMENT);
|
||||
arrAchievement.forEach(o => {
|
||||
o.taskParam = parseNumberList(o.taskParam);
|
||||
@@ -120,11 +123,11 @@ export function loadTask() {
|
||||
dicAchievement.set(o.id, _.pick(o, Object.keys(DicAchievementKeys)));
|
||||
pushDicTaskType(o.taskType, TASK_FUN_TYPE.ACHIEVEMENT, o);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function pushDicTaskType(taskType: number, type: number, o: any) {
|
||||
if(!dicTaskType.has(taskType)) {
|
||||
if (!dicTaskType.has(taskType)) {
|
||||
dicTaskType.set(taskType, new Array<DicTask>());
|
||||
}
|
||||
let newObj = _.pick(o, Object.keys(DicTaskKeys));
|
||||
|
||||
Reference in New Issue
Block a user