AdvertisementModel = AdvertisementModel or BaseClass(BaseVo, true) local AdvertisementModel = AdvertisementModel AdvertisementModel.OPEN_ADVERTISEMENT_VIEW = "AdvertisementModel.OPEN_ADVERTISEMENT_VIEW" AdvertisementModel.CLOSE_ADVERTISEMENT_VIEW = "AdvertisementModel.CLOSE_ADVERTISEMENT_VIEW" -- 广告宣传图类型 AdvertisementModel.AD_TYPE = { LOGIN = "login", -- 有跳转按钮 INSIDE = "inside", -- 无跳转按钮 隔几秒自动关闭 } -- 与广告宣传图冲突的界面 AdvertisementModel.CONFLICT_VIEW = { BEACH = "BEACH", } function AdvertisementModel:__init() AdvertisementModel.Instance = self self:Reset() end function AdvertisementModel:Reset() self.advertisement_data = {} self.ad_cookie = {} self.conflict_view_list = {} self.scene_is_load = false end function AdvertisementModel.getInstance() if AdvertisementModel.Instance == nil then AdvertisementModel.Instance = AdvertisementModel.New() end return AdvertisementModel.Instance end --[[ { condition_list = table: 0x1b873c50 { 1 = table: 0x1b823c78 { 1 = open_lv 2 = 315 } 2 = table: 0x1b873c78 { 1 = adpic 2 = 1 } 3 = table: 0x1b873ce0 { 1 = login 2 = table: 0x1b873d28 { 1 = 331 2 = 70 } } } stime = 1597248000 base_type = 73 sub_type = 101 etime = 1597939199 desc = 限时活动 condition = [{adpic,1},{login,{331,70}}] is_first_open = 0 wlv = 335 name = 活动广告图 act_type = 3 } --]] -- 检查是否需要展示登陆活动广告 function AdvertisementModel:CheckAdNeedShow( vo ) local server_time = TimeUtil:getServerTime() local cur_lv = RoleManager.Instance.mainRoleInfo.level local need_lv = tonumber(vo.condition_list[1][2]) if server_time > vo.stime and vo.etime > server_time and need_lv <= cur_lv then self:SetAdvertisementData(vo) if self.advertisement_data[vo.sub_type].ad_tpye == AdvertisementModel.AD_TYPE.LOGIN and self:TodayIsFirstShow( vo.sub_type ) then if self:CheckViewIsConflict() then -- 如果有互斥界面已经打开了 本次就不弹出了 return end -- self.ad_cookie[vo.sub_type] = false -- self:SetADCookie() self:Fire(AdvertisementModel.OPEN_ADVERTISEMENT_VIEW, vo.sub_type) end end end -- 打开运营活动界面后 检查是否需要展示活动广告 function AdvertisementModel:CheckAndShowActivityAd( base_type ) if not base_type then return end for ad_sub_type, data in pairs(self.advertisement_data) do if data.ad_tpye == AdvertisementModel.AD_TYPE.INSIDE and tonumber(data.module_data[2]) == base_type and self:TodayIsFirstShow( ad_sub_type ) then self.ad_cookie[ad_sub_type] = false self:SetADCookie() self:Fire(AdvertisementModel.OPEN_ADVERTISEMENT_VIEW, ad_sub_type) break end end end -- 检查是否可以开始检查 function AdvertisementModel:CheckAd( vo ) if self.scene_is_load then self.need_login_check = false self:CheckAdNeedShow(vo) else self.need_login_check = true self.temp_vo_list = self.temp_vo_list or {} table.insert(self.temp_vo_list, vo) end end -- 设置登陆状态 function AdvertisementModel:SetSceneLoadState( ) self.scene_is_load = true self:LoadADCookie() self:UpdateCookie() if self.need_login_check then self.need_login_check = false for i,v in ipairs(self.temp_vo_list) do self:CheckAdNeedShow( v ) end self.temp_vo_list = nil end end -- 保存活动宣传图的数据 function AdvertisementModel:SetAdvertisementData( vo ) self.advertisement_data[vo.sub_type] = vo local temp = self.advertisement_data[vo.sub_type] temp.open_lv = vo.condition_list[1][2] temp.ad_tpye = vo.condition_list[3][1] temp.module_data = vo.condition_list[3][2] temp.ad_pic = Trim( "ad_pic" .. tostring(vo.condition_list[2][2]) ) end function AdvertisementModel:GetAdvertisementData( sub_type ) assert(self.advertisement_data[sub_type], "not data!") return self.advertisement_data[sub_type] end function AdvertisementModel:TodayIsFirstShow( sub_type ) if self.ad_cookie[sub_type] == nil then self.ad_cookie[sub_type] = true end return self.ad_cookie[sub_type] end function AdvertisementModel:SetSubTypeCookie( sub_type, bool ) self.ad_cookie[sub_type] = bool self:SetADCookie() end -- cookie操作 --设置宣传图cookie function AdvertisementModel:SetADCookie() CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.ADVERTISEMENT_SHOW, self.ad_cookie) CookieWrapper.Instance:WriteAll() end --获取宣传图cookie function AdvertisementModel:LoadADCookie() local temp = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.ADVERTISEMENT_SHOW) self.ad_cookie = temp or {} end function AdvertisementModel:UpdateCookie( ) if NewMainRoleModel:getInstance():IsTodayFirstLogin() then self.ad_cookie = {} self:SetADCookie() end end function AdvertisementModel:ResetCookieBySubType( sub_type ) self.ad_cookie[sub_type] = true self:SetADCookie() end -- 设置互斥界面的开启状态 如果有互斥界面打开了, 触发关闭广告的事件 function AdvertisementModel:AddConflictViewState( conflict_view, is_open ) self.conflict_view_list = self.conflict_view_list or {} self.conflict_view_list[conflict_view] = is_open if is_open then self:Fire(AdvertisementModel.CLOSE_ADVERTISEMENT_VIEW) end end -- 检查是否有互斥的界面正在显示 function AdvertisementModel:CheckViewIsConflict( ) for k,v in pairs(self.conflict_view_list) do if v then return true end end return false end