活动:添加弹出礼包每日弹出的逻辑
This commit is contained in:
@@ -5,6 +5,7 @@ import { RewardParam } from '../domain/activityField/rewardField';
|
||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||
import { ActivityPopUpShopModel, ActivityPopUpShopModelType } from '../db/ActivityPopUpShop';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import moment = require('moment');
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -56,6 +57,76 @@ export async function getPlayerPopUpShopData(activityId: number, serverId: numbe
|
||||
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>; // 将所有字段变成可选项
|
||||
@@ -23,6 +23,7 @@ import { ActivityGrowthFundModel, ActivityGrowthFundModelType } from '../db/Acti
|
||||
import { ActivityBuyRecordsModel } from '../db/ActivityBuyRecords';
|
||||
import { PopUpShopData } from '../domain/activityField/popUpShopField';
|
||||
import { ActivityPopUpShopModel } from '../db/ActivityPopUpShop';
|
||||
import { ActivityPopUpShopRecordModel, ActivityPopUpShopRecordModelType } from '../db/ActivityPopUpShopRecord';
|
||||
import moment = require("moment");
|
||||
|
||||
|
||||
@@ -590,13 +591,31 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
for (let task of allTaskData) {
|
||||
if (task.taskType == taskType) {
|
||||
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 recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
||||
if (!taskRecord || !taskRecord.isPush) {
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
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) {
|
||||
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)
|
||||
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 {
|
||||
let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||
//推送
|
||||
@@ -938,6 +950,13 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
|
||||
record.push(hid)
|
||||
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:
|
||||
addCount = 0;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user