活动:修改结构

This commit is contained in:
qiaoxin
2021-06-30 11:41:38 +08:00
parent 550ec29842
commit 3cff8acf3a
60 changed files with 260 additions and 169 deletions
@@ -11,6 +11,7 @@ import { TreasureHuntData } from '../../domain/activityField/treasureHuntField';
import { deltaDays } from '../../pubUtils/util';
import { addReward, stringToConsumeParam, stringToRewardParam } from './giftPackageService';
import { RewardParam } from '../../domain/activityField/rewardField';
import { RoleModel } from '../../db/Role';
/**
* 获取活动数据
@@ -22,12 +23,13 @@ import { RewardParam } from '../../domain/activityField/rewardField';
*/
export async function treasureHuntActivity(serverId: number, roleId: string) {
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
if (!activityData) {
return null;
}
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -56,12 +58,13 @@ export async function treasureHuntActivity(serverId: number, roleId: string) {
*/
export async function treasureHuntTaskActivity(serverId: number, roleId: string) {
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
if (!activityData) {
return null;
}
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -83,7 +86,8 @@ export async function treasureHuntTaskActivity(serverId: number, roleId: string)
export async function getPlayerTreasureHuntData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -104,7 +108,8 @@ export async function getPlayerTreasureHuntData(activityId: number, serverId: nu
export async function getPlayerTreasureHuntFirstPageData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -118,7 +123,8 @@ export async function getPlayerTreasureHuntFirstPageData(activityId: number, ser
export async function getPlayerTreasureHuntShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -132,7 +138,8 @@ export async function getPlayerTreasureHuntShopData(activityId: number, serverId
export async function getPlayerTreasureHuntTaskData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -146,7 +153,8 @@ export async function getPlayerTreasureHuntTaskData(activityId: number, serverId
export async function getPlayerTreasureHuntChallengeData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -158,7 +166,8 @@ export async function getPlayerTreasureHuntChallengeData(activityId: number, ser
export async function getPlayerTreasureHuntTreasureShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let playerData = new TreasureHuntData(activityData);
let { createTime } = await RoleModel.findByRoleId(roleId);
let playerData = new TreasureHuntData(activityData, createTime);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
@@ -170,13 +179,13 @@ export async function getPlayerTreasureHuntTreasureShopData(activityId: number,
}
//获取当前活动的周期等数据
export async function getTreasureHuntData(serverId: number) {
export async function getTreasureHuntData(serverId: number, roleId: string) {
let tempData: ServerTempModelType = await ServerTempModel.findData(serverId);
let now = moment(new Date()).toDate();
let activityData: ActivityModelType = null; //当前活动数据
if (!tempData) {//开始新周期
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getNewActivityData(serverId);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getNewActivityData(serverId, roleId);
if (huntActivityId === 0) {
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
}
@@ -185,7 +194,7 @@ export async function getTreasureHuntData(serverId: number) {
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
}
if (now > tempData.huntEndTime) {//活动过期
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getNextActivityData(serverId, tempData.huntActivityId, tempData.huntEndTime, tempData.huntRoundIndex);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getNextActivityData(serverId, roleId, tempData.huntActivityId, tempData.huntEndTime, tempData.huntRoundIndex);
if (huntActivityId === 0) {
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
}
@@ -205,15 +214,16 @@ export async function getTreasureHuntData(serverId: number) {
}
}
async function getNewActivityData(serverId: number) {
async function getNewActivityData(serverId: number, roleId: string) {
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
let huntActivityId: number = 0; // 寻宝骑兵-活动Id
let huntEndTime: Date = null; // 寻宝骑兵-结束时间
let huntRoundIndex: number = 0; // 寻宝骑兵-周期数
let activityArray: ActivityModelType[] = await ActivityModel.findActivityByType(activityGroupId, ACTIVITY_TYPE.TREASURE_HUNT, 1)//activityId从小到大排序
let treasureHuntDataArray: TreasureHuntData[] = [];
let { createTime } = await RoleModel.findByRoleId(roleId);
for (let obj of activityArray) {
treasureHuntDataArray.push(new TreasureHuntData(obj));
treasureHuntDataArray.push(new TreasureHuntData(obj, createTime));
}
let isOver = false;
let huntBeginTime = moment(SERVER_OPEN_TIME).startOf('d').add(1, 'd').toDate();
@@ -237,15 +247,16 @@ async function getNewActivityData(serverId: number) {
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex }
}
async function getNextActivityData(serverId: number, oldHuntActivityId: number, oldHuntEndTime: Date, oldHuntRoundIndex: number) {
async function getNextActivityData(serverId: number, roleId: string, oldHuntActivityId: number, oldHuntEndTime: Date, oldHuntRoundIndex: number) {
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
let huntActivityId: number = 0; // 寻宝骑兵-活动Id
let huntEndTime: Date = null; // 寻宝骑兵-结束时间
let huntRoundIndex: number = oldHuntRoundIndex; // 寻宝骑兵-周期数
let activityArray: ActivityModelType[] = await ActivityModel.findActivityByType(activityGroupId, ACTIVITY_TYPE.TREASURE_HUNT, 1)//activityId从小到大排序
let treasureHuntDataArray: TreasureHuntData[] = [];
let { createTime } = await RoleModel.findByRoleId(roleId);
for (let obj of activityArray) {
treasureHuntDataArray.push(new TreasureHuntData(obj));
treasureHuntDataArray.push(new TreasureHuntData(obj, createTime));
}
let isOver = false;
let huntBeginTime = moment(oldHuntEndTime).add(1, 'd').startOf('d').toDate();
@@ -296,7 +307,7 @@ async function getNextActivityData(serverId: number, oldHuntActivityId: number,
export async function makeShop(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
activityId: number, productID: string) {
// let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
if (!activityData) {
return {
code: STATUS.ACTIVITY_MISSING,