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

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

View File

@@ -39,12 +39,12 @@ export class PopUpShopHandler {
/**
* @description 购买礼包
* @param {{ activityId: number, taskId: number, id: number}} msg
* @param {{ activityId: number, id: number}} msg
* @param {BackendSession} session
* @memberof PopUpShopHandler
*/
async buyGift(msg: { activityId: number, taskId: number, id: number }, session: BackendSession) {
const { activityId, taskId, id } = msg;
async buyGift(msg: { activityId: number, id: number }, session: BackendSession) {
const { activityId, id } = msg;
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const sid = session.get('sid');
@@ -55,32 +55,32 @@ export class PopUpShopHandler {
if (!activityData) {
return resResult(STATUS.ACTIVITY_MISSING);
}
let playerRecords: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOpenDataByTaskId(serverId, activityId, roleId, taskId);
let playerRecords: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOpenDataByTaskId(serverId, activityId, roleId, id);
if (!playerRecords) {
return resResult(STATUS.ACTIVITY_POP_UP_SHOP_EXPIRE);
}
if (playerRecords.isBuy) {
return resResult(STATUS.ACTIVITY_REWARDED);
}
let allTaskData: any[] = JSON.parse(activityData.data);
let taskIndex = allTaskData.findIndex(obj => { return obj && obj.taskId == taskId });
let taskIndex = allTaskData.findIndex(obj => { return obj && obj.id == id });
if (taskIndex == -1) {
return resResult(STATUS.ACTIVITY_DATA_ERROR);
}
let playerData = new PopUpShopData(allTaskData[taskIndex]);
let itemData = playerData.findItem(id);
if (!itemData) {
return resResult(STATUS.ACTIVITY_DATA_ERROR);
}
if (itemData.price) {
if (playerData.price) {
return resResult(STATUS.ACTIVITY_NEED_PAY);
}
if (itemData.consume) {
if (playerData.consume) {
return resResult(STATUS.ACTIVITY_NEED_PAY);
}
//元宝消费
let arr = splitString(itemData.consume, '&')
let arr = splitString(playerData.consume, '&')
if (arr[0] != ACTIVITY_RESOURCES_TYPE.GOODS || arr[1] != CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD)) {
return resResult(STATUS.ACTIVITY_GOLD_RESOURCE);
}
@@ -88,7 +88,7 @@ export class PopUpShopHandler {
let resourceResult = await handleCost(roleId, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: price }]);
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let rewardParamArr: Array<RewardParam> = stringToRewardParam(itemData.reward);
let rewardParamArr: Array<RewardParam> = stringToRewardParam(playerData.reward);
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
return resResult(STATUS.SUCCESS, result);
}

View File

@@ -10,6 +10,8 @@ import { DailyItem } from '../../../domain/activityField/dailyChallengesField';
import { getPlayerDailyGiftsData } from '../../../services/dailyGiftsService';
import { DailyGiftItem } from '../../../domain/activityField/dailyGiftsField';
import { ActivityDailyGiftsModel } from '../../../db/ActivityDailyGifts';
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
import { RewardParam } from '../../../domain/activityField/rewardField';
export default function (app: Application) {
@@ -68,18 +70,18 @@ export class SevenDaysHandler {
return resResult(STATUS.ACTIVITY_REWARDED);
}
await ActivityGrowthModel.addCellRecord(activityId, roleId, dayIndex, cellIndex, type, 1);
let reward = growthItemData.goodReward();
let goods = await addItems(roleId, roleName, sid, reward);
let heroReward = growthItemData.heroReward();
let addHeros = [];
if (heroReward.length > 0) {
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
goods = goods.concat(heroResult.goods)
addHeros = addHeros.concat(heroResult.heroes);
}
await ActivityGrowthModel.addCellRecord(serverId, activityId, roleId, dayIndex, cellIndex, type, 1, growthItemData.point);
let rewardParamArr: Array<RewardParam> = stringToRewardParam(growthItemData.reward);
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
return resResult(STATUS.SUCCESS, { goods, addHeros });
growthItemData.receiveRewardCount = 1;
growthItemData.addPointCount = growthItemData.point;
playerData.totalPoint += growthItemData.point;
return resResult(STATUS.SUCCESS, Object.assign(result, {
param: msg,
item: growthItemData,
totalPoint: playerData.totalPoint
}));
}
/**
@@ -113,19 +115,19 @@ export class SevenDaysHandler {
return resResult(STATUS.ACTIVITY_TIME_ERROR);
}
await ActivityGrowthModel.addDayRecord(activityId, roleId, dayIndex, 1);
await ActivityGrowthModel.addDayRecord(serverId, activityId, roleId, dayIndex, 1);
let reward = dayItemData.goodReward();
let goods = await addItems(roleId, roleName, sid, reward);
let heroReward = dayItemData.heroReward();
let addHeros = [];
if (heroReward.length > 0) {
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
goods = goods.concat(heroResult.goods)
addHeros = addHeros.concat(heroResult.heroes);
}
let rewardParamArr: Array<RewardParam> = stringToRewardParam(dayItemData.reward);
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
return resResult(STATUS.SUCCESS, { goods, addHeros });
dayItemData.getPointReward = true;
playerData.totalConsumePoint += dayItemData.consumePoint;
return resResult(STATUS.SUCCESS, Object.assign(result, {
param: msg,
item: dayItemData,
totalPoint: playerData.totalPoint
}));
}
/************************今日挑战****************************/
@@ -176,7 +178,7 @@ export class SevenDaysHandler {
return resResult(STATUS.ACTIVITY_REWARDED);
}
await ActivityGrowthModel.addCellRecord(activityId, roleId, dayIndex, cellIndex, type, 1);
await ActivityGrowthModel.addCellRecord(serverId, activityId, roleId, dayIndex, cellIndex, type, 1, 0);
let reward = dailyItemData.goodReward();
let goods = await addItems(roleId, roleName, sid, reward);
let heroReward = dailyItemData.heroReward();

View File

@@ -25,7 +25,7 @@ export async function getActivityData(activityId: number, serverId: number, role
*/
export async function getPlayerGrowthData(activityId: number, serverId: number, roleId: string) {
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
let playerRecords: ActivityGrowthModelType[] = await ActivityGrowthModel.findData(activityId, roleId);
let playerRecords: ActivityGrowthModelType[] = await ActivityGrowthModel.findData(serverId, activityId, roleId);
let playerData = new GrowthData(activityData);
playerData.setPlayerRecords(playerRecords);

View File

@@ -1,7 +1,7 @@
import { ACTIVITY_TYPE, TASK_TYPE } from '../consts';
import { ActivityModel, ActivityModelType } from '../db/Activity';
import { ActivityDailyRMBGiftsModel, ActivityDailyRMBGiftsModelType } from '../db/ActivityDailyRMBGifts';
import { PopUpShopData, PopUpShopItem } from '../domain/activityField/PopUpSHopField';
import { PopUpShopData, } from '../domain/activityField/PopUpSHopField';
import { RoleModel } from '../db/Role';
import moment = require('moment');
import { UserOrderModel, UserOrderModelType } from '../db/UserOrder';
@@ -45,14 +45,15 @@ export async function getPlayerPopUpShopData(activityId: number, serverId: numbe
let allPlayerShop = [];
let allTaskData = JSON.parse(activityData.data);
for (let taskData of allTaskData) {
let playerData = new PopUpShopData(taskData);
let taskId = playerData.taskId;
let index = playerRecords.findIndex(obj => { return obj && obj.taskId == taskId });
if (index != -1) {
playerData.setPlayerRecords(playerRecords[index])
for (let record of playerRecords) {
if (!record.isBuy) {//没有购买
let index = allTaskData.findIndex(obj => { return obj && obj.id === record.id })
if (index != -1) {
let playerData = new PopUpShopData(allTaskData[index]);
playerData.isBuy == false;
allPlayerShop.push(playerData)
}
}
allPlayerShop.push(playerData)
}
return allPlayerShop;
}
@@ -78,15 +79,12 @@ export async function makePopUpShopReward(roleId: string, roleName: string, sid:
return null;
}
let playerData = new PopUpShopData(allTaskData[taskIndex]);
let taskId = playerData.taskId;
let item = playerData.findItemByProductID(productID);
let playerRecords: ActivityPopUpShopModelType = await ActivityPopUpShopModel.addRecord(serverId, activityId, roleId, taskId, item.id);
let playerRecords: ActivityPopUpShopModelType = await ActivityPopUpShopModel.addRecord(serverId, activityId, roleId, playerData.id);
if (!playerRecords) {
return null;
}
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
let rewardParamArr: Array<RewardParam> = stringToRewardParam(playerData.reward);
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
return result
}
}

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 });
}
}

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 }
});
}

View File

@@ -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
}
}
}

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;

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) {

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);
}
}
}