local TestingGift_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local bind_account_pb = require("Proto/bind_account_pb") local LuaFuncEntry = require("Main/LuaFuncEntry") private.isInit = false TestingGift_Model.ActivityID = { Questionnaire = 7, FaceBookFan = 8, StoreScore = 9, BindAccount = 10, } TestingGift_Model.RedPointKey = { [TestingGift_Model.ActivityID.FaceBookFan] = CTL.RedPoint.RedPointKey.TestingGift_FaceBook, [TestingGift_Model.ActivityID.StoreScore] = CTL.RedPoint.RedPointKey.TestingGift_StoreScore, [TestingGift_Model.ActivityID.BindAccount] = CTL.RedPoint.RedPointKey.TestingGift_BindAccount, } private.hasAwardActivity = {} private.hasClickRedActivity = {} function TestingGift_Model.OnStartup() private.SetupEntryFunc(true) NetManager.RegisterMsgCB(MessageEnums.MessageHWActivityGetInfo, private.OnHWActivityGetInfoResp) NetManager.RegisterMsgCB(MessageEnums.MessageHWActivityReward, private.OnHWActivityRewardResp) EventSystem.Regist(EventID.New_Day_Refresh, private.OnNewDayRefresh) EventSystem.Regist(EventID.UI_SDKUser_Unlock_Update, TestingGift_Model.RefreshRedPoint) end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.OnUpdateSDKUserInfo, private.UpdateSDKUserInfo) end function private.UpdateSDKUserInfo() if SDKUtil.CurrentUserInfo.IsRelated then TestingGift_Model.HWActivityRewardReq(MDL.TestingGift.ActivityID.BindAccount) end end function TestingGift_Model.OnShutdown() private.SetupEntryFunc(false) end function TestingGift_Model.HWActivityGetInfoReq() local msg = bind_account_pb.HWActivityGetInfoReq() NetManager.SendMessage(MessageEnums.MessageHWActivityGetInfo, msg) end function private.OnHWActivityGetInfoResp(msgResp) if msgResp.Resp.Code == 0 then for _,v in ipairs(msgResp.activeIds) do private.hasAwardActivity[v] = true end end --没领过奖励且已经绑定账号直接给奖励 if private.hasAwardActivity[TestingGift_Model.ActivityID.BindAccount] ~= true and SDKUtil.CurrentUserInfo.IsRelated == true then TestingGift_Model.HWActivityRewardReq(TestingGift_Model.ActivityID.BindAccount) end --红点 TestingGift_Model.RefreshRedPoint() end function private.OnNewDayRefresh() table.clear(private.hasClickRedActivity) TestingGift_Model.RefreshRedPoint() end function private.UpdateTestingGiftRed() for _,redKey in pairs(TestingGift_Model.RedPointKey) do CTL.RedPoint.RemoveRedPoint(redKey) end for i, v in DataSheetManager.Welfare:GetEnumerator() do --有页签且奖励未领的情况下显示红点 TestingGift_Model.SetSubTabRed(v) end EventSystem.Dispatch(EventID.UI_WelfareBase_BindAccountRefreshRed) end --forceRemove:点击页签直接去掉红点 function TestingGift_Model.SetSubTabRed(data, forceRemove) local id = data.ID local redKey = TestingGift_Model.RedPointKey[id] if redKey then if forceRemove then CTL.RedPoint.RemoveRedPoint(redKey) private.hasClickRedActivity[id] = true MDL.RedPoint.OneTimeRedPointRequest(TestingGift_Model.GetRedIDByTestGiftRId(id), 1, true, nil) else if TestingGift_Model.HasClaimReward(id) ~= true and CTL.TestingGift.CheckTabShow(data) and private.hasClickRedActivity[id] ~= true then CTL.RedPoint.AddRedPoint(redKey) else CTL.RedPoint.RemoveRedPoint(redKey) end end end end function TestingGift_Model.HWActivityRewardReq(id) if private.hasAwardActivity[id] then return end local msg = bind_account_pb.HWActivityRewardReq() msg.activeId = id NetManager.SendMessage(MessageEnums.MessageHWActivityReward, msg) end function private.OnHWActivityRewardResp(msgResp) if msgResp.Resp.Code == 0 then private.hasAwardActivity[msgResp.activeId] = true local data = DataSheetManager.Welfare:GetDataByID(msgResp.activeId) TestingGift_Model.SetSubTabRed(data) EventSystem.Dispatch(EventID.UI_TestingGift_GetReward) end end function TestingGift_Model.HasClaimReward(activeId) return private.hasAwardActivity[activeId] end function TestingGift_Model.GetRedIDByTestGiftRId(id) if id == TestingGift_Model.ActivityID.FaceBookFan then return MDL.RedPoint.RedPointType.TestingGift_FaceBook elseif id == TestingGift_Model.ActivityID.StoreScore then return MDL.RedPoint.RedPointType.TestingGift_StoreScore elseif id == TestingGift_Model.ActivityID.BindAccount then return MDL.RedPoint.RedPointType.TestingGift_BindAccount end end function TestingGift_Model.RefreshRedPoint() local time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.TestingGift_FaceBook) if time and time > 0 and not UTL.Time.IsTimestampCrossDay(time) then private.hasClickRedActivity[TestingGift_Model.ActivityID.FaceBookFan] = true else private.hasClickRedActivity[TestingGift_Model.ActivityID.FaceBookFan] = false end time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.TestingGift_StoreScore) if time and time > 0 and not UTL.Time.IsTimestampCrossDay(time) then private.hasClickRedActivity[TestingGift_Model.ActivityID.StoreScore] = true else private.hasClickRedActivity[TestingGift_Model.ActivityID.StoreScore] = false end time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.TestingGift_BindAccount) if time and time > 0 and not UTL.Time.IsTimestampCrossDay(time) then private.hasClickRedActivity[TestingGift_Model.ActivityID.BindAccount] = true else private.hasClickRedActivity[TestingGift_Model.ActivityID.BindAccount] = false end private.UpdateTestingGiftRed() end return TestingGift_Model