活动:添加弹出礼包每日弹出的逻辑
This commit is contained in:
@@ -5,6 +5,7 @@ import { RewardParam } from '../domain/activityField/rewardField';
|
|||||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||||
import { ActivityPopUpShopModel, ActivityPopUpShopModelType } from '../db/ActivityPopUpShop';
|
import { ActivityPopUpShopModel, ActivityPopUpShopModelType } from '../db/ActivityPopUpShop';
|
||||||
import { ServerlistModel } from '../db/Serverlist';
|
import { ServerlistModel } from '../db/Serverlist';
|
||||||
|
import moment = require('moment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取活动数据
|
* 获取活动数据
|
||||||
@@ -56,6 +57,76 @@ export async function getPlayerPopUpShopData(activityId: number, serverId: numbe
|
|||||||
return allPlayerShop;
|
return allPlayerShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 弹出礼包任务特殊处理
|
||||||
|
// *
|
||||||
|
// * @param {number} serverId 区Id
|
||||||
|
// * @param {number} activityId 活动Id
|
||||||
|
// * @param {string} roleId 角色Id
|
||||||
|
// *
|
||||||
|
// */
|
||||||
|
// export async function checkPopUpActivityTask(serverId: number, sid: number, funcs: number[], roleId: string, taskType: number, addCount: number) {
|
||||||
|
// let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
|
||||||
|
// let allActivity = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.POP_UP_SHOP, new Date());
|
||||||
|
// for (let activity of allActivity) {
|
||||||
|
// let allTaskData: any[] = JSON.parse(activity.data);
|
||||||
|
// for (let task of allTaskData) {
|
||||||
|
// if (task.taskType == taskType) {
|
||||||
|
// let popShopData = new PopUpShopData(task, activity.activityId);
|
||||||
|
// let taskRecord = await ActivityPopUpShopModel.findDataByTaskId(serverId, activity.activityId, roleId, popShopData.id, popShopData.taskType)
|
||||||
|
// let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
||||||
|
|
||||||
|
// let beginTime = new Date();
|
||||||
|
// let endTime = moment(new Date()).add(task.duration, 'h').toDate();
|
||||||
|
// if (taskType == TASK_TYPE.ROLE_TERAPH_STAGE_UP) {//只要触发就弹出礼包商店
|
||||||
|
// //推送
|
||||||
|
// let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, addCount, beginTime, endTime);
|
||||||
|
// popShopData.setPlayerRecords(playerRecord)
|
||||||
|
// // pushMessage = pushMessage.concat(popShopData);
|
||||||
|
// } else if (taskType == TASK_TYPE.EQUIP_QUALITY_COUNT || taskType == TASK_TYPE.GACHA_QUALITY_COUNT) {//每天统计
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // if (!taskRecord || !taskRecord.isPush) {
|
||||||
|
// // let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||||
|
// // if (addCount) {
|
||||||
|
|
||||||
|
// // if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE || taskType == TASK_TYPE.BATTLE_TOWER_LV) {
|
||||||
|
// // let playerRecord = await ActivityPopUpShopModel.setTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||||
|
// // //推送
|
||||||
|
// // if (task.condition <= playerRecord.totalCount) {
|
||||||
|
// // playerRecord = await ActivityPopUpShopModel.pushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, beginTime, endTime);
|
||||||
|
// // popShopData.setPlayerRecords(playerRecord)
|
||||||
|
// // pushMessage = pushMessage.concat(popShopData);
|
||||||
|
// // }
|
||||||
|
// // } else if (taskType == TASK_TYPE.ROLE_TERAPH_STAGE_UP) {//只要触发就弹出礼包商店
|
||||||
|
// // //推送
|
||||||
|
// // let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, addCount, beginTime, endTime);
|
||||||
|
// // popShopData.setPlayerRecords(playerRecord)
|
||||||
|
// // pushMessage = pushMessage.concat(popShopData);
|
||||||
|
// // } else if (taskType == TASK_TYPE.EQUIP_QUALITY_COUNT || taskType == TASK_TYPE.GACHA_QUALITY_COUNT) {//每天统计
|
||||||
|
|
||||||
|
// // } else {
|
||||||
|
// // let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||||
|
// // //推送
|
||||||
|
// // if (task.condition <= playerRecord.totalCount) {
|
||||||
|
// // playerRecord = await ActivityPopUpShopModel.pushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, beginTime, endTime);
|
||||||
|
// // popShopData.setPlayerRecords(playerRecord)
|
||||||
|
// // pushMessage = pushMessage.concat(popShopData);
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // if (record) {
|
||||||
|
// // await ActivityPopUpShopModel.addTaskRecord(serverId, activity.activityId, roleId, task.id, task.taskType, JSON.stringify(record));
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结算购买礼包的奖励
|
* 结算购买礼包的奖励
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import BaseModel from './BaseModel';
|
||||||
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动系统 - 弹出商店数据统计
|
||||||
|
*/
|
||||||
|
@index({ roleId: 1 })
|
||||||
|
|
||||||
|
export default class Activity_Pop_Up_Shop_Record extends BaseModel {
|
||||||
|
@prop({ required: true })
|
||||||
|
serverId: number; // 服id
|
||||||
|
@prop({ required: true })
|
||||||
|
activityId: number; // 活动Id
|
||||||
|
@prop({ required: true })
|
||||||
|
roleId: string; // 用户Id
|
||||||
|
@prop({ required: true })
|
||||||
|
beginTime: Date; // 开始统计时间
|
||||||
|
@prop({ required: true })
|
||||||
|
id: number; // 任务id
|
||||||
|
@prop({ required: true })
|
||||||
|
type: number; // 任务类型
|
||||||
|
@prop({ required: true })
|
||||||
|
count: number; // 统计次数
|
||||||
|
|
||||||
|
|
||||||
|
//添加统计
|
||||||
|
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number, type: number, beginTime: Date, count: number) {
|
||||||
|
let result: ActivityPopUpShopRecordModelType = await ActivityPopUpShopRecordModel.findOneAndUpdate({
|
||||||
|
serverId, roleId, activityId, id, type, beginTime,
|
||||||
|
},
|
||||||
|
{ $inc: { count: count } }, { upsert: true, new: true }).lean(true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询统计数据
|
||||||
|
public static async findRecordData(serverId: number, activityId: number, roleId: string, id: number, type: number, beginTime: Date) {
|
||||||
|
let result: ActivityPopUpShopRecordModelType = await ActivityPopUpShopRecordModel.findOne({
|
||||||
|
serverId, roleId, activityId, id, type, beginTime,
|
||||||
|
}).lean(true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除活动统计记录
|
||||||
|
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number, type: number,) {
|
||||||
|
await ActivityPopUpShopRecordModel.deleteMany({
|
||||||
|
roleId, activityId, id, type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActivityPopUpShopRecordModel = getModelForClass(Activity_Pop_Up_Shop_Record);
|
||||||
|
|
||||||
|
export interface ActivityPopUpShopRecordModelType extends Pick<DocumentType<Activity_Pop_Up_Shop_Record>, keyof Activity_Pop_Up_Shop_Record> { }
|
||||||
|
export type ActivityPopUpShopRecordModelTypeParam = Partial<ActivityPopUpShopRecordModelType>; // 将所有字段变成可选项
|
||||||
+35
-16
@@ -23,6 +23,7 @@ import { ActivityGrowthFundModel, ActivityGrowthFundModelType } from '../db/Acti
|
|||||||
import { ActivityBuyRecordsModel } from '../db/ActivityBuyRecords';
|
import { ActivityBuyRecordsModel } from '../db/ActivityBuyRecords';
|
||||||
import { PopUpShopData } from '../domain/activityField/popUpShopField';
|
import { PopUpShopData } from '../domain/activityField/popUpShopField';
|
||||||
import { ActivityPopUpShopModel } from '../db/ActivityPopUpShop';
|
import { ActivityPopUpShopModel } from '../db/ActivityPopUpShop';
|
||||||
|
import { ActivityPopUpShopRecordModel, ActivityPopUpShopRecordModelType } from '../db/ActivityPopUpShopRecord';
|
||||||
import moment = require("moment");
|
import moment = require("moment");
|
||||||
|
|
||||||
|
|
||||||
@@ -590,13 +591,31 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
|||||||
for (let task of allTaskData) {
|
for (let task of allTaskData) {
|
||||||
if (task.taskType == taskType) {
|
if (task.taskType == taskType) {
|
||||||
let popShopData = new PopUpShopData(task, activity.activityId);
|
let popShopData = new PopUpShopData(task, activity.activityId);
|
||||||
|
let beginTime = new Date();
|
||||||
|
let endTime = moment(new Date()).add(task.duration, 'h').toDate();
|
||||||
|
if (taskType == TASK_TYPE.ROLE_TERAPH_STAGE_UP) {//只要触发就弹出礼包商店
|
||||||
|
//推送
|
||||||
|
let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, count, beginTime, endTime);
|
||||||
|
popShopData.setPlayerRecords(playerRecord)
|
||||||
|
pushMessage = pushMessage.concat(popShopData);
|
||||||
|
} else if (taskType == TASK_TYPE.EQUIP_QUALITY_COUNT || taskType == TASK_TYPE.GACHA_QUALITY_COUNT) {//每天统计
|
||||||
|
let recordDate = moment(new Date()).startOf('d').toDate()
|
||||||
|
let recordData: ActivityPopUpShopRecordModelType = await ActivityPopUpShopRecordModel.findRecordData(serverId, activity.activityId, roleId, task.id, task.taskType, recordDate)
|
||||||
|
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, null);
|
||||||
|
if (recordData && (recordData.count < task.condition) && (recordData.count + addCount >= task.condition)) {//完成当天任务
|
||||||
|
let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, count, beginTime, endTime);
|
||||||
|
popShopData.setPlayerRecords(playerRecord)
|
||||||
|
pushMessage = pushMessage.concat(popShopData);
|
||||||
|
await ActivityPopUpShopRecordModel.addRecord(serverId, activity.activityId, roleId, task.id, task.taskType, recordDate, addCount)
|
||||||
|
} else {
|
||||||
|
await ActivityPopUpShopRecordModel.addRecord(serverId, activity.activityId, roleId, task.id, task.taskType, recordDate, addCount)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
let taskRecord = await ActivityPopUpShopModel.findDataByTaskId(serverId, activity.activityId, roleId, popShopData.id, popShopData.taskType)
|
let taskRecord = await ActivityPopUpShopModel.findDataByTaskId(serverId, activity.activityId, roleId, popShopData.id, popShopData.taskType)
|
||||||
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
||||||
if (!taskRecord || !taskRecord.isPush) {
|
if (!taskRecord || !taskRecord.isPush) {
|
||||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||||
if (addCount) {
|
if (addCount) {
|
||||||
let beginTime = new Date();
|
|
||||||
let endTime = moment(new Date()).add(task.duration, 'h').toDate();
|
|
||||||
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE || taskType == TASK_TYPE.BATTLE_TOWER_LV) {
|
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE || taskType == TASK_TYPE.BATTLE_TOWER_LV) {
|
||||||
let playerRecord = await ActivityPopUpShopModel.setTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
let playerRecord = await ActivityPopUpShopModel.setTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||||
//推送
|
//推送
|
||||||
@@ -605,13 +624,6 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
|||||||
popShopData.setPlayerRecords(playerRecord)
|
popShopData.setPlayerRecords(playerRecord)
|
||||||
pushMessage = pushMessage.concat(popShopData);
|
pushMessage = pushMessage.concat(popShopData);
|
||||||
}
|
}
|
||||||
} else if (taskType == TASK_TYPE.ROLE_TERAPH_STAGE_UP) {//只要触发就弹出礼包商店
|
|
||||||
//推送
|
|
||||||
// let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, addCount, beginTime, endTime);
|
|
||||||
// popShopData.setPlayerRecords(playerRecord)
|
|
||||||
// pushMessage = pushMessage.concat(popShopData);
|
|
||||||
} else if (taskType == TASK_TYPE.EQUIP_QUALITY_COUNT) {//每天统计
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||||
//推送
|
//推送
|
||||||
@@ -681,9 +693,9 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return pushMessage;
|
return pushMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 达成任务标准
|
* 达成任务标准
|
||||||
*
|
*
|
||||||
* @param {string} roleId 角色Id
|
* @param {string} roleId 角色Id
|
||||||
@@ -694,7 +706,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any, recordData?: any): any {
|
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any, recordData?: any): any {
|
||||||
console.log('达成任务标准', roleId, taskType, taskParam, count, paramObj)
|
console.log('达成任务标准', roleId, taskType, taskParam, count, paramObj)
|
||||||
let param = splitString(taskParam, '&');
|
let param = splitString(taskParam, '&');
|
||||||
let addCount: number = 0; // 条件是否满足
|
let addCount: number = 0; // 条件是否满足
|
||||||
@@ -938,6 +950,13 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
|
|||||||
record.push(hid)
|
record.push(hid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TASK_TYPE.EQUIP_QUALITY_COUNT:
|
||||||
|
{
|
||||||
|
let quality = param[1]
|
||||||
|
let equips = paramObj.equips.filter(equip => { return equip.quality == quality })
|
||||||
|
addCount = equips.length;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
addCount = 0;
|
addCount = 0;
|
||||||
break;
|
break;
|
||||||
@@ -945,15 +964,15 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
|
|||||||
}
|
}
|
||||||
console.log('dddddddddddd', addCount, record)
|
console.log('dddddddddddd', addCount, record)
|
||||||
return { addCount, record };
|
return { addCount, record };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建账号时临时获得可开启功能,主要用于check 主公升级任务
|
* 创建账号时临时获得可开启功能,主要用于check 主公升级任务
|
||||||
* 该函数不会存储funcs,如pvp开启会在entryHandler里面再查一次funcs,那时候正式开启
|
* 该函数不会存储funcs,如pvp开启会在entryHandler里面再查一次funcs,那时候正式开启
|
||||||
* @param dataFuncs
|
* @param dataFuncs
|
||||||
* @param lv
|
* @param lv
|
||||||
*/
|
*/
|
||||||
export async function getCreateUserFuncs(dataFuncs: number[], lv: number) {
|
export async function getCreateUserFuncs(dataFuncs: number[], lv: number) {
|
||||||
let addFuncs: number[] = [];
|
let addFuncs: number[] = [];
|
||||||
for (let [id, dicFunSwitch] of gameData.funcsSwitch) {
|
for (let [id, dicFunSwitch] of gameData.funcsSwitch) {
|
||||||
if (dataFuncs.includes(id)) continue; // 已开启过了
|
if (dataFuncs.includes(id)) continue; // 已开启过了
|
||||||
@@ -963,4 +982,4 @@ export async function getCreateUserFuncs(dataFuncs: number[], lv: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addFuncs;
|
return addFuncs;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user