活动:弹出礼包

This commit is contained in:
luying
2022-03-15 18:20:29 +08:00
parent 8a6627ea13
commit 319d4cf454
14 changed files with 887 additions and 434 deletions
+66 -92
View File
@@ -1,6 +1,28 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { PopShopItem } from '../domain/activityField/popUpShopField';
import { Reward } from '../domain/battleField/pvp';
export class PopUpShopItem {
@prop({ required: true })
id: number; // 分档礼包id
@prop({ required: true })
productID: string; // 商品id
@prop({ required: true })
hasBoughtCnt: number = 0; // 已购买次数
@prop({ required: true, _id: false, type: Reward })
rewards: Reward[] = []; // 已购买次数
constructor(item: PopShopItem) {
this.id = item.id;
this.productID = item.productID;
this.rewards = item.rewardInter;
}
}
/**
* 活动系统 - 弹出商店
@@ -10,119 +32,71 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
export default class Activity_Pop_Up_Shop 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 })
endTime: Date; // 结束时间
@prop({ required: true })
id: number; // 任务id
effectBeginTime: Date; // 刷新等生效开始时间
@prop({ required: true })
type: number; // 任务类型
effectEndTime: Date; // 刷新等生效结束时间
@prop({ required: true })
totalCount: number; // 累计达成次数
id: number; // 礼包id
@prop({ required: true })
data: string; // 数据信息
code: string; // 本礼包本次推送的唯一code
@prop({ required: true, type: PopUpShopItem, _id: false })
items: PopUpShopItem[]; // 礼包id
@prop({ required: true })
buyCount: number; // 购买次数
hasBought: boolean; // 是否购买了
@prop({ required: true })
isPush: boolean; // 是否推送过
isLast: boolean; // 是否是最后一个
//购买记录
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number, type: number, buyCount: number, beginTime: Date) {
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({
serverId, roleId, activityId, id, type,
beginTime: beginTime
},
{ $inc: { buyCount: buyCount } }, { upsert: true, new: true }).lean(true);
return result;
/**
* 获取自然日内的次数
* @param roleId
* @param beginTime
* @param endTime
*/
public static async findAllEffectData(serverId: number, activityId: number, roleId: string) {
let now = new Date();
let rec: ActivityPopUpShopModelType[] = await ActivityPopUpShopModel.find({ roleId, serverId, activityId, effectBeginTime: { $lte: now }, effectEndTime: { $gte: now } }).lean();
return rec;
}
//查询现在正在进行的活动数据
public static async findAllOpenData(serverId: number, activityId: number, roleId: string) {
let nowDate = new Date();
let result: ActivityPopUpShopModelType[] = await ActivityPopUpShopModel.find({
serverId, roleId, activityId,
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate },
isBuy: { $ne: true },
}).lean(true);
return result;
public static async findAllLastData(serverId: number, activityId: number, roleId: string) {
let rec: ActivityPopUpShopModelType[] = await ActivityPopUpShopModel.find({ roleId, serverId, activityId, isLast: true }).lean();
return rec;
}
//根据活动taskId查询现在正在进行的活动数据
public static async findDataByTaskId(serverId: number, activityId: number, roleId: string, id: number, type: number) {
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOne({
serverId, roleId, activityId, id, type,
}).lean(true);
return result;
public static async createRecord(param: ActivityPopUpShopModelTypeParam) {
let { serverId, activityId, roleId, id,} = param;
await ActivityPopUpShopModel.updateMany({ serverId, activityId, roleId, id, isLast: true }, { $set: { isLast: false } });
let code = genCode(8);
let rec: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ code }, { $set: {...param, hasBought: false, isLast: true } }, { new: true, upsert: true }).lean();
return rec;
}
//根据活动开始时间查询现在正在开启的商店数据
public static async findDataByBeginTime(serverId: number, activityId: number, roleId: string, id: number, type: number, beginTime: Date) {
console.log('beginTime', serverId, roleId, activityId, id, type, beginTime)
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOne({
serverId, roleId, activityId, id, type, beginTime: beginTime
}).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;
}
//标记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;
}
//添加数据并标记push消息
public static async addTaskPushMessage(serverId: number, activityId: number, roleId: string, id: number, type: number, totalCount: number, beginTime: Date, endTime: Date) {
let result: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate({ serverId, roleId, activityId, id, type, totalCount, beginTime, endTime },
{ $set: { isPush: true } }, { upsert: true, new: true }).lean(true);
return result;
}
//添加数据并标记push消息
public static async addTaskArrayPushMessage(serverId: number, activityId: number, roleIds: string[], id: number, type: number, totalCount: number, beginTime: Date, endTime: Date) {
let activityData = [];
for (let roleId of roleIds) {
activityData.push(
{ serverId, roleId, activityId, id, type, totalCount, beginTime, endTime, isPush: true, buyCount: 0, data: JSON.stringify({ totalCount }) }
)
}
await ActivityPopUpShopModel.insertMany(activityData);
}
//删除活动领取记录
public static async deleteActivity(_serverId: number, activityId: number, roleId: string, id: number) {
let nowDate = new Date();
await ActivityPopUpShopModel.deleteMany({
roleId, activityId, id,
beginTime: { $lt: nowDate }, endTime: { $gt: nowDate }
});
public static async addRecord(serverId: number, activityId: number, roleId: string, code: string, productID: string) {
let rec: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOneAndUpdate(
{ serverId, activityId, roleId, code, 'items.productID': productID },
{ $set: { hasBought: true }, $inc: { 'items.$.hasBoughtCnt': 1 } },
{ new: true} ).lean();
return rec;
}
}
-55
View File
@@ -1,55 +0,0 @@
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>; // 将所有字段变成可选项