活动:修复每日特惠礼包
This commit is contained in:
@@ -42,9 +42,8 @@ export class ActivityHandler {
|
||||
let activityData = await getActivityById(activityId);
|
||||
if (activityData) {
|
||||
let playerActivityData = await getActivity(serverId, roleId, activityId, activityData.type);
|
||||
console.log('******', !!playerActivityData, activityId, activityData.type)
|
||||
if(playerActivityData && playerActivityData.beginTime <= Date.now() && playerActivityData.endTime >= Date.now()) {
|
||||
if (playerActivityData) playerGroupActivityArray.push(playerActivityData);
|
||||
playerGroupActivityArray.push(playerActivityData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ export class DailyRMBGiftsHandler {
|
||||
if (item.isReceive) {
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
if (item.price > 0) {
|
||||
if (!playerData.isBuy && item.price > 0) {
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.DAILY_RMB_GIFT)
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), [item.id]);
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex, [item.id]);
|
||||
item.isReceive = true;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, id },
|
||||
@@ -89,7 +89,7 @@ export class DailyRMBGiftsHandler {
|
||||
item.isReceive = true;
|
||||
}
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardArray, ITEM_CHANGE_REASON.DAILY_RMB_GIFT)
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), ids);
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex, ids);
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId },
|
||||
items: items
|
||||
|
||||
@@ -66,14 +66,14 @@ export async function getActivity(serverId: number, roleId: string, activityId:
|
||||
{
|
||||
let data = await getPlayerThirtyDaysData(activityId, serverId, roleId);
|
||||
let todayIndex = await playerThirtyDaysActivityDays(roleId);
|
||||
activityData = { playerData: data, todayIndex }
|
||||
activityData = { playerData: data, todayIndex, beginTime: data.beginTime, endTime: data.endTime }
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.SELF_SERVICE_SHOP://自选商店 糜家商队 13
|
||||
{
|
||||
let data = await getPlayerActivityData(activityId, serverId, roleId);
|
||||
let playerGoods = await ActivitySelfServiceGoodsModel.findData(activityId, roleId, data.roundIndex, true);
|
||||
activityData = { playerData: data, playerGoods: playerGoods ? playerGoods : [] }
|
||||
activityData = { playerData: data, playerGoods: playerGoods ? playerGoods : [], beginTime: data.beginTime, endTime: data.endTime }
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.FIRST_GIFT://首冲礼包活动 14
|
||||
|
||||
@@ -50,8 +50,8 @@ export async function getPlayerDailyRMBGiftsData(activityId: number, serverId: n
|
||||
// buyTime = playerOrders[0].createdAt;//购买时候的日期
|
||||
// endTime = moment(buyTime).add(7, 'd').endOf('d').toDate()
|
||||
// }
|
||||
let playerRecord: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate());
|
||||
let unReceiveRecord: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.findBuyRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate());
|
||||
let playerRecord: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex);
|
||||
let unReceiveRecord: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.findBuyRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex);
|
||||
|
||||
playerData.setPlayerRecords(playerRecord, unReceiveRecord.length);
|
||||
return playerData;
|
||||
@@ -78,14 +78,14 @@ export async function makeDailyRMBGiftsReward(roleId: string, roleName: string,
|
||||
let playerData = new DailyRMBGiftsData(activityData, createTime);
|
||||
let bigGiftProductID = playerData.productID;
|
||||
if (bigGiftProductID == productID) {//一次性购买7天礼包
|
||||
let playerRecord: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate());
|
||||
let playerRecord: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex);
|
||||
if (playerRecord && playerRecord.records && playerRecord.records.length > 0) {//今天已经购买过其他奖励
|
||||
playerData.beginTime += 24 * 60 * 60 * 1000;
|
||||
playerData.todayIndex ++;
|
||||
}
|
||||
|
||||
for (let i = 0; i < playerData.day; i++) {
|
||||
let beginTime = playerData.beginTime + 24 * 60 * 60 * 1000 * i;
|
||||
await ActivityDailyRMBGiftsModel.buyRecord(serverId, activityId, roleId, moment(beginTime).toDate(), true);
|
||||
let todayIndex = playerData.todayIndex + i;
|
||||
await ActivityDailyRMBGiftsModel.buyRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), todayIndex, true);
|
||||
}
|
||||
let endTime = moment(playerData.endTime).add(playerData.day, 'd').toDate()
|
||||
return {
|
||||
@@ -101,7 +101,7 @@ export async function makeDailyRMBGiftsReward(roleId: string, roleName: string,
|
||||
}
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.DAILY_RMB_GIFT)
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), [item.id]);
|
||||
await ActivityDailyRMBGiftsModel.receiveRecord(serverId, activityId, roleId, moment(playerData.beginTime).toDate(), playerData.todayIndex, [item.id]);
|
||||
item.isReceive = true;
|
||||
return {
|
||||
code: 0,
|
||||
|
||||
@@ -411,7 +411,7 @@ export const STATUS = {
|
||||
ACTIVITY_SIGNIN_VIP_CONDITION: { code: 50020, simStr: '开启条件不足' },
|
||||
ACTIVITY_SIGNIN_EXPIRE: { code: 50021, simStr: '签到过期,补签' },
|
||||
ACTIVITY_POP_UP_SHOP_EXPIRE: { code: 50022, simStr: '弹出商店过期' },
|
||||
ACTIVITY_NEED_PAY: { code: 50023, simStr: '客户端调错接口了' },
|
||||
ACTIVITY_NEED_PAY: { code: 50023, simStr: '该商品未购买,不可领取' },
|
||||
ACTIVITY_GOLD_RESOURCE: { code: 50024, simStr: '元宝资源' },
|
||||
ACTIVITY_ID_ERROR: { code: 50025, simStr: 'id错误' },
|
||||
ACTIVITY_NEW_PLAYER_GIFT_END: { code: 50026, simStr: '新手活动结束' },
|
||||
|
||||
@@ -30,12 +30,14 @@ export default class Activity_Daily_RMB_Gifts extends BaseModel {
|
||||
@prop({ required: true })
|
||||
beginTime: Date; // 开始时间
|
||||
@prop({ required: true })
|
||||
todayIndex: number; // 开始时间
|
||||
@prop({ required: true })
|
||||
isBuy: boolean; // 是否已经购买过
|
||||
@prop({ required: true })
|
||||
records: BuyRecord[]; // 领取记录
|
||||
|
||||
//添加领取记录
|
||||
public static async receiveRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, ids: number[]) {
|
||||
public static async receiveRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, todayIndex: number, ids: number[]) {
|
||||
let data = [];
|
||||
for (let id of ids) {
|
||||
data.push({
|
||||
@@ -44,30 +46,30 @@ export default class Activity_Daily_RMB_Gifts extends BaseModel {
|
||||
})
|
||||
}
|
||||
let result = await ActivityDailyRMBGiftsModel.findOneAndUpdate(
|
||||
{ serverId, roleId, activityId, beginTime }, { $push: { records: { $each: data } } }, { upsert: true, new: true }
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex }, { $push: { records: { $each: data } } }, { upsert: true, new: true }
|
||||
).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
//添加购买记录
|
||||
public static async buyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, isBuy: boolean) {
|
||||
public static async buyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, todayIndex: number, isBuy: boolean) {
|
||||
let result = await ActivityDailyRMBGiftsModel.findOneAndUpdate(
|
||||
{ serverId, roleId, activityId, beginTime }, { $set: { isBuy } }, { upsert: true, new: true }
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex }, { $set: { isBuy } }, { upsert: true, new: true }
|
||||
).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
//历史领取的记录
|
||||
public static async findRecord(serverId: number, activityId: number, roleId: string, beginTime: Date) {
|
||||
public static async findRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, todayIndex: number) {
|
||||
let result: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findOne(
|
||||
{ serverId, roleId, activityId, beginTime }).lean(true);
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//获取已经购买还没有领取的数据
|
||||
public static async findBuyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date) {
|
||||
public static async findBuyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, todayIndex: number) {
|
||||
let result: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.find(
|
||||
{ serverId, roleId, activityId, beginTime: { $gt: beginTime } }).lean(true);
|
||||
{ serverId, roleId, activityId, beginTime, todayIndex: { $gt: todayIndex } }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ export abstract class ActivityBase {
|
||||
this.nextRefreshTime = this.endTime;
|
||||
|
||||
this.type = activityData.type;
|
||||
// console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
|
||||
// console.log('***** activityData', activityData.timeType)
|
||||
console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
|
||||
console.log('***** activityData', activityData.timeType)
|
||||
switch (activityData.timeType) {
|
||||
case ACTIVITY_TIME_TYPE.SERVER_OPEN_TIME: {
|
||||
this.beginTime = moment(SERVER_OPEN_TIME).add(this.delayDay, 'd').startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
@@ -43,7 +43,7 @@ export abstract class ActivityBase {
|
||||
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
|
||||
}
|
||||
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
|
||||
// console.log('活动时间数据11...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
console.log('活动时间数据11...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TIME_TYPE.ROLE_REGISTER_TIME: {
|
||||
@@ -55,11 +55,11 @@ export abstract class ActivityBase {
|
||||
}
|
||||
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
|
||||
|
||||
// console.log('活动时间数据22...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
console.log('活动时间数据22...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TIME_TYPE.DATE_TIME: {
|
||||
// console.log('活动时间数据33...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
console.log('活动时间数据33...', activityData.timeType, this.beginTime, this.endTime, this.todayIndex, this.roundIndex, this.nextRefreshTime)
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -71,9 +71,9 @@ export abstract class ActivityBase {
|
||||
this.nextRefreshTime = moment(this.beginTime).add(activityData.interval * this.roundIndex, 'second').valueOf();
|
||||
this.todayIndex = Math.ceil(((moment(new Date).valueOf() - this.beginTime) / (24 * 60 * 60 * 1000)));
|
||||
}
|
||||
// console.log('活动时间数据...', '活动id:', activityData.activityId, '类型:', activityData.timeType, '开始时间:', this.beginTime, moment(this.beginTime).toDate(),
|
||||
// '结束:', this.endTime, moment(this.endTime).toDate(),
|
||||
// '今天第几天:', this.todayIndex, '回合:', this.roundIndex, '下次刷新:', this.nextRefreshTime, moment(this.nextRefreshTime).toDate())
|
||||
console.log('活动时间数据...', '活动id:', activityData.activityId, '类型:', activityData.timeType, '开始时间:', this.beginTime, moment(this.beginTime).toDate(),
|
||||
'结束:', this.endTime, moment(this.endTime).toDate(),
|
||||
'今天第几天:', this.todayIndex, '回合:', this.roundIndex, '下次刷新:', this.nextRefreshTime, moment(this.nextRefreshTime).toDate())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export class LimitShopData extends ActivityBase {
|
||||
name: string = '';//活动名称
|
||||
interval: number = 0;//周期间隔(秒)
|
||||
list: Array<ShopItem> = [];//商品列表
|
||||
nextRefreshTime: number;//下次刷新时间
|
||||
// nextRefreshTime: number;//下次刷新时间
|
||||
roundIndex: number = 1;//周期数从1开始
|
||||
|
||||
public findItemByProductID(productID: string) {
|
||||
@@ -73,7 +73,7 @@ export class LimitShopData extends ActivityBase {
|
||||
|
||||
|
||||
public initData(data: string) {
|
||||
this.nextRefreshTime = this.endTime;
|
||||
// this.nextRefreshTime = this.endTime;
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.interval = dataObj.interval;
|
||||
|
||||
@@ -151,7 +151,7 @@ export class RefreshShopData extends ActivityBase {
|
||||
|
||||
|
||||
public initData(data: string) {
|
||||
this.nextRefreshTime = this.endTime;
|
||||
// this.nextRefreshTime = this.endTime;
|
||||
let dataObj = JSON.parse(data);
|
||||
this.shopType = dataObj.shopType;
|
||||
this.name = dataObj.name;
|
||||
|
||||
@@ -56,7 +56,7 @@ export class RefreshTaskData extends ActivityBase {
|
||||
name: string = '';//活动名称
|
||||
interval: number = 0;//周期间隔(秒)
|
||||
list: Array<RefreshTaskPage> = [];
|
||||
nextRefreshTime: number;//下次刷新时间
|
||||
// nextRefreshTime: number;//下次刷新时间
|
||||
roundIndex: number = 1;//周期数从1开始
|
||||
addPointActivityId: number = 0;//获得的点数,关联其他活动id(新将礼物)
|
||||
|
||||
@@ -106,7 +106,7 @@ export class RefreshTaskData extends ActivityBase {
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
this.nextRefreshTime = this.endTime;
|
||||
// this.nextRefreshTime = this.endTime;
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.interval = dataObj.interval;
|
||||
|
||||
Reference in New Issue
Block a user