local DailyGift_Model = {} local private = {} local daily_gift_pb = require("Proto/daily_gift_pb") local EventSystem = require('Event/EventSystem') DailyGift_Model.DailyGiftState = { UnBuy = 0, --未购买 UnGet = 1, --已购买未领取 HasGet = 2, --已领取 } function DailyGift_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageReceiveDailyGift, private.OnDailyGiftResp) NetManager.RegisterMsgCB(MessageEnums.MessageDailyGiftWelfare, private.OnDailyGiftWelfareResp) end function DailyGift_Model.SyncDailyGiftInfo(info) private.dailyGiftInfo = info EventSystem.Dispatch(EventID.UI_DailyGift_Refresh) end function DailyGift_Model.GetDailyGiftInfo() return private.dailyGiftInfo end --套票是否已结束 function DailyGift_Model.GetSumGiftEndDay() if private.dailyGiftInfo then return private.dailyGiftInfo.receiveDayNum end return 0 end function DailyGift_Model.DailyGiftReq(giftType) local msg = daily_gift_pb.ReceiveDailyGiftReq() msg.giftType = giftType NetManager.SendMessage(MessageEnums.MessageReceiveDailyGift, msg) end function private.OnDailyGiftResp(msgResp) logging.log(LTAG.LOG, "DailyGiftResp") end function DailyGift_Model.DailyGiftWelfareReq() local msg = daily_gift_pb.DailyGiftWelfareReq() NetManager.SendMessage(MessageEnums.MessageDailyGiftWelfare, msg) end function private.OnDailyGiftWelfareResp(msgResp) logging.log(LTAG.LOG, "DailyGiftWelfareResp") end --获取礼包状态 function DailyGift_Model.GetGiftState(giftType) if private.dailyGiftInfo then local gifts = private.dailyGiftInfo.gifts for _, v in ipairs(gifts) do if v.giftType == giftType then if v.receiveGiftId == 0 then return DailyGift_Model.DailyGiftState.UnGet else return DailyGift_Model.DailyGiftState.HasGet, v.receiveGiftId end end end end return DailyGift_Model.DailyGiftState.UnBuy end --获取明日福利奖励 function DailyGift_Model.GetTomorrowWelfareReward() if private.dailyGiftInfo then if private.dailyGiftInfo.receiveDayNum > 0 then local maxId = 0 for i, v in DataSheetManager.DailyGiftPreview:GetEnumerator() do if v.ID > maxId then maxId = v.ID end end local reward = DataSheetManager.DailyGiftPreview:GetDataByID(maxId).Reward return DataSheetManager.DailyGiftReward:GetDataByID(reward).Item_Table end local giftCount = #private.dailyGiftInfo.gifts for _, v in DataSheetManager.DailyGiftPreview:GetEnumerator() do if #v.Money == giftCount then local flag = true for i, money in ipairs(v.Money) do local state = DailyGift_Model.GetGiftState(money) if state == DailyGift_Model.DailyGiftState.UnBuy then flag = false break end end if flag then local reward = v.Reward return DataSheetManager.DailyGiftReward:GetDataByID(reward).Item_Table end end end end local reward = DataSheetManager.DailyGiftPreview:GetDataByID(1).Reward return DataSheetManager.DailyGiftReward:GetDataByID(reward).Item_Table end --今日福利奖励 function DailyGift_Model.GetTodayWelfareReward() if private.dailyGiftInfo then local data = DataSheetManager.DailyGiftPreview:GetDataByID(private.dailyGiftInfo.welfareId) if data then local reward = data.Reward return DataSheetManager.DailyGiftReward:GetDataByID(reward).Item_Table end end local reward = DataSheetManager.DailyGiftPreview:GetDataByID(1).Reward return DataSheetManager.DailyGiftReward:GetDataByID(reward).Item_Table end --获取已购总金额 function DailyGift_Model.GetBuySum() if private.dailyGiftInfo then if private.dailyGiftInfo.receiveDayNum > 0 then local curIAP = DataSheetManager.ConstData:GetDataByID("DailyGiftCurrentPrice").IntValue return MDL.Currency.GetFullyIAPPrice(curIAP) end local sum = 0 local gifts = private.dailyGiftInfo.gifts for _, v in ipairs(gifts) do local price = MDL.Currency.GetIAPPriceNum(v.giftType) sum = sum + price end if sum == 0 then return nil end return MDL.Currency.FormatPriceNum(sum) end return nil end return DailyGift_Model