活动:七天乐添加获取玩家领取奖励数据接口

This commit is contained in:
qiaoxin
2021-04-21 14:59:36 +08:00
parent 2d114e2533
commit e442e4ea75
4 changed files with 85 additions and 10 deletions

View File

@@ -1,12 +1,15 @@
import { prop } from '@typegoose/typegoose';
import { ActivityModelType } from '../../db/Activity';
import { ActivitySevenDaysModelType } from '../../db/ActivitySevenDays';
import { ActivityBase } from './activityField';
// 每日配置数据
export class SevenDayItem {
@prop({ required: true })
id: number = 0;
dayIndex: number = 0;
@prop({ required: true })
cellIndex: number = 0;
@prop({ required: true })
count: number = 0;
@prop({ required: true })
@@ -14,11 +17,12 @@ export class SevenDayItem {
@prop({ required: true })
isReceive: boolean = false;
constructor(id: number, count: number, total: number, isReceive: boolean) {
this.id = id;
this.count = count;
this.total = total;
this.isReceive = isReceive;
constructor(dayIndex: number, cellIndex: number, count: number, total: number, isReceive: boolean) {
this.dayIndex = dayIndex;//第几天奖励
this.cellIndex = cellIndex;//某天第几个奖励
this.count = count;//已经领取奖励的次数
this.total = total;//总共可领取奖励次数
this.isReceive = isReceive;//是否领取
}
}
@@ -28,10 +32,20 @@ export class SevenDaysData extends ActivityBase {
@prop({ required: true })
items: Array<SevenDayItem> = [];
//解析玩家领取记录
public setPlayerRecords(data: ActivitySevenDaysModelType[]) {
for (let obj of this.items) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.count = data[index].count;
}
}
}
public initData(data: string) {
let arr = JSON.parse(data);
for (let obj of arr) {
this.items.push(new SevenDayItem(obj.id, obj.count, 0, false));
this.items.push(new SevenDayItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
}
}