活动:弹出商店添加条件判断
This commit is contained in:
@@ -361,6 +361,7 @@ export const STATUS = {
|
||||
ACTIVITY_GOLD_RESOURCE: { code: 50024, simStr: '元宝资源' },
|
||||
ACTIVITY_ID_ERROR: { code: 50025, simStr: 'id错误' },
|
||||
ACTIVITY_NEW_PLAYER_GIFT_END: { code: 50026, simStr: '新手活动结束' },
|
||||
ACTIVITY_POP_UP_SHOP_CLOSED: { code: 50027, simStr: '商店已经关闭' },
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||
|
||||
@@ -21,13 +21,19 @@ export default class Activity_Pop_Up_Shop extends BaseModel {
|
||||
@prop({ required: true })
|
||||
id: number; // 任务id
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true })
|
||||
isBuy: boolean; // 是否购买
|
||||
|
||||
//购买记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number, type: number) {
|
||||
let nowDate = new Date();
|
||||
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({
|
||||
serverId, roleId, activityId, id,
|
||||
serverId, roleId, activityId, id, type,
|
||||
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
||||
},
|
||||
{ $set: { isBuy: true } }, { upsert: true, new: true }).lean(true);
|
||||
@@ -39,21 +45,43 @@ export default class Activity_Pop_Up_Shop extends BaseModel {
|
||||
let nowDate = new Date();
|
||||
let result: ActivityPopUpShopModelType[] = await ActivityPopUpShopModel.find({
|
||||
serverId, roleId, activityId,
|
||||
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
||||
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate },
|
||||
isBuy: { $ne: true },
|
||||
}).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动taskId查询现在正在进行的活动数据
|
||||
public static async findOpenDataByTaskId(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
public static async findOpenDataByTaskId(serverId: number, activityId: number, roleId: string, id: number, type: number) {
|
||||
let nowDate = new Date();
|
||||
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOne({
|
||||
serverId, roleId, activityId, id,
|
||||
serverId, roleId, activityId, id, type,
|
||||
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
|
||||
}).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, id: number, type: number, count: number) {
|
||||
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ serverId, roleId, activityId, id, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, id: number, type: number, addCount: number) {
|
||||
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ serverId, roleId, activityId, id, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, id: number, type: number, data: string,) {
|
||||
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ serverId, roleId, activityId, id, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(_serverId: number, activityId: number, roleId: string, id: number) {
|
||||
let nowDate = new Date();
|
||||
|
||||
@@ -58,14 +58,14 @@ export class DailyRMBGiftsData extends ActivityBase {
|
||||
return;
|
||||
}
|
||||
let records = data.records ? data.records : [];
|
||||
let isOver = false;
|
||||
let isOver = true;
|
||||
for (let item of this.list) {
|
||||
let index = records.findIndex(obj => { return obj.id === item.id })
|
||||
if (index != -1) {
|
||||
item.isReceive = true;
|
||||
}
|
||||
if (!item.isReceive) {
|
||||
isOver = true;
|
||||
isOver = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { ActivityPopUpShopModelType } from "../../db/ActivityPopUpShop";
|
||||
|
||||
// 弹框商店
|
||||
export class PopUpShopData {
|
||||
|
||||
activityId: number; // 活动id
|
||||
id: number; // 第几个,从1开始
|
||||
name: string; //名字
|
||||
consume: string; //消耗资源(这里优先rmb的price价格,其次资源消耗)
|
||||
@@ -13,18 +15,22 @@ export class PopUpShopData {
|
||||
taskType: number; // 任务类型
|
||||
taskParam: number; // 任务参数
|
||||
condition: number; // 任务条件
|
||||
isBuy: boolean = false; //购买过
|
||||
totalCount: number; //一共完成次数
|
||||
|
||||
// //解析玩家购买记录
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
isBuy: boolean = false; //购买过
|
||||
beginTime: Date = null;//开始时间
|
||||
endTime: Date = null;//结束时间
|
||||
|
||||
//解析玩家购买记录
|
||||
public setPlayerRecords(data: ActivityPopUpShopModelType) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
this.isBuy = data.isBuy ? data.isBuy : false;
|
||||
this.beginTime = data.beginTime;
|
||||
this.endTime = data.endTime;
|
||||
this.totalCount = data.totalCount;
|
||||
}
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
@@ -40,9 +46,13 @@ export class PopUpShopData {
|
||||
this.taskParam = data.taskParam;
|
||||
this.condition = data.condition;
|
||||
this.isBuy = false;
|
||||
this.beginTime = null;
|
||||
this.endTime = null;
|
||||
this.totalCount = 0;
|
||||
}
|
||||
|
||||
constructor(activityData: any) {
|
||||
constructor(activityData: any, activityId: number) {
|
||||
this.activityId = activityId;
|
||||
this.initData(activityData)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import { ActivityThirtyDaysModel, ActivityThirtyDaysModelType } from '../db/Acti
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { ActivityGrowthFundModel, ActivityGrowthFundModelType } from '../db/ActivityGrowthFund';
|
||||
import { ActivityBuyRecordsModel } from '../db/ActivityBuyRecords';
|
||||
import { PopUpShopData } from '../domain/activityField/popUpShopField';
|
||||
import { ActivityPopUpShopModel } from '../db/ActivityPopUpShop';
|
||||
|
||||
|
||||
|
||||
@@ -567,6 +569,32 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
}
|
||||
}
|
||||
|
||||
//弹出商店
|
||||
{
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||
} else {
|
||||
await ActivityPopUpShopModel.addTaskCount(serverId, activity.activityId, roleId, task.id, task.taskType, addCount);
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
await ActivityPopUpShopModel.addTaskRecord(serverId, activity.activityId, roleId, task.id, task.taskType, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//主线成长基金
|
||||
if (taskType === TASK_TYPE.BATTLE_MAIN) {
|
||||
allActivity = await ActivityModel.findOpenActivityByTypes(activityGroupId, [ACTIVITY_TYPE.GROWTH_FUND_MAIN, ACTIVITY_TYPE.GROWTH_FUND_MAIN_VIP], new Date());
|
||||
|
||||
Reference in New Issue
Block a user