| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- local RemoteProxy = requireProxy( "remote/RemoteProxy" )
- local InformationProxy = class( "InformationProxy", RemoteProxy )
- InformationProxy.NAME = global.ProxyTable.InformationProxy
- function InformationProxy:ctor()
- InformationProxy.super.ctor( self )
- self._config = {}
- self._day_count = {}
- self._pay_day_count = {} --充值信息
- self._curr_day = 1
- self._pay_curr_day = 1 --当前数组的天数
- self._select_day = {} --记录本地已选择的天数
- self:LoadConfig()
- end
- function InformationProxy:LoadConfig()
- local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
- local fileName = "cfg_information.lua"
-
- if global.FileUtilCtl:isFileExist("scripts/game_config/" .. fileName) then
- self._config = requireGameConfig("cfg_information")
- end
- self._select_day = self:GetSelecDaykData()
- end
- function InformationProxy:GetConfig()
- return self._config
- end
- function InformationProxy:GetConfigByID( id )
- if not id then
- return {}
- end
- return self._config[id] or {}
- end
- function InformationProxy:GetDayByID( id )
- if not id then
- return 7
- end
- return self._select_day[id] or 7
- end
- function InformationProxy:SetDayByID( id,day )
- if not id or not day then
- return
- end
- self._select_day[id] = day
- self:SetSelecDaykData()
- end
- function InformationProxy:GetDayMath( day )
- if not day then
- return ""
- end
- local ret = ""
- if day >= 365 then
- ret = string.format( GET_STRING(310000308), math.floor(day/365) )
- elseif day >= 30 then
- ret = string.format( GET_STRING(310000307), math.floor(day/30) )
- elseif day > 0 then
- ret = string.format( GET_STRING(310000306), day )
- end
- return ret
- end
- function InformationProxy:GetInformationCount( day,id )
- if not day then
- return 0
- end
- local count = 0
- local offDay = 0
-
- local currDay = 1
- local dayCount = {}
- if id == 4 then --充值信息单独获取
- dayCount = self._pay_day_count
- currDay = self._pay_curr_day
- else
- dayCount = self._day_count
- currDay = self._curr_day
- end
-
- for i=1,day do
- local index = currDay - i + offDay + 1
- if index == 0 then
- index = 365
- offDay = 365
- end
- count = count + (dayCount[index] or 0)
- end
- return count
- end
- function InformationProxy:PareseInformationName( id )
- if not id then
- return {}
- end
- local config = self:GetConfigByID( id )
- local array1 = string.split( config.page2name or "", "#" )
- local array2 = string.split( config.page3name or "", "#" )
-
- local array = {}
- for i,v in ipairs(array1) do
- array[i] = {
- name = array1[i] or "",
- txtStr = array2[i] or ""
- }
- end
- return array
- end
- function InformationProxy:SetDayCountData( str )
- self._day_count = {}
- local array = string.split( str or "", ";" )
- for i,v in ipairs( array ) do
- if v and v ~= "" then
- local arry1 = string.split(v,"=")
- local day = tonumber(arry1[1]) or 0
- local count = tonumber(arry1[2]) or 0
- self._day_count[day] = count
- end
- end
- end
- function InformationProxy:SetPayDayCountData( str )
- self._pay_day_count = {}
- local array = string.split( str or "", ";" )
- for i,v in ipairs( array ) do
- if v and v ~= "" then
- local arry1 = string.split(v,"=")
- local day = tonumber(arry1[1]) or 0
- local count = tonumber(arry1[2]) or 0
- self._pay_day_count[day] = count
- end
- end
- end
- -- 本地缓存数据
- function InformationProxy:GetSelecDaykData()
- local PosData = UserData:new("InformationData")
- local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
- local flag = proxy:GetSelectedRoleID() or "errorName"
- local clientData = PosData:getStringForKey( "information"..flag )
-
- if not clientData or clientData == "" then
- return {}
- end
- local cjson = require( "cjson" )
- local lastJsonData = cjson.decode(clientData)
- return lastJsonData
- end
-
- function InformationProxy:SetSelecDaykData()
-
- local PosData = UserData:new("InformationData")
- local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
- local flag = proxy:GetSelectedRoleID() or "errorName"
- local cjson = require( "cjson" )
- local selectDayData = cjson.encode(self._select_day)
- local clientData = PosData:setStringForKey( "information"..flag, selectDayData )
-
- end
- -- 收集个人信息
- function InformationProxy:handle_MSG_SC_GET_INFORMATION_RESPON( msg )
- local msgLen = msg:GetDataLength()
- local msgHdr = msg:GetHeader()
- local dataString = msg:GetData():ReadString(msgLen)
- self._curr_day = msgHdr.recog
- self:SetDayCountData( dataString )
- end
- -- 收集个人充值信息
- function InformationProxy:handle_MSG_SC_GET_EVERYDAY_CHARGE( msg )
- local msgLen = msg:GetDataLength()
- local msgHdr = msg:GetHeader()
- local dataString = msg:GetData():ReadString(msgLen)
- self._pay_curr_day = msgHdr.recog
- self:SetPayDayCountData( dataString )
- end
- function InformationProxy:RegisterMsgHandler()
- InformationProxy.super.RegisterMsgHandler(self)
- local msgType = global.MsgType
- LuaRegisterMsgHandler( msgType.MSG_SC_GET_INFORMATION_RESPON, handler( self, self.handle_MSG_SC_GET_INFORMATION_RESPON) )
- LuaRegisterMsgHandler( msgType.MSG_SC_GET_EVERYDAY_CHARGE, handler( self, self.handle_MSG_SC_GET_EVERYDAY_CHARGE) )
- end
- return InformationProxy
|