local AppPushGift_Model = {} local EventSystem = require('Event/EventSystem') local private = {} function AppPushGift_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageBuyRecallGift, nil) end function AppPushGift_Model.BuyRecallGiftReq(id) local msg = NetManager.GetPB("recall_gift_opt_pb").BuyRecallGiftReq() msg.id = id NetManager.SendMessage(MessageEnums.MessageBuyRecallGift, msg) end function AppPushGift_Model.UpdateRecallGiftInfo(info) private.RecallGiftInfo = info EventSystem.Dispatch(EventID.UI_AppPushGift_UpdateRecallGiftInfo) private.EndTimeCloseView() end function AppPushGift_Model.GetRecallGiftInfo() return private.RecallGiftInfo end function private.EndTimeCloseView() if private.EndTimeCloseViewTimer == nil then local endTime = private.RecallGiftInfo.endTime - UTL.Time.GetServerTimestamp() private.EndTimeCloseViewTimer = TimerUtil.Interval(function () EventSystem.Dispatch(EventID.UI_AppPushGift_UpdateRecallGiftInfo) end, endTime, 1) end end function AppPushGift_Model.IsOpen() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.AppPushGift) then if private.RecallGiftInfo and private.RecallGiftInfo.endTime > 0 then local serverTime = UTL.Time.GetServerTimestamp() if serverTime < private.RecallGiftInfo.endTime then for _, v in ipairs(private.RecallGiftInfo.info) do if v.state == 0 then TimerUtil.Interval(private.EndTimeCloseView, private.RecallGiftInfo.endTime - serverTime + 1, 1) return true end end end end end return false end function private.EndTimeCloseView() local isOpen = AppPushGift_Model.IsOpen() EventSystem.Dispatch(EventID.FunctionUnlockUpdate, MDL.Unlock.FunctionType.AppPushGift, isOpen) BIManager.DispatchBIClientEvent(BIManager.EventName.AppPushGiftIsOpen, "IsOpen", isOpen) end function AppPushGift_Model.GetGiftState(id) if private.RecallGiftInfo and private.RecallGiftInfo.info then for _, v in ipairs(private.RecallGiftInfo.info) do if v.id == id then return v.state end end end return 0 end function AppPushGift_Model.GetOpenCount() private.openCount = private.openCount or 0 private.openCount = private.openCount + 1 return private.openCount end return AppPushGift_Model