InformationProxy.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. local RemoteProxy = requireProxy( "remote/RemoteProxy" )
  2. local InformationProxy = class( "InformationProxy", RemoteProxy )
  3. InformationProxy.NAME = global.ProxyTable.InformationProxy
  4. function InformationProxy:ctor()
  5. InformationProxy.super.ctor( self )
  6. self._config = {}
  7. self._day_count = {}
  8. self._pay_day_count = {} --充值信息
  9. self._curr_day = 1
  10. self._pay_curr_day = 1 --当前数组的天数
  11. self._select_day = {} --记录本地已选择的天数
  12. self:LoadConfig()
  13. end
  14. function InformationProxy:LoadConfig()
  15. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  16. local fileName = "cfg_information.lua"
  17. if global.FileUtilCtl:isFileExist("scripts/game_config/" .. fileName) then
  18. self._config = requireGameConfig("cfg_information")
  19. end
  20. self._select_day = self:GetSelecDaykData()
  21. end
  22. function InformationProxy:GetConfig()
  23. return self._config
  24. end
  25. function InformationProxy:GetConfigByID( id )
  26. if not id then
  27. return {}
  28. end
  29. return self._config[id] or {}
  30. end
  31. function InformationProxy:GetDayByID( id )
  32. if not id then
  33. return 7
  34. end
  35. return self._select_day[id] or 7
  36. end
  37. function InformationProxy:SetDayByID( id,day )
  38. if not id or not day then
  39. return
  40. end
  41. self._select_day[id] = day
  42. self:SetSelecDaykData()
  43. end
  44. function InformationProxy:GetDayMath( day )
  45. if not day then
  46. return ""
  47. end
  48. local ret = ""
  49. if day >= 365 then
  50. ret = string.format( GET_STRING(310000308), math.floor(day/365) )
  51. elseif day >= 30 then
  52. ret = string.format( GET_STRING(310000307), math.floor(day/30) )
  53. elseif day > 0 then
  54. ret = string.format( GET_STRING(310000306), day )
  55. end
  56. return ret
  57. end
  58. function InformationProxy:GetInformationCount( day,id )
  59. if not day then
  60. return 0
  61. end
  62. local count = 0
  63. local offDay = 0
  64. local currDay = 1
  65. local dayCount = {}
  66. if id == 4 then --充值信息单独获取
  67. dayCount = self._pay_day_count
  68. currDay = self._pay_curr_day
  69. else
  70. dayCount = self._day_count
  71. currDay = self._curr_day
  72. end
  73. for i=1,day do
  74. local index = currDay - i + offDay + 1
  75. if index == 0 then
  76. index = 365
  77. offDay = 365
  78. end
  79. count = count + (dayCount[index] or 0)
  80. end
  81. return count
  82. end
  83. function InformationProxy:PareseInformationName( id )
  84. if not id then
  85. return {}
  86. end
  87. local config = self:GetConfigByID( id )
  88. local array1 = string.split( config.page2name or "", "#" )
  89. local array2 = string.split( config.page3name or "", "#" )
  90. local array = {}
  91. for i,v in ipairs(array1) do
  92. array[i] = {
  93. name = array1[i] or "",
  94. txtStr = array2[i] or ""
  95. }
  96. end
  97. return array
  98. end
  99. function InformationProxy:SetDayCountData( str )
  100. self._day_count = {}
  101. local array = string.split( str or "", ";" )
  102. for i,v in ipairs( array ) do
  103. if v and v ~= "" then
  104. local arry1 = string.split(v,"=")
  105. local day = tonumber(arry1[1]) or 0
  106. local count = tonumber(arry1[2]) or 0
  107. self._day_count[day] = count
  108. end
  109. end
  110. end
  111. function InformationProxy:SetPayDayCountData( str )
  112. self._pay_day_count = {}
  113. local array = string.split( str or "", ";" )
  114. for i,v in ipairs( array ) do
  115. if v and v ~= "" then
  116. local arry1 = string.split(v,"=")
  117. local day = tonumber(arry1[1]) or 0
  118. local count = tonumber(arry1[2]) or 0
  119. self._pay_day_count[day] = count
  120. end
  121. end
  122. end
  123. -- 本地缓存数据
  124. function InformationProxy:GetSelecDaykData()
  125. local PosData = UserData:new("InformationData")
  126. local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  127. local flag = proxy:GetSelectedRoleID() or "errorName"
  128. local clientData = PosData:getStringForKey( "information"..flag )
  129. if not clientData or clientData == "" then
  130. return {}
  131. end
  132. local cjson = require( "cjson" )
  133. local lastJsonData = cjson.decode(clientData)
  134. return lastJsonData
  135. end
  136. function InformationProxy:SetSelecDaykData()
  137. local PosData = UserData:new("InformationData")
  138. local proxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  139. local flag = proxy:GetSelectedRoleID() or "errorName"
  140. local cjson = require( "cjson" )
  141. local selectDayData = cjson.encode(self._select_day)
  142. local clientData = PosData:setStringForKey( "information"..flag, selectDayData )
  143. end
  144. -- 收集个人信息
  145. function InformationProxy:handle_MSG_SC_GET_INFORMATION_RESPON( msg )
  146. local msgLen = msg:GetDataLength()
  147. local msgHdr = msg:GetHeader()
  148. local dataString = msg:GetData():ReadString(msgLen)
  149. self._curr_day = msgHdr.recog
  150. self:SetDayCountData( dataString )
  151. end
  152. -- 收集个人充值信息
  153. function InformationProxy:handle_MSG_SC_GET_EVERYDAY_CHARGE( msg )
  154. local msgLen = msg:GetDataLength()
  155. local msgHdr = msg:GetHeader()
  156. local dataString = msg:GetData():ReadString(msgLen)
  157. self._pay_curr_day = msgHdr.recog
  158. self:SetPayDayCountData( dataString )
  159. end
  160. function InformationProxy:RegisterMsgHandler()
  161. InformationProxy.super.RegisterMsgHandler(self)
  162. local msgType = global.MsgType
  163. LuaRegisterMsgHandler( msgType.MSG_SC_GET_INFORMATION_RESPON, handler( self, self.handle_MSG_SC_GET_INFORMATION_RESPON) )
  164. LuaRegisterMsgHandler( msgType.MSG_SC_GET_EVERYDAY_CHARGE, handler( self, self.handle_MSG_SC_GET_EVERYDAY_CHARGE) )
  165. end
  166. return InformationProxy