活动:成长活动、今日挑战奖励接口返回数据添加字段

This commit is contained in:
qiaoxin
2021-05-20 17:16:01 +08:00
parent 14acc426a0
commit afc95d2e19
10 changed files with 119 additions and 158 deletions
+19 -19
View File
@@ -27,62 +27,62 @@ export default class ActivityGrowth extends BaseModel {
getPointReward: boolean; // 是否兑换领取奖章奖励
//任务领取记录
public static async addCellRecord(activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, activityId, dayIndex, cellIndex, type },
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(lean);
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, addPointCount: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
{ $inc: { receiveRewardCount: count, addPointCount: addPointCount } }, { upsert: true, new: true }).lean(lean);
return result;
}
//当日奖章领取记录
public static async addDayRecord(activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, activityId, dayIndex, cellIndex },
public static async addDayRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
{ $set: { getPointReward: true } }, { upsert: true, new: true }).lean(lean);
return result;
}
//根据活动统计完成任务次数
public static async setTaskCount(activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, activityId, dayIndex, cellIndex, type },
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
return result;
}
//根据活动统计完成任务次数
public static async addTaskCount(activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, activityId, dayIndex, cellIndex, type },
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
return result;
}
//根据活动id查询活动数据
public static async findData(activityId: number, roleId: string, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ roleId, activityId }).lean(lean);
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ serverId, roleId, activityId }).lean(lean);
return result;
}
//查询第几天的活动数据
public static async findDataByDayIndex(activityId: number, roleId: string, dayIndex: number, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ roleId, activityId, dayIndex }).lean(lean);
public static async findDataByDayIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ serverId, roleId, activityId, dayIndex }).lean(lean);
return result;
}
//查询第几天某个的活动数据
public static async findDataByCellIndex(activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ roleId, activityId, dayIndex, cellIndex }).lean(lean);
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(lean);
return result;
}
//新增领取记录
public static async addData(activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, activityId, dayIndex, cellIndex },
public static async addData(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
{ $: { count: count } },
{ upsert: true, new: true }).lean(lean);
return result;
}
//删除活动领取记录
public static async deleteActivity(activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
await ActivityGrowthModel.deleteMany({ roleId, activityId, dayIndex, cellIndex });
public static async deleteActivity(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
await ActivityGrowthModel.deleteMany({ serverId, roleId, activityId, dayIndex, cellIndex });
}
}
+9 -20
View File
@@ -2,17 +2,6 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 购买记录
*/
export class BuyRecord {
@prop({ required: true })
id: number; //物品id标识
@prop({ required: true })
time: Date; //购买时间
}
/**
* 活动系统 - 弹出商店
*/
@@ -30,18 +19,18 @@ export default class ActivityPopUpShop extends BaseModel {
@prop({ required: true })
endTime: Date; // 结束时间
@prop({ required: true })
taskId: number; // 任务id
id: number; // 任务id
@prop({ required: true })
records: BuyRecord[]; // 购买记录
isBuy: boolean; // 是否购买
//购买奖励的记录
public static async addRecord(serverId: number, activityId: number, roleId: string, taskId: number, id: number) {
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
let nowDate = new Date();
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({
serverId, roleId, activityId, taskId,
serverId, roleId, activityId, id,
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
},
{ $push: { records: { id, time: new Date() } } }, { upsert: true, new: true }).lean(true);
{ $set: { isBuy: true } }, { upsert: true, new: true }).lean(true);
return result;
}
@@ -56,20 +45,20 @@ export default class ActivityPopUpShop extends BaseModel {
}
//根据活动taskId查询现在正在进行的活动数据
public static async findOpenDataByTaskId(serverId: number, activityId: number, roleId: string, taskId: number) {
public static async findOpenDataByTaskId(serverId: number, activityId: number, roleId: string, id: number) {
let nowDate = new Date();
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOne({
serverId, roleId, activityId, taskId,
serverId, roleId, activityId, id,
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
}).lean(true);
return result;
}
//删除活动领取记录
public static async deleteActivity(serverId: number, activityId: number, roleId: string, taskId: number) {
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number) {
let nowDate = new Date();
await ActivityPopUpShopModel.deleteMany({
roleId, activityId, taskId,
roleId, activityId, id,
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
});
}
@@ -26,6 +26,7 @@ export class DailyItem {
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.condition = data.condition;
this.reward = data.reward;
}
@@ -50,7 +51,7 @@ export class DailyItem {
}
public canReceive(): boolean {
return this.receiveRewardCount != 0;
return this.receiveRewardCount == 0;
}
public isComplete(): boolean {
@@ -121,8 +122,11 @@ export class DailyChallengesData extends ActivityBase {
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.totalCount = data[index].totalCount;
obj.receiveRewardCount = data[index].receiveRewardCount;
obj.totalCount = data[index].totalCount ? data[index].totalCount : 0;
obj.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
} else {
obj.totalCount = 0;
obj.receiveRewardCount = 0
}
}
}
+3 -3
View File
@@ -59,7 +59,7 @@ export class GrowthItem {
}
public canReceive(): boolean {
return this.receiveRewardCount != 0;
return this.receiveRewardCount == 0;
}
public isComplete(): boolean {
@@ -140,8 +140,8 @@ export class GrowthData extends ActivityBase {
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.totalCount = data[index].totalCount;
obj.receiveRewardCount = data[index].receiveRewardCount;
obj.totalCount = data[index].totalCount ? data[index].totalCount : 0;
obj.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
obj.addPointCount = data[index].addPointCount ? data[index].addPointCount : 0;
obj.getPointReward = data[index].getPointReward ? data[index].getPointReward : false;
this.totalPoint += obj.addPointCount;
+28 -60
View File
@@ -1,77 +1,45 @@
import { DAILYRMBGIFTS_DAYS } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityPopUpShopModelType } from '../../db/ActivityPopUpShop';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 商品数据
export class PopUpShopItem {
// 弹框商店
export class PopUpShopData {
id: number; // 第几个,从1开始
name: string; //名字
consume: string; //消耗资源(这里优先rmb的price价格,其次资源消耗)
price: number; // 商品价格
productID: string; // 商品id支付时使用
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
countMax: number = 0; //可购买的最大次数,0表示不限制
name: string; //名字
rebate: number; // 折扣用于显示
duration: number; // 持续时间,单位小时
taskType: number; // 任务类型
taskParam: number; // 任务参数
condition: number; // 任务条件
isBuy: boolean = false; //购买过
buyCount: number = 0; //购买过的次数
// //解析玩家购买记录
// public setPlayerRecords(data: ActivityPopUpShopModelType) {
// if (!data) {
// return;
// }
// for (let item of this.list) {
// let buyRecords = data.records.filter(obj => { return obj && obj.id === item.id });
// item.buyCount = buyRecords.length;
// }
// }
constructor(data: any) {
public initData(data: any) {
this.id = data.id;
this.reward = data.reward;
this.countMax = data.countMax;
this.consume = data.consume ? data.consume : '';
this.price = data.price ? data.price : 0;
this.productID = data.productID ? data.productID : '';
this.name = data.name;
}
}
// 弹框商店
export class PopUpShopData {
name: string = '';//活动名称
taskId: number = 0;//id
list: Array<PopUpShopItem> = [];//每件商品信息
public findItemByProductID(productID: string) {
let index = this.list.findIndex(obj => { return obj && obj.productID === productID });
return (index != -1) ? this.list[index] : null
}
public findItem(id: number) {
let index = this.list.findIndex(obj => { return obj && obj.id === id });
return (index != -1) ? this.list[index] : null
}
//全部领取完成
public isComplete() {
for (let item of this.list) {
if (item.countMax == 0 ||
(item.countMax > 0 && item.buyCount < item.countMax)) {
return false
}
}
return true;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityPopUpShopModelType) {
if (!data) {
return;
}
for (let item of this.list) {
let buyRecords = data.records.filter(obj => { return obj && obj.id === item.id });
item.buyCount = buyRecords.length;
}
}
public initData(data: any) {
this.taskId = data.taskId;
let arr = data.data;
for (let obj of arr) {
this.list.push(new PopUpShopItem(obj))
}
this.rebate = data.rebate;
this.duration = data.duration;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.condition = data.condition;
this.isBuy = false;
}
constructor(activityData: any) {
+2 -2
View File
@@ -491,9 +491,9 @@ export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count:
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
if (addCount) {
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE) {
await ActivityGrowthModel.setTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
await ActivityGrowthModel.setTaskCount(activity.serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
} else {
await ActivityGrowthModel.addTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
await ActivityGrowthModel.addTaskCount(activity.serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
}
}
}