local FreeBuy_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local IAP_SCORE_ID = 30 function FreeBuy_Controller.OnStartup() EventSystem.Regist(EventID.UI_FreeBuy_RefreshRedPoint, private.RefreshRedPoint) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.RefreshInfoByFunction) private.ActivityType = MDL.OperationActivity.ActivityType.FreeBuy end --是否有可返还奖励 function FreeBuy_Controller.IsHasReturnReward() local result = false local allPackageData = MDL.FreeBuy.GetPackageData() --无数据时 if not allPackageData then return false end for i,v in pairs(allPackageData) do if v.data then result = MDL.FreeBuy.IsCanGetReturnPackage(v.activityId,v.data.HotPackageID) if result then return result end end end return result end --当前还有礼包存在 function FreeBuy_Controller.IsHasPackage() local data = MDL.FreeBuy.GetPackageData() if data and next(data) then return true end return false end --获取道具购买礼包的消耗道具和数量 function FreeBuy_Controller.GetPackageItemCost(data) local giftData = MDL.OperationActivity.CommonGiftReward:GetDataByID(data.GiftID) if giftData.GoldIngot and giftData.GoldIngot > 0 then return giftData.GoldIngot, MDL.Currency.CurrencyType.GoldIngot elseif giftData.DragonJade and giftData.DragonJade > 0 then return giftData.DragonJade, MDL.Currency.CurrencyType.DragonJade end end --是否是道具购买礼包 function FreeBuy_Controller.IsItemBuyGift(giftID) local giftData = MDL.OperationActivity.CommonGiftReward:GetDataByID(giftID) if not string.isNilOrEmpty(giftData.IapID) then return false end if giftData.GoldIngot and giftData.GoldIngot > 0 then return true elseif giftData.DragonJade and giftData.DragonJade > 0 then return true end return false end function FreeBuy_Controller.GetIapIndex(iapId) for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapId then return v.Index end end end --获取充值积分 function FreeBuy_Controller.GetBuyScore(iapId) for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapId then for _, item in ipairs (v.Item_Condition_Table) do if item.GetID == IAP_SCORE_ID then return item.GetAmount end end break end end return -1 end --获取购买后的返还天数 function FreeBuy_Controller.GetReturnDayAfterBuy(activityID,hotPackageID) local data = MDL.FreeBuy.GetDataByActivityIDAndPackageID(activityID,hotPackageID) if data then return data.data.PayBackTime / 24 end return -1 end --是否显示入口 function FreeBuy_Controller.IsCanShowEntrance() return CTL.OperationActivity.IsOperationActivityTypeOpen(private.ActivityType) and CTL.OperationActivity.IsOperationActivityTypeUnlock(private.ActivityType) and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FreeBuy) and FreeBuy_Controller.IsHasPackage() end --获取购买礼包剩余时间 function FreeBuy_Controller.GetBuyRemainTime(activityID,hotPackageID) local data = MDL.FreeBuy.GetDataByActivityIDAndPackageID(activityID,hotPackageID) if data then local buyTime = data.info.endTime local nowTime = UTL.Time.GetServerTimestamp() return buyTime - nowTime end return -1 end --获取购买礼包还有多少时间开始 function FreeBuy_Controller.GetToBuyTime(activityID,hotPackageID) local data = MDL.FreeBuy.GetLockedDataByActivityIDAndPackageID(activityID,hotPackageID) if data then local startTime = data.info.startTime local nowTime = UTL.Time.GetServerTimestamp() return startTime - nowTime end return -1 end --获取返还礼包剩余时间 function FreeBuy_Controller.GetReturnRemainTime(activityID,hotPackageID) local returnTime = MDL.FreeBuy.GetReturnTime(activityID,hotPackageID) local nowTime = UTL.Time.GetServerTimestamp() return returnTime - nowTime end function private.RefreshRedPoint() if FreeBuy_Controller.IsHasReturnReward() or MDL.FreeBuy.AnyFirstShowRP() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.FreeBuy_HasReward) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FreeBuy_HasReward) end end function private.RefreshInfoByFunction(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.FreeBuy then if not isUnlock then FreeBuy_Controller.EndAndCloseActivity() end end end --添加礼包返还刷新 function FreeBuy_Controller.AddGiftPayBackTimer(activityID,hotPackageID) if not private.payBackTimerHandle then private.payBackTimerHandle = {} end --已有的定时器跳过 if private.payBackTimerHandle[activityID] and private.payBackTimerHandle[activityID][hotPackageID] then return end --判断可返还,可返还的添加返还定时器 local nowTime = UTL.Time.GetServerTimestamp() local returnTime = MDL.FreeBuy.GetReturnTime(activityID,hotPackageID) if returnTime and returnTime > 0 and returnTime > nowTime then local deltaTime = returnTime - nowTime + 10 --延后10s 刷新 --返回之前的时间才执行定时器 if deltaTime < 0 then return end --logging.error(LTAG.ERROR,"SetTimer") local timeHandle = TimerUtil.Interval(FreeBuy_Controller.RefreshTimer, deltaTime, 1) if not private.payBackTimerHandle[activityID] then private.payBackTimerHandle[activityID] = {} end private.payBackTimerHandle[activityID][hotPackageID] = timeHandle end end --刷新所有礼包返还定时器 function FreeBuy_Controller.RefreshAllGiftPayBackTimer() local packageData = MDL.FreeBuy.GetPackageData() if not packageData then return end for i,v in pairs(packageData) do local nowTime = UTL.Time.GetServerTimestamp() if v.info.backTime > 0 and v.info.backTime > nowTime then FreeBuy_Controller.AddGiftPayBackTimer(v.activityId,v.data.HotPackageID) else FreeBuy_Controller.RemoveGiftPayBackTimer(v.activityId,v.data.HotPackageID) end end end --移除礼包返还刷新 function FreeBuy_Controller.RemoveGiftPayBackTimer(activityID,hotPackageID) if private.payBackTimerHandle and private.payBackTimerHandle[activityID] and private.payBackTimerHandle[activityID][hotPackageID] then TimerUtil.Remove(private.payBackTimerHandle[activityID][hotPackageID]) private.payBackTimerHandle[activityID][hotPackageID] = nil end end --礼包更新时刷新 function FreeBuy_Controller.RefreshTimer() --logging.error(LTAG.ERROR,"FreeBuy_Controller.RefreshTimer") if FreeBuy_Controller.IsHasPackage() then EventSystem.Dispatch(EventID.UI_FreeBuy_RefreshRedPoint) EventSystem.Dispatch(EventID.UI_FreeBuy_RefreshUI) else --没有礼包时关闭活动 FreeBuy_Controller.EndAndCloseActivity() end end function FreeBuy_Controller.EndAndCloseActivity() UIManager.CloseView(Const_UI_Lua.UIEnum.UIPreviewItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.OperationActivity.UIFreeBuy) end return FreeBuy_Controller