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

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
@@ -59,7 +59,7 @@ export class NewHeroGachaHandler {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId); let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new NewHeroGachaData(activityData); let playerData = new NewHeroGachaData(activityData);
for (let pageData of playerData.list) { for (let pageData of playerData.list) {
await ActivityNewHeroGachaModel.selectedHero(serverId, activityId, roleId, hid, pageData.hid == hid); await ActivityNewHeroGachaModel.selectedHero(serverId, activityId, roleId, pageData.hid, pageData.hid == hid);
} }
return resResult(STATUS.SUCCESS); return resResult(STATUS.SUCCESS);
} }
@@ -77,15 +77,17 @@ export class RefreshTaskHandler {
//获得点数 //获得点数
await ActivityRefreshTaskPointModel.addPoint(serverId, activityId, roleId, dailyItemData.point); await ActivityRefreshTaskPointModel.addPoint(serverId, activityId, roleId, dailyItemData.point);
let addPointActivityId = playerData.addPointActivityId;//点数关联其他活动id // let addPointActivityId = playerData.addPointActivityId;//点数关联其他活动id
if (addPointActivityId) { // if (addPointActivityId) {
let activityData = await ActivityModel.findActivity(addPointActivityId); // let activityData = await ActivityModel.findActivity(addPointActivityId);
if (activityData) { // if (activityData) {
if (activityData.type === ACTIVITY_TYPE.NEW_HERO_GIFTS) { // if (activityData.type === ACTIVITY_TYPE.NEW_HERO_GIFTS) {
await newHeroGiftPoint(serverId, addPointActivityId, roleId, dailyItemData.point); // await newHeroGiftPoint(serverId, addPointActivityId, roleId, dailyItemData.point);
} // let uids = [{ uid: roleId, sid }];
} // this.app.get('channelService').pushMessageByUids('addPoint', resResult(STATUS.SUCCESS, { activityId: addPointActivityId, addPoint: dailyItemData.point }), uids);
} // }
// }
// }
dailyItemData.receiveRewardCount += 1; dailyItemData.receiveRewardCount += 1;
return resResult(STATUS.SUCCESS, Object.assign(result, { return resResult(STATUS.SUCCESS, Object.assign(result, {
@@ -9,6 +9,7 @@ import { nowSeconds, getZeroPointD } from "../../../pubUtils/timeUtil";
import { DicDailyTask, DicAchievement, DicMainTask } from "../../../pubUtils/dictionary/DicTask"; import { DicDailyTask, DicAchievement, DicMainTask } from "../../../pubUtils/dictionary/DicTask";
import { getMainTask, refDailyTaskBox, removeHistoryTask, getCurTask, checkTask } from "../../../services/taskService"; import { getMainTask, refDailyTaskBox, removeHistoryTask, getCurTask, checkTask } from "../../../services/taskService";
import { TASK } from "../../../pubUtils/dicParam"; import { TASK } from "../../../pubUtils/dicParam";
import { newHeroGiftPoint } from "../../../services/activity/newHeroGiftsService";
export default function (app: Application) { export default function (app: Application) {
return new ShopHandler(app); return new ShopHandler(app);
@@ -28,6 +29,7 @@ export class ShopHandler {
// 领取主线任务、每日任务、成就单条任务 // 领取主线任务、每日任务、成就单条任务
async receiveTask(msg: { type: number, id: number }, session: BackendSession) { async receiveTask(msg: { type: number, id: number }, session: BackendSession) {
const roleId: string = session.get('roleId'); const roleId: string = session.get('roleId');
const serverId: number = session.get('serverId');
const roleName: string = session.get('roleName'); const roleName: string = session.get('roleName');
const sid: string = session.get('sid'); const sid: string = session.get('sid');
const { type, id } = msg; const { type, id } = msg;
@@ -56,12 +58,21 @@ export class ShopHandler {
} }
point = userTask.dailyTaskPoint; point = userTask.dailyTaskPoint;
weeklyPoint = userTask.dailyTaskPointWeekly; weeklyPoint = userTask.dailyTaskPointWeekly;
let addPointActivityId = 0;//点数关联的活动id
if (addPointActivityId) {
await newHeroGiftPoint(serverId, addPointActivityId, roleId, point);
let uids = [{ uid: roleId, sid }];
this.app.get('channelService').pushMessageByUids('addPoint', resResult(STATUS.SUCCESS, { activityId: addPointActivityId, addPoint: point }), uids);
}
} else if (type == TASK_FUN_TYPE.ACHIEVEMENT) { } else if (type == TASK_FUN_TYPE.ACHIEVEMENT) {
let dic = <DicAchievement>dicTask; let dic = <DicAchievement>dicTask;
let userTask = await UserTaskModel.incInfo(roleId, { achievementPoint: dic.point }); let userTask = await UserTaskModel.incInfo(roleId, { achievementPoint: dic.point });
point = userTask.achievementPoint; point = userTask.achievementPoint;
} }
let goods = await addItems(roleId, roleName, sid, taskReward); let goods = await addItems(roleId, roleName, sid, taskReward);
return resResult(STATUS.SUCCESS, { return resResult(STATUS.SUCCESS, {
@@ -82,7 +82,6 @@ export async function makeDailyRMBGiftsReward(roleId: string, roleName: string,
for (let i = 0; i < playerData.day; i++) { for (let i = 0; i < playerData.day; i++) {
let beginTime = playerData.beginTime + 24 * 60 * 60 * 1000 * i; let beginTime = playerData.beginTime + 24 * 60 * 60 * 1000 * i;
// let beginTime = moment(new Date()).startOf('d').add(i, 'day').add(REFRESH_TIME, 'h').toDate();
await ActivityDailyRMBGiftsModel.buyRecord(serverId, activityId, roleId, moment(beginTime).toDate(), true); await ActivityDailyRMBGiftsModel.buyRecord(serverId, activityId, roleId, moment(beginTime).toDate(), true);
} }
let endTime = moment(playerData.endTime).add(playerData.day, 'd').toDate() let endTime = moment(playerData.endTime).add(playerData.day, 'd').toDate()
+5 -1
View File
@@ -25,9 +25,13 @@ export default class Activity extends BaseModel {
@prop({ required: true }) @prop({ required: true })
timeType: number; // 活动时间类型 ACTIVITY_TIME_TYPE timeType: number; // 活动时间类型 ACTIVITY_TIME_TYPE 1.服务器开启时间 2.角色创建时间 3.指定开启时间(beginTime,endTime)
@prop({ required: true }) @prop({ required: true })
days: number; // 活动持续天数 timeType=1、2 days: number; // 活动持续天数 timeType=1、2
@prop({ required: true })
delayDay: number; // 迟几天开启活动,0表示按照规定时间开启
@prop({ required: true })
interval: number; // 周期性活动时间间隔,秒
//根据活动类型查询开启的活动数据 //根据活动类型查询开启的活动数据
+50 -4
View File
@@ -1,4 +1,5 @@
import moment = require('moment'); import moment = require('moment');
import { ACTIVITY_TIME_TYPE, REFRESH_TIME, SERVER_OPEN_TIME } from '../../consts';
import { ActivityModelType } from '../../db/Activity'; import { ActivityModelType } from '../../db/Activity';
import { deltaDays } from '../../pubUtils/util'; import { deltaDays } from '../../pubUtils/util';
@@ -9,6 +10,10 @@ export abstract class ActivityBase {
endTime: number = 0; endTime: number = 0;
type: number = 0; type: number = 0;
todayIndex: number = 0;//从1开始 todayIndex: number = 0;//从1开始
delayDay: number = 0;//延迟多少天开启,0表示按照原计划开启
roundIndex: number = 0;//周期活动第几个周期,从1开始
nextRefreshTime: number = 0;//周期活动下次刷新时间
abstract initData(data: string): void; abstract initData(data: string): void;
@@ -19,11 +24,52 @@ export abstract class ActivityBase {
constructor(activityData: ActivityModelType) { constructor(activityData: ActivityModelType) {
this.activityId = activityData.activityId; this.activityId = activityData.activityId;
this.beginTime = moment(activityData.beginTime).valueOf(); this.delayDay = activityData.delayDay ? activityData.delayDay : 0;
this.endTime = moment(activityData.endTime).valueOf(); 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.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) // 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())
} }
} }
+10 -8
View File
@@ -100,14 +100,16 @@ export class DailyCoinData extends ActivityBase {
for (let obj of dataObj.coinRewardFormula) { for (let obj of dataObj.coinRewardFormula) {
this.coinRewardFormulaItem.push(new CoinRewardFormulaItem(obj)) this.coinRewardFormulaItem.push(new CoinRewardFormulaItem(obj))
} }
let curDate = moment(new Date()); // let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) { // if (curDate.hour() < REFRESH_TIME) {
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf(); // this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf(); // this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
} else { // } else {
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf(); // this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf() // this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
} // }
// console.log('ddddddddddddbbbbbbb')
} }
constructor(activityData: ActivityModelType) { constructor(activityData: ActivityModelType) {
@@ -56,14 +56,15 @@ export class DailyMealData extends ActivityBase {
for (let obj of arr) { for (let obj of arr) {
this.list.push(new DailyMealItem(obj)) this.list.push(new DailyMealItem(obj))
} }
let curDate = moment(new Date()); // let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) { // if (curDate.hour() < REFRESH_TIME) {
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf(); // this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf(); // this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
} else { // } else {
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf(); // this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf() // this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
} // }
// console.log('ddddddddddddbbbbbbb')
} }
constructor(activityData: ActivityModelType) { constructor(activityData: ActivityModelType) {
@@ -84,14 +84,16 @@ export class DailyRMBGiftsData extends ActivityBase {
this.day = dataObj.day; this.day = dataObj.day;
this.price = dataObj.price; this.price = dataObj.price;
this.productID = dataObj.productID; this.productID = dataObj.productID;
let curDate = moment(new Date()); // let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) { // if (curDate.hour() < REFRESH_TIME) {
this.beginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf(); // 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(); // this.endTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
} else { // } else {
this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf(); // this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = 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; let arr = dataObj.data;
for (let obj of arr) { for (let obj of arr) {
@@ -80,12 +80,12 @@ export class LimitShopData extends ActivityBase {
this.name = dataObj.name; this.name = dataObj.name;
this.interval = dataObj.interval; this.interval = dataObj.interval;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf(); // this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) { // if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000)); // 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(); // this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
} // }
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,) // console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
let arr = dataObj.data; let arr = dataObj.data;
for (let obj of arr) { for (let obj of arr) {
this.list.push(new ShopItem(obj)) this.list.push(new ShopItem(obj))
@@ -158,12 +158,12 @@ export class RefreshShopData extends ActivityBase {
this.name = dataObj.name; this.name = dataObj.name;
this.interval = dataObj.interval; this.interval = dataObj.interval;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf(); // this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) { // if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000)); // 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(); // this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
} // }
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,) // console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,)
let arr = dataObj.data; let arr = dataObj.data;
for (let obj of arr) { for (let obj of arr) {
this.list.push(new RefreshShopPage(obj)) this.list.push(new RefreshShopPage(obj))
@@ -117,12 +117,12 @@ export class RefreshTaskData extends ActivityBase {
this.totalPoint = 0; this.totalPoint = 0;
this.exchangePoint = 0; this.exchangePoint = 0;
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf(); // this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
if (this.interval > 0) { // if (this.interval > 0) {
this.roundIndex = Math.ceil((moment(new Date).valueOf() - this.beginTime) / (this.interval * 1000)); // 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(); // this.nextRefreshTime = moment(this.beginTime).add(this.interval * this.roundIndex, 'second').valueOf();
} // }
console.log(moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex,) // console.log('ddddddddddddbbbbbbb', moment(new Date).valueOf(), moment(this.beginTime).valueOf(), this.roundIndex, this.nextRefreshTime)
let arr = dataObj.data; let arr = dataObj.data;
for (let obj of arr) { for (let obj of arr) {
this.list.push(new RefreshTaskPage(obj)) this.list.push(new RefreshTaskPage(obj))
@@ -318,14 +318,6 @@ export class SevenDaysData extends ActivityBase {
this.growth = new SevenDaysGrowthData(objData.growth) this.growth = new SevenDaysGrowthData(objData.growth)
this.dailyGift = new SevenDaysDailyGiftsData(objData.dailyGift) this.dailyGift = new SevenDaysDailyGiftsData(objData.dailyGift)
this.dailyChallenge = new SevenDaysDailyChallengesData(objData.dailyChallenge) 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) { constructor(activityData: ActivityModelType) {
+4 -1
View File
@@ -53,6 +53,8 @@ export interface DicDailyTask extends DicTaskBase {
readonly point: number; readonly point: number;
// 经验基数 // 经验基数
readonly exp: number; readonly exp: number;
// 获得积分关联的活动id
readonly addPointActivityId: number;
} }
const DicDailyTaskKeys: KeysEnum<DicDailyTask> = { const DicDailyTaskKeys: KeysEnum<DicDailyTask> = {
@@ -63,7 +65,8 @@ const DicDailyTaskKeys: KeysEnum<DicDailyTask> = {
condition: true, condition: true,
taskReward: true, taskReward: true,
point: true, point: true,
exp: true exp: true,
addPointActivityId: true
}; };
// 成就 // 成就