活动:特惠礼包
This commit is contained in:
@@ -166,6 +166,14 @@ export const SIGNIN_VIP_OPEN_LIMIT = 15;
|
||||
//每日特惠礼包RMB购买4挡,一次性支付购买7天,每天只能领取当天的礼包奖励
|
||||
export const DAILYRMBGIFTS_DAYS = 7;//一次性购买*天
|
||||
|
||||
export enum DAILY_RMB_GIFT_STATUS {
|
||||
CAN_BUY = 0, // 可以购买
|
||||
CAN_NOT_BUY = 1, // 不可购买
|
||||
CAN_RECEIVE = 2, // 可以一键领取
|
||||
HAS_RECEIVED = 3, // 已一键领取
|
||||
|
||||
}
|
||||
|
||||
//签到活动开启时间
|
||||
export const SIGNIN_OPEN = 1;//*号0点开启
|
||||
export const SIGNIN_CLOSE = 31;//*号晚上24点结束
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class Activity_Daily_RMB_Gifts extends BaseModel {
|
||||
//获取已经购买还没有领取的数据
|
||||
public static async findBuyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, todayIndex: number) {
|
||||
let result: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.find(
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex: { $gt: todayIndex } }).lean(true);
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex: { $gte: todayIndex } }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DAILYRMBGIFTS_DAYS } from '../../consts';
|
||||
import { DAILYRMBGIFTS_DAYS, DAILY_RMB_GIFT_STATUS } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyRMBGiftsModelType } from '../../db/ActivityDailyRMBGifts';
|
||||
import { ActivityBase } from './activityField';
|
||||
@@ -32,13 +32,14 @@ export class DailyRMBGiftsData extends ActivityBase {
|
||||
list: Array<DailyRMBGiftsItem> = [];//每件商品信息
|
||||
isBuy: boolean = false;//是否一次性购买过
|
||||
|
||||
unReceived: number[] = [];
|
||||
unReceiveCount: number = 0;//剩余领取次数(一次性购买)
|
||||
buttonStatus: number = DAILY_RMB_GIFT_STATUS.CAN_BUY;
|
||||
|
||||
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
|
||||
@@ -50,29 +51,61 @@ export class DailyRMBGiftsData extends ActivityBase {
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType, unReceiveCount: number) {
|
||||
this.isBuy = false;
|
||||
this.unReceiveCount = 0;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
let records = data.records ? data.records : [];
|
||||
let isOver = true;
|
||||
for (let item of this.list) {
|
||||
let index = records.findIndex(obj => { return obj.id === item.id })
|
||||
if (index != -1) {
|
||||
item.isReceive = true;
|
||||
}
|
||||
if (!item.isReceive) {
|
||||
isOver = false;
|
||||
public setPlayerRecords(playerRecords: ActivityDailyRMBGiftsModelType[]) {
|
||||
for(let playerRecord of playerRecords) {
|
||||
if(playerRecord.todayIndex == this.todayIndex) {
|
||||
this.isBuy = !!playerRecord.isBuy;
|
||||
let records = playerRecord.records ? playerRecord.records : [];
|
||||
for(let {id} of records) {
|
||||
let item = this.findItem(id);
|
||||
if(item) item.isReceive = true;
|
||||
}
|
||||
} else {
|
||||
this.unReceived.push(playerRecord.todayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
this.isBuy = data.isBuy ? data.isBuy : false;
|
||||
this.unReceiveCount = unReceiveCount;
|
||||
if (this.isBuy && !isOver) {
|
||||
this.unReceiveCount += 1;
|
||||
this.calTodayReceiveStatus();
|
||||
this.calButtonStatus();
|
||||
}
|
||||
|
||||
public calTodayReceiveStatus() {
|
||||
if(this.isBuy) {
|
||||
let hasAllReceived = !this.list.find(item => !item.isReceive);
|
||||
console.log('##### calTodayReceiveStatus', this.unReceived, this.todayIndex, hasAllReceived)
|
||||
if(!hasAllReceived && this.unReceived.indexOf(this.todayIndex) == -1) {
|
||||
this.unReceived.push(this.todayIndex);
|
||||
}
|
||||
}
|
||||
this.unReceiveCount = this.unReceived.length;
|
||||
}
|
||||
|
||||
public calButtonStatus() {
|
||||
if(this.isBuy) { // 已购买
|
||||
let hasAllReceived = !this.list.find(item => !item.isReceive);
|
||||
if(hasAllReceived) { // 买了且全都领完
|
||||
this.buttonStatus = DAILY_RMB_GIFT_STATUS.HAS_RECEIVED;
|
||||
} else {
|
||||
this.buttonStatus = DAILY_RMB_GIFT_STATUS.CAN_RECEIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public shouldbuyNextDay() {
|
||||
return this.list.filter(item => item.isReceive && item.price != 0).length != 0;
|
||||
}
|
||||
|
||||
public receiveItems(ids: number[]) {
|
||||
let items: DailyRMBGiftsItem[] = [];
|
||||
for(let item of this.list) {
|
||||
if(ids.indexOf(item.id) != -1) {
|
||||
item.isReceive = true;
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
this.calButtonStatus();
|
||||
this.calTodayReceiveStatus();
|
||||
return items;
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
{
|
||||
"id": 5,
|
||||
"score": 2500,
|
||||
"reward": "40005&500"
|
||||
"reward": "60004&1"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
|
||||
Reference in New Issue
Block a user