活动:修改30天任务的数据结构

This commit is contained in:
qiaoxin
2021-06-01 18:35:10 +08:00
parent c49e861209
commit 8195913389
11 changed files with 78 additions and 57 deletions
+10
View File
@@ -28,6 +28,8 @@ export default class Activity_Pop_Up_Shop extends BaseModel {
data: string; // 数据信息
@prop({ required: true })
isBuy: boolean; // 是否购买
@prop({ required: true })
isPush: boolean; // 是否推送过
//购买记录
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number, type: number) {
@@ -82,6 +84,14 @@ export default class Activity_Pop_Up_Shop extends BaseModel {
return result;
}
//标记push消息
public static async pushMessage(serverId: number, activityId: number, roleId: string, id: number, type: number, beginTime: Date, endTime: Date) {
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ serverId, roleId, activityId, id, type },
{ $set: { isPush: true, beginTime, endTime } }, { upsert: true, new: true }).lean(true);
return result;
}
//删除活动领取记录
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number) {
console.log(serverId)
+13 -11
View File
@@ -18,6 +18,8 @@ export default class Activity_Thirty_Days extends BaseModel {
@prop({ required: true })
cellIndex: number; // 第*页的第几个奖励
@prop({ required: true })
tab: number; // 具体任务id
@prop({ required: true })
type: number; // 任务类型
@prop({ required: true })
totalCount: number; // 累计达成次数
@@ -27,29 +29,29 @@ export default class Activity_Thirty_Days extends BaseModel {
data: string; // 数据信息
//添加领取记录
public static async addRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, lean = true) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex },
{ $set: { isReceive: true } }, { upsert: true, new: true }).lean(lean);
public static async addRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab },
{ $set: { isReceive: true } }, { upsert: true, new: true }).lean(true);
return result;
}
//根据活动统计完成任务次数
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, type },
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, addCount: number, lean = true) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
return result;
}
//根据活动记录统计数据
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, tab: number, type: number, data: string,) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, tab, type },
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
return result;
}
//根据活动统计完成任务次数
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, type: number, count: number, lean = true) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, type },
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, count: number, lean = true) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
return result;
}
@@ -67,8 +69,8 @@ export default class Activity_Thirty_Days extends BaseModel {
}
//查询第*页的某个的活动数据
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, type: number,) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, type }).lean(true);
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number,) {
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type }).lean(true);
return result;
}
@@ -1,9 +1,6 @@
import { ACTIVITY_RESOURCES_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityDailyGiftsModelType } from '../../db/ActivityDailyGifts';
import { RewardInter } from '../../pubUtils/interface';
import { parseGoodStrWithType, parseHeroStrWithType, parseResStr } from '../../pubUtils/util';
import { CreateHeroParam } from '../roleField/hero';
import { parseResStr } from '../../pubUtils/util';
import { ConsumeResParam } from '../activityField/consumeField';
import { ActivityBase } from './activityField';
@@ -69,7 +69,7 @@ export class DailyRMBGiftsData extends ActivityBase {
}
}
this.isBuy = data.isBuy;
this.isBuy = data.isBuy ? data.isBuy : false;
this.unReceiveCount = unReceiveCount;
if (this.isBuy && !isOver) {
this.unReceiveCount += 1;
@@ -1,3 +1,4 @@
import moment = require("moment");
import { ACTIVITY_TYPE } from "../../consts";
import { ActivityPopUpShopModelType } from "../../db/ActivityPopUpShop";
@@ -21,6 +22,8 @@ export class PopUpShopData {
isBuy: boolean = false; //购买过
beginTime: Date = null;//开始时间
endTime: Date = null;//结束时间
beginTimeStamp: number = 0;//开始时间
endTimeStamp: number = 0;//结束时间
//解析玩家开启的商店记录
public setPlayerRecords(data: ActivityPopUpShopModelType) {
@@ -30,6 +33,8 @@ export class PopUpShopData {
this.isBuy = data.isBuy ? data.isBuy : false;
this.beginTime = data.beginTime;
this.endTime = data.endTime;
this.beginTimeStamp = moment(data.beginTime).valueOf();
this.endTimeStamp = moment(data.endTime).valueOf();
this.totalCount = data.totalCount;
}
+14 -11
View File
@@ -1,10 +1,7 @@
import { ACTIVITY_RESOURCES_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityThirtyDaysModelType } from '../../db/ActivityThirtyDays';
import { ActivityThirtyDaysPointRewardModelType } from '../../db/ActivityThirtyDaysPointReward';
import { RewardInter } from '../../pubUtils/interface';
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
import { CreateHeroParam } from '../roleField/hero';
import { splitString } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 30天目标每个点兑换奖励的数据
@@ -58,11 +55,13 @@ export class ThirtyDaysPointItem {
// 30天目标每个奖励的数据
export class ThirtyDaysItem {
tab: number; // id
pageIndex: number; // 第几页,从1开始
cellIndex: number; // 第几个,从1开始
name: string; //名称
taskType: number; // 任务类型 dic_zyz_taskType.json
taskParam: string; //任务数据 dic_zyz_taskType.json
condition: number; //任务条件
taskParamArray: Array<number>; //任务数据 dic_zyz_taskType.json
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
point: number; // 任务达成获得的奖励点,只在当前活动中有用,虚拟
@@ -71,12 +70,14 @@ export class ThirtyDaysItem {
isComplete: boolean = false; //是否完成任务
isReceive: boolean = false; //是否领取过奖励
constructor(data: any, pageIndex: number) {
constructor(data: any, pageIndex: number, cellIndex: number) {
this.tab = data.tab;
this.pageIndex = pageIndex;
this.cellIndex = data.cellIndex;
this.cellIndex = cellIndex;
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.condition = data.condition;
this.reward = data.reward;
this.point = data.point;
@@ -98,7 +99,9 @@ export class ThirtyDaysPage {
this.name = data.name;
this.item = [];
for (let obj of data.item) {
this.item.push(new ThirtyDaysItem(obj, data.pageIndex));
for (let cellData of obj.taskList) {
this.item.push(new ThirtyDaysItem(cellData, data.pageIndex, obj.cellIndex));
}
}
}
}
@@ -195,10 +198,10 @@ export class ThirtyDaysData extends ActivityBase {
}
//完成的任务奖励内容
public findThirtyDaysItem(pageIndex: number, cellIndex: number): ThirtyDaysItem {
public findThirtyDaysItem(pageIndex: number, cellIndex: number, tab: number): ThirtyDaysItem {
let listIndex = this.list.findIndex(obj => { return obj && obj.pageIndex == pageIndex });
if (listIndex != -1) {
let itemIndex = this.list[listIndex].item.findIndex(obj => { return obj && obj.cellIndex == cellIndex });
let itemIndex = this.list[listIndex].item.findIndex(obj => { return obj && obj.cellIndex == cellIndex && obj.tab == tab });
if (itemIndex != -1) {
return this.list[listIndex].item[itemIndex];
}
@@ -223,10 +226,10 @@ export class ThirtyDaysData extends ActivityBase {
public setPlayerRecords(data: ActivityThirtyDaysModelType[]) {
this.totalPoint = 0;
for (let record of data) {
let itemData = this.findThirtyDaysItem(record.pageIndex, record.cellIndex)
let itemData = this.findThirtyDaysItem(record.pageIndex, record.cellIndex, record.tab)
if (itemData) {
itemData.isReceive = record.isReceive === true;
itemData.isComplete = record.totalCount >= itemData.taskParamArray[0];
itemData.isComplete = record.totalCount >= itemData.condition;
if (itemData.isReceive) {
this.totalPoint += itemData.point;
}
+10 -5
View File
@@ -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 moment = require("moment");
@@ -556,11 +557,11 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
thirtyDaysActivity.setPlayerRecords(playerRecords);
let taskArray = thirtyDaysActivity.findUncompleteTaskByType(taskType);
for (let task of taskArray) {
let taskRecord = await ActivityThirtyDaysModel.findDataByCellIndex(serverId, thirtyDaysActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType)
let taskRecord = await ActivityThirtyDaysModel.findDataByCellIndex(serverId, thirtyDaysActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.tab, task.taskType)
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
if (addCount) {
await ActivityThirtyDaysModel.addTaskCount(serverId, thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.taskType, addCount);
await ActivityThirtyDaysModel.addTaskCount(serverId, thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.tab, task.taskType, addCount);
}
if (record) {
await ActivityGrowthModel.addTaskRecord(serverId, thirtyDaysActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, JSON.stringify(record));
@@ -579,20 +580,24 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
let popShopData = new PopUpShopData(task, activity.activityId);
let taskRecord = await ActivityPopUpShopModel.findOpenDataByTaskId(serverId, activity.activityId, roleId, popShopData.id, popShopData.taskType)
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
if (!taskRecord || !taskRecord.isBuy) {
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) {
let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
//推送
if (task.condition < playerRecord.totalCount) {
if (task.condition <= playerRecord.totalCount) {
await ActivityPopUpShopModel.pushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, beginTime, endTime);
popShopData.setPlayerRecords(playerRecord)
pushMessage = pushMessage.concat(popShopData);
}
} else {
let playerRecord = await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
//推送
if (task.condition < playerRecord.totalCount) {
if (task.condition <= playerRecord.totalCount) {
await ActivityPopUpShopModel.pushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, beginTime, endTime);
popShopData.setPlayerRecords(playerRecord)
pushMessage = pushMessage.concat(popShopData);
}