活动:每日兑换铜币活动
This commit is contained in:
@@ -35,6 +35,7 @@ export enum ACTIVITY_TYPE {
|
||||
FOURTEEN_DAY = 28, // 十四天乐活动
|
||||
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
|
||||
DAILY_MEAL = 30, // 每日领取免费午饭、晚饭活动
|
||||
DAILY_COIN = 31, // 每日兑换铜钱
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 每日兑换铜币
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Daily_Coin extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
beginTime: number; // 开始统计的时间
|
||||
@prop({ required: true })
|
||||
exchangeCount: number; // 兑换次数
|
||||
|
||||
|
||||
//兑换记录
|
||||
public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, beginTime: number, count: number) {
|
||||
let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, beginTime }, { $inc: { exchangeCount: count } }, { upsert: true, new: true }).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动时间查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, beginTime: number) {
|
||||
let result: ActivityDailyCoinModelType = await ActivityDailyCoinModel.findOne({
|
||||
serverId, roleId, activityId, beginTime,
|
||||
}).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动兑换记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, beginTime: number) {
|
||||
await ActivityDailyCoinModel.deleteMany({ serverId, roleId, activityId, beginTime });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityDailyCoinModel = getModelForClass(Activity_Daily_Coin);
|
||||
|
||||
export interface ActivityDailyCoinModelType extends Pick<DocumentType<Activity_Daily_Coin>, keyof Activity_Daily_Coin> { }
|
||||
export type ActivityDailyCoinModelTypeParam = Partial<ActivityDailyCoinModelType>; // 将所有字段变成可选项
|
||||
@@ -18,21 +18,19 @@ export default class Activity_Self_Service_Goods extends BaseModel {
|
||||
@prop({ required: true })
|
||||
cellIndex: number; // 第几个坑位从1开始
|
||||
@prop({ required: true })
|
||||
gift: number; // 礼包id
|
||||
@prop({ required: true })
|
||||
rewardIndex: number; // 礼包中第几项奖励
|
||||
|
||||
|
||||
//添加选中的物品
|
||||
public static async addGoods(activityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number) {
|
||||
public static async addGoods(activityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, rewardIndex: number) {
|
||||
let result: ActivitySelfServiceGoodsModelType = await ActivitySelfServiceGoodsModel.findOneAndUpdate({ roleId, activityId, roundIndex, index, cellIndex },
|
||||
{ $set: { gift, rewardIndex } }, { upsert: true, new: true }).lean(true);
|
||||
{ $set: { rewardIndex } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
|
||||
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, activityId, roundIndex }, {
|
||||
index: 1, cellIndex: 1, gift: 1, rewardIndex: 1, _id: -1
|
||||
index: 1, cellIndex: 1, rewardIndex: 1, _id: -1
|
||||
}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import moment = require('moment');
|
||||
import { random } from 'underscore';
|
||||
import { REFRESH_TIME, TASK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyCoinModelType } from '../../db/ActivityDailyCoin';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每次配置数据
|
||||
export class DailyCoinItem {
|
||||
index: number; // 第几次从1开始
|
||||
baseReward: string; //基础奖励
|
||||
extraReward: string; //额外奖励
|
||||
exchangeRate: number; // 兑换比例 1元宝兑换多少铜币
|
||||
double: number; // 双倍概率 0.25
|
||||
fiveTimes: number; // 5倍概率 0.05
|
||||
consume: string; //补签消耗资源
|
||||
|
||||
public getRate() {
|
||||
let ran = (random(99) + 1) * 0.01;//[1,100]
|
||||
ran -= this.double;
|
||||
if (ran <= 0) {
|
||||
return 2;
|
||||
}
|
||||
ran -= this.fiveTimes;
|
||||
if (ran <= 0) {
|
||||
return 5;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.index = data.index;
|
||||
this.baseReward = data.baseReward;
|
||||
this.extraReward = data.extraReward;
|
||||
this.exchangeRate = data.exchangeRate;
|
||||
this.double = data.double;
|
||||
this.fiveTimes = data.fiveTimes;
|
||||
this.consume = data.consume;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每日兑换铜币活动数据
|
||||
export class DailyCoinData extends ActivityBase {
|
||||
list: Array<DailyCoinItem> = [];
|
||||
name: string = '';//名字
|
||||
exchangeCount: number = 0;//已经兑换次数
|
||||
|
||||
public findItem(index: number) {
|
||||
let itemIndex = this.list.findIndex(obj => { return obj.index === index });
|
||||
return (itemIndex != -1) ? this.list[itemIndex] : null;
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityDailyCoinModelType) {
|
||||
this.exchangeCount = data && data.exchangeCount ? data.exchangeCount : 0;
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
this.exchangeCount = 0;
|
||||
let dataObj = JSON.parse(data);
|
||||
let arr = dataObj;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new DailyCoinItem(obj))
|
||||
}
|
||||
let curDate = moment(new Date());
|
||||
if (curDate.hour() < REFRESH_TIME) {
|
||||
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
|
||||
} else {
|
||||
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,11 @@ export class SelfServiceShopItem {
|
||||
|
||||
buyCount: number = 0; //已经购买次数
|
||||
|
||||
public findCellIndex(cellIndex: number) {
|
||||
let index = this.data.findIndex(obj => { return obj && obj.cellIndex === cellIndex });
|
||||
return (index != -1) ? this.data[index] : null;
|
||||
}
|
||||
|
||||
constructor(cellData: any) {
|
||||
this.index = cellData.index;
|
||||
this.name = cellData.name;
|
||||
|
||||
Reference in New Issue
Block a user