活动:调整每日优惠的结构

This commit is contained in:
qiaoxin
2021-05-31 18:07:41 +08:00
parent d2a8bbeb5d
commit 75403c4540
6 changed files with 162 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
import { DAILYRMBGIFTS_DAYS } from '../../consts';
import moment = require('moment');
import { DAILYRMBGIFTS_DAYS, REFRESH_TIME } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityDailyRMBGiftsModelType } from '../../db/ActivityDailyRMBGifts';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 商品数据
@@ -12,7 +12,6 @@ export class DailyRMBGiftsItem {
price: number; //价格
reward: string; //奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
isBuy: boolean = false; //是否已经购买
isReceive: boolean = false; //是否领取过奖励
constructor(data: any) {
@@ -21,6 +20,7 @@ export class DailyRMBGiftsItem {
this.name = data.name;
this.price = data.price;
this.reward = data.reward;
this.isReceive = false;
}
}
@@ -31,11 +31,17 @@ export class DailyRMBGiftsData extends ActivityBase {
price: number = 0;//一次性购买的价格
productID: string = '';//一次性购买的商品id
list: Array<DailyRMBGiftsItem> = [];//每件商品信息
isBuy: boolean = false;//是否一次性购买过
receiveCount: number = 0;//已经领取次数(一次性购买)
unReceiveCount: number = 0;//剩余领取次数(一次性购买)
public findTodayItem() {
let index = this.list.findIndex(obj => { return obj.productID == '' });
public unReceiveItem() {
return this.list.filter(obj => { return !obj.isReceive });
}
public findItem(id: number) {
let index = this.list.findIndex(obj => { return obj.id == id });
return (index != -1) ? this.list[index] : null
}
@@ -45,36 +51,47 @@ export class DailyRMBGiftsData extends ActivityBase {
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType[], endTime: Date) {
let isOver = true;
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType, unReceiveCount: number) {
this.isBuy = false;
this.unReceiveCount = 0;
if (!data) {
return;
}
let records = data.records ? data.records : [];
let isOver = false;
for (let item of this.list) {
let index = data.findIndex(obj => { obj.id == item.id });
let index = records.findIndex(obj => { return obj.id === item.id })
if (index != -1) {
item.isBuy = true;
item.isReceive = true;
} else {
item.isBuy = false;
item.isReceive = false;
isOver = false;
}
if (!item.isReceive) {
isOver = true;
}
}
if (endTime) {//DAILYRMBGIFTS_DAYS天内有购买过一次性礼包结束时间
if (new Date() < endTime) {
for (let item of this.list) {
item.isBuy = true;
}
}
this.receiveCount = deltaDays(new Date, endTime) + (isOver ? 0 : 1);
this.isBuy = data.isBuy;
this.unReceiveCount = unReceiveCount;
if (this.isBuy && !isOver) {
this.unReceiveCount += 1;
}
}
public initData(data: string) {
this.isBuy = false;
this.unReceiveCount = 0;
let dataObj = JSON.parse(data);
this.name = dataObj.name;
this.day = dataObj.day;
this.price = dataObj.price;
this.productID = dataObj.productID;
let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) {
this.beginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
} else {
this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
}
let arr = dataObj.data;
for (let obj of arr) {