✨ feat(活动): 月基金
This commit is contained in:
@@ -64,6 +64,7 @@ export enum ACTIVITY_TYPE {
|
||||
GROUP_SHOP = 49, // 团购
|
||||
BIND_PHONE = 50, // 绑定手机号
|
||||
WEEKLY_FUND = 51, // 周基金
|
||||
MONTHLY_FUND = 52, // 月基金
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1150,6 +1150,8 @@ export enum ITEM_CHANGE_REASON {
|
||||
ACT_MINI_GAME_BUY_CNT = 180, // 小游戏花元宝买
|
||||
ACT_WEEKLY_FUND_BUY = 181, // 周基金一次性购买
|
||||
ACT_WEEKLY_FUND_SIGN = 182, // 周基金签到
|
||||
ACT_MONTHLY_FUND_BUY = 183, // 月基金一次性购买
|
||||
ACT_MONTHLY_FUND_SIGN = 184, // 月基金签到
|
||||
}
|
||||
|
||||
export enum TA_EVENT {
|
||||
|
||||
@@ -659,6 +659,10 @@ export const STATUS = {
|
||||
ACTIVITY_WEEKLY_FUND_NOT_FOUND: { code: 50057, simStr: '未找到该配置' },
|
||||
ACTIVITY_WEEKLY_FUND_LOCK: { code: 50058, simStr: '本次签到暂未解锁' },
|
||||
ACTIVITY_WEEKLY_FUND_HAS_SIGN: { code: 50059, simStr: '本次签到奖励已领取' },
|
||||
ACTIVITY_MONTHLY_FUND_NOT_BOUGHT: { code: 50060, simStr: '月基金未购买' },
|
||||
ACTIVITY_MONTHLY_FUND_NOT_FOUND: { code: 50061, simStr: '未找到该配置' },
|
||||
ACTIVITY_MONTHLY_FUND_LOCK: { code: 50062, simStr: '本次签到暂未解锁' },
|
||||
ACTIVITY_MONTHLY_FUND_HAS_SIGN: { code: 60063, simStr: '本次签到奖励已领取' },
|
||||
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
|
||||
66
shared/db/ActivityMonthlyFund.ts
Normal file
66
shared/db/ActivityMonthlyFund.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 周基金
|
||||
*/
|
||||
|
||||
class SignRecord {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天的签到
|
||||
@prop({ required: true })
|
||||
todayIndex: number; // 签到当天是第几天
|
||||
@prop({ required: true })
|
||||
time: Date; // 时间戳
|
||||
|
||||
constructor(dayIndex: number, todayIndex: number) {
|
||||
this.dayIndex = dayIndex;
|
||||
this.todayIndex = todayIndex;
|
||||
this.time = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
@index({ roleId: 1, activityId: 1 })
|
||||
|
||||
export default class Activity_Monthly_Fund extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服Id
|
||||
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 第几轮
|
||||
|
||||
@prop({ required: true })
|
||||
pageIndex: number; // 第几页
|
||||
|
||||
@prop({ required: true })
|
||||
productID: string; // 商品id
|
||||
|
||||
@prop({ required: true, type: SignRecord, _id: false })
|
||||
record: SignRecord[]; // 铸造记录
|
||||
|
||||
public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) {
|
||||
let result: ActivityMonthlyFundModelType[] = await ActivityMonthlyFundModel.find({ serverId, roleId, activityId, roundIndex }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async buy(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, productID: string) {
|
||||
let result: ActivityMonthlyFundModelType = await ActivityMonthlyFundModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex }, { $setOnInsert: { record: [], productID } }, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async sign(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, dayIndex: number, todayIndex: number) {
|
||||
let result: ActivityMonthlyFundModelType = await ActivityMonthlyFundModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, 'record.dayIndex': { $ne: dayIndex } }, { $push: { record: new SignRecord(dayIndex, todayIndex)} }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityMonthlyFundModel = getModelForClass(Activity_Monthly_Fund);
|
||||
|
||||
export interface ActivityMonthlyFundModelType extends Pick<DocumentType<Activity_Monthly_Fund>, keyof Activity_Monthly_Fund> { }
|
||||
export type ActivityMonthlyFundModelTypeParam = Partial<ActivityMonthlyFundModelType>; // 将所有字段变成可选项
|
||||
129
shared/domain/activityField/monthlyFundField.ts
Normal file
129
shared/domain/activityField/monthlyFundField.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
// 周基金
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityMonthlyFundModelType } from '../../db/ActivityMonthlyFund';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
interface MonthlyFundRewardInDb {
|
||||
dayIndex: number; // 第几天
|
||||
reward: string; // 每天签到的奖励 type&id&count
|
||||
}
|
||||
|
||||
interface MonthlyFundPageInDb {
|
||||
pageIndex: number;
|
||||
name: string;
|
||||
productID: string; // 商品id,商品表
|
||||
price: number; // 购买价格
|
||||
onceReward: string; // 购买后立刻可以获得的奖励 type&id&count
|
||||
rewards: MonthlyFundRewardInDb[]; // 每天签到可领取的奖励
|
||||
rebate: number; // 显示用的返利倍数
|
||||
buyEndDay: number; // 购买截止时间
|
||||
}
|
||||
|
||||
interface MonthlyFundDataInDb {
|
||||
list: MonthlyFundPageInDb[];
|
||||
}
|
||||
|
||||
class MonthlyFundReward {
|
||||
dayIndex: number; // 第几天
|
||||
reward: string; // 每天签到的奖励 type&id&count
|
||||
hasReceived: boolean = false; // 是否领取过
|
||||
|
||||
constructor(data: MonthlyFundRewardInDb) {
|
||||
this.dayIndex = data.dayIndex;
|
||||
this.reward = data.reward;
|
||||
}
|
||||
|
||||
public setHasReceived() {
|
||||
this.hasReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
class MonthlyFundPage {
|
||||
pageIndex: number; // 第几页
|
||||
name: string; // 基金
|
||||
productID: string; // 商品id,商品表
|
||||
price: number; // 购买价格
|
||||
onceReward: string; // 购买后立刻可以获得的奖励 type&id&count
|
||||
rebate: number; // 显示用的返利倍数
|
||||
buyEndTime: number = 0; // 购买截止时间
|
||||
rewards: MonthlyFundReward[] = []; // 每天签到可领取的奖励
|
||||
|
||||
hasBought: boolean = false; // 是否购买了
|
||||
|
||||
constructor(dataObj: MonthlyFundPageInDb, beginTime: number) {
|
||||
this.pageIndex = dataObj.pageIndex;
|
||||
this.name = dataObj.name;
|
||||
this.productID = dataObj.productID;
|
||||
this.price = dataObj.price;
|
||||
this.onceReward = dataObj.onceReward;
|
||||
this.rebate = dataObj.rebate;
|
||||
this.buyEndTime = beginTime + dataObj.buyEndDay * 86400000;
|
||||
for(let reward of (dataObj.rewards||[])) {
|
||||
this.rewards.push(new MonthlyFundReward(reward));
|
||||
}
|
||||
}
|
||||
|
||||
public setPlayerRecord(playerData: ActivityMonthlyFundModelType) {
|
||||
if(!playerData) return;
|
||||
this.hasBought = true;
|
||||
for(let { dayIndex } of playerData.record) {
|
||||
let reward = this.rewards.find(cur => cur.dayIndex == dayIndex);
|
||||
if(reward) reward.setHasReceived();
|
||||
}
|
||||
}
|
||||
|
||||
public findSignReward(dayIndex: number) {
|
||||
return this.rewards.find(cur => cur.dayIndex == dayIndex);
|
||||
}
|
||||
|
||||
private hasReceivedAll() {
|
||||
return !this.rewards.find(cur => !cur.hasReceived);
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
if(this.buyEndTime < Date.now() && !this.hasBought) return null;
|
||||
if(this.hasReceivedAll()) return null
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export class MonthlyFundData extends ActivityBase {
|
||||
|
||||
list: MonthlyFundPage[] = [];
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
|
||||
public initData(data: string): void {
|
||||
let dataObj: MonthlyFundDataInDb = JSON.parse(data);
|
||||
if(!dataObj) return;
|
||||
for(let data of (dataObj.list||[])) {
|
||||
let obj = new MonthlyFundPage(data, this.beginTime);
|
||||
if(obj) this.list.push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public setPlayerRecords(playerDatas: ActivityMonthlyFundModelType[]) {
|
||||
for(let playerData of playerDatas) {
|
||||
let data = this.list.find(cur => cur.pageIndex == playerData.pageIndex);
|
||||
if(data) data.setPlayerRecord(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
public findPage(pageIndex: number) {
|
||||
return this.list.find(cur => cur.pageIndex == pageIndex);
|
||||
}
|
||||
|
||||
public findByProductID(productID: string) {
|
||||
return this.list.find(cur => cur.productID == productID);
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
return {
|
||||
...this.getBaseKeys(),
|
||||
list: this.list.map(data => data.getShowResult()).filter(cur => cur)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user