活动:限时排行榜

This commit is contained in:
luying
2022-03-03 14:11:56 +08:00
parent d0eb46ece4
commit f099daf80b
27 changed files with 871 additions and 151 deletions

View File

@@ -6,6 +6,7 @@ import { deltaDays } from '../../pubUtils/util';
// 活动数据
export abstract class ActivityBase {
activityId: number = 0;
name: string = '';
beginTime: number = 0;
endTime: number = 0;
type: number = 0;
@@ -23,9 +24,27 @@ export abstract class ActivityBase {
}
public canShow() {
console.log('#### canShow', this.beginTime <= Date.now(), this.endTime >= Date.now())
return this.beginTime <= Date.now() && this.endTime >= Date.now()
}
/**
* getBaseKeys
*/
public getBaseKeys() {
return {
activityId: this.activityId,
name: this.name,
beginTime: this.beginTime,
endTime: this.endTime,
type: this.type,
todayIndex: this.todayIndex,
delayDay: this.delayDay,
roundIndex: this.roundIndex,
nextRefreshTime: this.nextRefreshTime,
}
}
constructor(activityData: ActivityModelType, createTime: number) {
this.activityId = activityData.activityId;
this.delayDay = activityData.delayDay ? activityData.delayDay : 0;
@@ -34,6 +53,7 @@ export abstract class ActivityBase {
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
this.roundIndex = 1;
this.nextRefreshTime = this.endTime;
this.name = activityData.name;
this.type = activityData.type;
console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)

View File

@@ -138,7 +138,10 @@ export class FirstGiftData extends ActivityBase {
}
public getShowResult() {
return pick(this, 'list');
return {
...this.getBaseKeys(),
list: this.list,
}
}
constructor(activityData: ActivityModelType, createTime: number) {

View File

@@ -171,7 +171,12 @@ export class LuckyTurntableData extends ActivityBase {
public getShowResult() {
return {
...pick(this, ['cost', 'freeCount', 'todayCount', 'count', 'box']),
...this.getBaseKeys(),
cost: this.cost,
freeCount: this.freeCount,
todayCount: this.todayCount,
count: this.count,
box: this.box,
pool: this.pool.map(pool => pool.getShowResult()),
records: this.records.map(record => [record.roleName, record.gid, record.count])
}

View File

@@ -0,0 +1,91 @@
import { pick } from 'underscore';
import { RANK_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityTurntableModelType, TurntableRecord } from '../../db/ActivityTurntableRec';
import { RewardInter } from '../../pubUtils/interface';
import { getRandEelmWithWeight, parseGoodStr } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
interface TimeLimitRewardInDb {
rank: number; // 第几名
rewards: string; // type&id&count
}
interface TimeLimitInDb {
rankType: number; // 排行榜类型
hid: number; // 如果有单个武将排行这里写武将id
rankEndTime: number; // 排行榜统计结束时间。13位时间戳之后会在后台加时间筛选在此之前先找wo
sendMailTime: number; // 发送奖励时间。13位时间戳
rankRewards: TimeLimitRewardInDb[]; // 不同排名的奖励
tabName: string; // 排行榜标签名
}
export class TimeLimitRankReward {
rank: number
rewards: string;
constructor(data: TimeLimitRewardInDb) {
this.rank = data.rank;
this.rewards = data.rewards;
}
}
// 新云转盘活动数据
export class TimeLimitRankData extends ActivityBase {
rankType: number; // 排行榜类型
hid: number; // 如果有单个武将排行这里写武将id
rankEndTime: number; // 排行榜统计结束时间。13位时间戳之后会在后台加时间筛选在此之前先找wo
sendMailTime: number; // 发送奖励时间。13位时间戳
rankRewards: TimeLimitRankReward[] = []; // 不同排名的奖励
tabName: string; // 标签名
// 是否可以记录
public canRecord() {
return this.beginTime <= Date.now() && this.rankEndTime >= Date.now();
}
public getRewardByRank(rank: number) {
let result: TimeLimitRankReward;
for(let reward of this.rankRewards) {
if(reward.rank > rank) break;
result = reward;
}
return result;
}
public needSnapshot() {
switch(this.rankType) {
case RANK_TYPE.GUILD_FUND:
return false;
default:
return true;
}
}
public initData(data: string) {
let dataObj: TimeLimitInDb = JSON.parse(data);
this.rankType = dataObj.rankType;
this.hid = dataObj.hid;
this.rankEndTime = dataObj.rankEndTime;
this.sendMailTime = dataObj.sendMailTime;
for(let rank of dataObj.rankRewards) {
this.rankRewards.push(new TimeLimitRankReward(rank));
}
this.tabName = dataObj.tabName;
}
public getShowResult() {
return {
...this.getBaseKeys(),
rankType: this.rankType,
rankEndTime: this.rankEndTime,
tabName: this.tabName,
}
}
constructor(activityData: ActivityModelType, createTime: number) {
super(activityData, createTime)
this.initData(activityData.data)
}
}