MainOperateActivityInfo.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. ---@class MainOperateActivityInfo
  2. MainOperateActivityInfo = class()
  3. local this = MainOperateActivityInfo
  4. function this:ctor()
  5. end
  6. function this:Reset()
  7. self.operateMainActivityRedsTbl = {}
  8. end
  9. function this:Init()
  10. self:InitData()
  11. self:RegistMessages()
  12. end
  13. function this:InitData()
  14. self.isOperateActivityMainBtnShow = false --主界面运营活动按钮是否展示 true展示
  15. self.operateActivityTypeTime = 0 --运营大活动开启时间
  16. self.operateActivityTypeCloseTime = 0 --运营大活动关闭时间
  17. self.isOperateHaveShowPanel = false --主界面运营活动按钮内是否有活动 true有
  18. self.operateMainActivityData = {} --RES_MAIN_ACTIVE_INFO协议内的所有运营活动数据
  19. self.tmpAllShowPanelTbl = {} --判断是否有功能开关变动
  20. self.operateMainConditionInfo = {} --运营活动条件集相关数据
  21. self.operateMainActivityRedsTbl = {} --运营活动红点表
  22. self.NowOperateActivityMainGroup = 0 --当前轮活动mainGroup
  23. self.addRechargeInfo = {} --累充活动
  24. self.diamondPackInfo = {} --累充活动
  25. end
  26. function this:RegistMessages()
  27. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO, self.RefreshOperateActivityData, self)
  28. SL:RegisterLUAEvent(LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self.LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self)
  29. end
  30. function this:LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE()
  31. self:RefreshMainOperateActivityRedPoint(EOperateActivityActivityType.RechargeDirect, "tog_Directpurchase", self:IsDirectRedDot())
  32. end
  33. -- [
  34. -- RES_MAIN_ACTIVE_INFO = 10000276, -- 响应:运营活动基础信息
  35. -- mainActive [activeId,closeTime,isShow,mainGroup,startTime]
  36. -- subActive [list = {id,openTime}]
  37. -- ]
  38. function this:RefreshOperateActivityData(_, msg)
  39. if (not msg) or table.isNullOrEmpty(msg) or table.isNullOrEmpty(msg.mainActive) then
  40. SL:LogError("RES_MAIN_ACTIVE_INFO(10000276)协议内没有数据,请检查---------")
  41. return
  42. end
  43. local data = msg
  44. if self.isOperateActivityMainBtnShow ~= data.mainActive.isShow then
  45. self.isOperateActivityMainBtnShow = data.mainActive.isShow
  46. end
  47. self.operateActivityTypeTime = data.mainActive.startTime
  48. self.operateActivityTypeCloseTime = data.mainActive.closeTime
  49. local isHideMainOperatePanel = false
  50. if data.mainActive.isShow then
  51. local operateActivityAllInfo = SL:GetConfigMultiKeys("cfg_OperateActivity_all", data.mainActive.mainGroup, "mainGroup")
  52. if table.isNullOrEmpty(operateActivityAllInfo) then
  53. local str = "cfg_OperateActivity_all表内没有mainGroup为" .. data.mainActive.mainGroup .. "的数据!请检查配置!"
  54. SL:LogError(str)
  55. return
  56. else
  57. data.operateActivityAllInfo = operateActivityAllInfo
  58. --获取当前运营活动需要展示的所有子活动
  59. local allShowPanel = {}
  60. local returnDataTbl = {}
  61. if not table.isNullOrEmpty(data.subActive) then
  62. self.isOperateHaveShowPanel = true
  63. if not table.isNullOrEmpty(self.tmpAllShowPanelTbl) then
  64. for _, v in pairs(data.subActive) do
  65. local subActivityData = SL:GetConfig("cfg_OperateActivity_subActivity", tonumber(v.id))
  66. local id = subActivityData.id
  67. if not table.contains(self.tmpAllShowPanelTbl, id) then
  68. isHideMainOperatePanel = true
  69. break
  70. end
  71. end
  72. if table.count(self.tmpAllShowPanelTbl) ~= table.count(data.subActive) then
  73. isHideMainOperatePanel = true
  74. end
  75. end
  76. self.tmpAllShowPanelTbl = {}
  77. self.operateMainConditionInfo = {}
  78. for _, v in pairs(data.subActive) do
  79. local subActivityData = SL:GetConfig("cfg_OperateActivity_subActivity", tonumber(v.id))
  80. table.insert(self.tmpAllShowPanelTbl, subActivityData.id)
  81. v.subActivityData = subActivityData --OperateActivity_subActivity表内对应数据
  82. local subPanelData = SL:GetConfig("cfg_sub_OperateActivity", subActivityData.subId)
  83. subPanelData.togShowName = subActivityData.showTogName
  84. table.insert(allShowPanel, subPanelData)
  85. returnDataTbl[subActivityData.subType] = v
  86. local time = v.openTime > 0 and v.openTime or 0
  87. self.operateMainConditionInfo[subActivityData.subType] = time
  88. end
  89. data.allShowPanelData = allShowPanel --当前运营活动界面需要展示的页签panel
  90. data.returnData = returnDataTbl --需要发回给后端的id,也可用来判断功能是否开启
  91. else
  92. self.isOperateHaveShowPanel = false
  93. end
  94. end
  95. self.operateMainActivityData = {}
  96. self.operateMainActivityData = data
  97. self.NowOperateActivityMainGroup = data.mainActive.mainGroup
  98. self:InitMainOperateRedInfo()
  99. self:GetSubActiveDataInfo(data)
  100. if isHideMainOperatePanel then
  101. local operateMainPanel = GUI:GetUI("dev/outui/MainOperateActivity/Panel/KLMainOperateActivity/KLMainOperateActivityPanel")
  102. if operateMainPanel then
  103. operateMainPanel:OnClickClose()
  104. end
  105. end
  106. else
  107. --运营活动关闭
  108. local operateMainPanel = GUI:GetUI("dev/outui/MainOperateActivity/Panel/KLMainOperateActivity/KLMainOperateActivityPanel")
  109. if operateMainPanel then
  110. operateMainPanel:OnClickClose()
  111. end
  112. end
  113. --派发事件
  114. SL:onLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE)
  115. end
  116. ----------------------------------------------运营活动---------------------------------------------------------------
  117. --初始化子活动红点页签
  118. function this:InitMainOperateRedInfo()
  119. if self.isOperateHaveShowPanel then
  120. local showTbl = self.operateMainActivityData.allShowPanelData
  121. if not table.isNullOrEmpty(showTbl) then
  122. for _, v in pairs(showTbl) do
  123. self.operateMainActivityRedsTbl[v.togName] = false
  124. end
  125. end
  126. end
  127. end
  128. --获取子活动数据
  129. function this:GetSubActiveDataInfo(data)
  130. if not table.isNullOrEmpty(data.totalSubActive) then
  131. self:RefreshAddRechargeData(data.totalSubActive)
  132. end
  133. if not table.isNullOrEmpty(data.diamondPackInfo) then
  134. self.diamondPackInfo = data.diamondPackInfo
  135. end
  136. self:RefershOperateRed()
  137. end
  138. --刷新子活动红点
  139. function this:RefershOperateRed()
  140. self:RefreshMainOperateActivityRedPoint(EOperateActivityActivityType.RechargeDirect, "tog_Directpurchase", self:IsDirectRedDot())
  141. self:RefreshMainOperateActivityRedPoint(EOperateActivityActivityType.OperateAddRecharge, "tog_Accumulation", self:RefreshAddRechargeRed())
  142. self:RefreshMainOperateActivityRedPoint(EOperateActivityActivityType.DiamondRecharge, "tog_Diamond", self:GetDiamondRedPoint())
  143. end
  144. --刷新累充活动红点
  145. function this:RefreshAddRechargeRed()
  146. local addRechargeData = self.addRechargeInfo
  147. if not table.isNullOrEmpty(addRechargeData) then
  148. for _, v in pairs(addRechargeData) do
  149. if v.isShowRed then
  150. return true
  151. end
  152. end
  153. end
  154. return false
  155. end
  156. function this:GetDiamondRedPoint()
  157. if self.diamondPackInfo then
  158. for i, v in pairs(self.diamondPackInfo) do
  159. ---@type cfg_DiamondPack_column
  160. local tbl = SL:GetConfig("cfg_DiamondPack", tonumber(v.diamondPackId))
  161. if tbl.type == 3 then
  162. local buycount = InfoManager.countInfo:GetLimitAndTotalCountByKey(tbl.countkey)
  163. if buycount > 0 then
  164. return true
  165. end
  166. end
  167. end
  168. end
  169. return false
  170. end
  171. --判断小活动功能是否开启
  172. ---@param subType OperateActivity_subActivity表内的subType EOperateActivityActivityType枚举
  173. function this:JudgeThisSubtypeActivityIsOpen(subType)
  174. if (not table.isNullOrEmpty(self.operateMainActivityData))
  175. and (not table.isNullOrEmpty(self.operateMainActivityData.returnData))
  176. and (not table.isNullOrEmpty(self.operateMainActivityData.returnData[subType])) then
  177. return true
  178. end
  179. return false
  180. end
  181. ---刷新运营活动主界面按钮红点以及子页签红点
  182. ---togName sub_OperateActivity表内字段
  183. ---isShow是否展示红点 true展示
  184. function this:RefreshMainOperateActivityRedPoint(subType, togName, isShow)
  185. if isShow then
  186. isShow = self.isOperateActivityMainBtnShow and self:JudgeThisSubtypeActivityIsOpen(subType)
  187. end
  188. if not table.isNullOrEmpty(self.operateMainActivityRedsTbl) then
  189. self.operateMainActivityRedsTbl[togName] = isShow
  190. SL:RefreshPanelALLRedStateKmlByCondition("checkMainOperateActivityRed")
  191. local panel = GUI:GetUI("dev/outui/MainOperateActivity/Panel/KLMainOperateActivity/KLMainOperateActivityPanel")
  192. if panel then
  193. panel:RefreshTogRedPointShow()
  194. end
  195. end
  196. end
  197. --获取今天是周几
  198. function this:WhatDayIsTodayInWeek()
  199. local time = math.floor(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) / 1000)
  200. local TimeData = os.date("*t", time)
  201. local dayNum = TimeData.wday - 1 --周日为1 周一为2
  202. if dayNum == 0 then
  203. dayNum = 7
  204. end
  205. return dayNum
  206. end
  207. --获取是否在时间区间内
  208. --time 2024/12/16-2024/12/23
  209. function this:IntervalTweenyearTime(time)
  210. local curTime = math.floor(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) / 1000)
  211. local tmpData = string.split(time, "-")
  212. local firstData = tmpData[1]
  213. local lastData = tmpData[2]
  214. local stratTime = self:GetyearTimeStamp(firstData)
  215. if curTime < stratTime then
  216. return false
  217. end
  218. local endTime = self:GetyearTimeStamp(lastData) + 86400
  219. if curTime > endTime then
  220. return false
  221. end
  222. return true
  223. end
  224. function this:GetyearTimeStamp(data)
  225. local numbers = string.split(data, "_")
  226. if table.count(numbers) == 2 then
  227. return self:DateToServerTime({ year = numbers[1], month = numbers[2], day = 0, hour = 0 })
  228. end
  229. if table.count(numbers) == 3 then
  230. return self:DateToServerTime({ year = numbers[1], month = numbers[2], day = numbers[3], hour = 0 })
  231. end
  232. SL:LogError("time Error!!")
  233. return 0
  234. end
  235. --考虑时区 单位秒
  236. ---@param serverDate table 服务器日期table { year = 2021, month = 12, day = 16, hour = 0,min = 0, sec = 0 }
  237. function this:DateToServerTime(serverDate)
  238. local DAY_SECONDS = 24 * 3600
  239. local TIMEZONES_SECONDS = 8 * 3600 --东八区 时区时间差
  240. local TIME_ZONE = os.time({ year = 1970, month = 1, day = 2, hour = 0, isdst = false })
  241. serverDate.isdst = false ---禁用夏令时
  242. local localDateTime = os.time(serverDate)
  243. return localDateTime + ((DAY_SECONDS - TIMEZONES_SECONDS) - TIME_ZONE)
  244. end
  245. function this:GetDurationDayMainGroup()
  246. local class = 0
  247. local curTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  248. class = self:DayApartFromTwoTime(curTime, InfoManager.mainOperateActivityInfo.operateActivityTypeTime) + 1 --持续天数+1天
  249. return class
  250. end
  251. function this:GetDurationDaySubType(subtype)
  252. local class = 0
  253. local openActivityTime = InfoManager.mainOperateActivityInfo.operateMainConditionInfo[subtype]
  254. if openActivityTime > 0 then
  255. local curTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  256. class = self:DayApartFromTwoTime(curTime, openActivityTime) + 1 --持续天数+1天
  257. end
  258. return class
  259. end
  260. ---@param sTime number (ms) 毫秒 eTime 时间戳 (ms) 毫秒
  261. ---@return number apart days
  262. function this:DayApartFromTwoTime(sTime, eTime)
  263. sTime = math.floor(sTime / 1000)
  264. eTime = math.floor(eTime / 1000)
  265. local TIMEZONES_SECONDS = 8 * 3600 --东八区 时区时间差
  266. local DAY_SECONDS = 24 * 3600
  267. --此处需要知道服务器时区 现在假定是在东八区 则需要加8个小时 8*3600
  268. local result = math.floor((sTime + TIMEZONES_SECONDS) / DAY_SECONDS) - math.floor((eTime + TIMEZONES_SECONDS) / DAY_SECONDS)
  269. return result
  270. end
  271. ---获取子活动界面倒计时 返回倒计时时间戳
  272. ---@return number timeStamp 时间戳
  273. function this:GetOADJSTimeBySubType(subType)
  274. local actualTbl = {}
  275. local showData = self.operateMainActivityData.subActive
  276. if not table.isNullOrEmpty(showData) then
  277. for _, v in pairs(showData) do
  278. if v.subActivityData.mainGroup == self.NowOperateActivityMainGroup and v.subActivityData.subType == subType then
  279. actualTbl = v
  280. break
  281. end
  282. end
  283. end
  284. if table.isNullOrEmpty(actualTbl) then
  285. return
  286. end
  287. local condition = actualTbl.subActivityData.closeCondition
  288. local tmpData = string.split(condition, "#")
  289. local conditionType = tonumber(tmpData[1]) --条件类型
  290. local mainGroup = tonumber(tmpData[2]) --大活动类型
  291. local subSubType = tonumber(tmpData[3]) --子活动类型
  292. local conditionKey = tonumber(tmpData[4]) --子活动持续天数
  293. local timeStamp = 0
  294. local dayTime = 86400
  295. if mainGroup == self.NowOperateActivityMainGroup then
  296. if subType == subSubType then
  297. if conditionType == 981 then
  298. local curTime = math.floor(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) / 1000)
  299. timeStamp = math.floor(self.operateMainConditionInfo[subSubType] / 1000 + conditionKey * dayTime - curTime)
  300. else
  301. local tips = "OperateActivity_subActivity表内mainGroup==" .. self.NowOperateActivityMainGroup ..
  302. ", subType==" .. subType .. "的closeCondition字段第一个参数应该配置为981条件,请检查!!"
  303. SL:LogError(tips)
  304. end
  305. else
  306. local tips = "OperateActivity_subActivity表内mainGroup==" .. self.NowOperateActivityMainGroup ..
  307. ", subType==" .. subType .. "的closeCondition字段第三个参数配错了,请检查!!"
  308. SL:LogError(tips)
  309. end
  310. else
  311. local tips = "OperateActivity_subActivity表内mainGroup==" .. self.NowOperateActivityMainGroup ..
  312. ", subType==" .. subType .. "的closeCondition字段第二个参数配错了,请检查!!"
  313. SL:LogError(tips)
  314. end
  315. return timeStamp
  316. end
  317. ----------------------------------------------运营活动子活动---------------------------------------------------------------
  318. --刷新累充活动数据
  319. function this:RefreshAddRechargeData(totalSubActive)
  320. self.addRechargeInfo = {}
  321. local tab = {}
  322. local tbl = {}
  323. local TgiftState = 2
  324. ---获取剩余次数和总次数
  325. local buycount = 0
  326. local totalcount = 0
  327. local showmoney = 0
  328. local isShow = false
  329. for _, v in pairs(totalSubActive.panel) do
  330. showmoney = totalSubActive.money
  331. tbl = SL:GetConfig("cfg_rechargeRccrued", tonumber(v.accumulatedId))
  332. buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(tbl.Countkey)
  333. if buycount > 0 and totalSubActive.money >= tbl.amount then
  334. --剩余次数大于0切可以领取
  335. TgiftState = E_RechargeState.CanGet --可领取
  336. showmoney = tbl.amount
  337. isShow = true
  338. elseif totalSubActive.money < tbl.amount then
  339. TgiftState = E_RechargeState.NotComplete --未完成
  340. else
  341. TgiftState = E_RechargeState.AlreadyGet --已领取
  342. showmoney = tbl.amount
  343. end
  344. tab = {
  345. id = v.accumulatedId,
  346. money = showmoney,
  347. showCount = tbl.showCount,
  348. reward = tbl.reward,
  349. taskDes = tbl.text,
  350. goal = tbl.amount,
  351. giftState = TgiftState,
  352. isShowRed = isShow
  353. }
  354. table.insert(self.addRechargeInfo, tab)
  355. end
  356. end
  357. ----直购红点
  358. function this:IsDirectRedDot()
  359. local currentGroup = self.NowOperateActivityMainGroup
  360. local cfg = SL:GetConfigTable("cfg_OperateActivity_CDM")
  361. for k, v in ipairs(cfg) do
  362. if v.mainGroup == currentGroup and (v.bugType == 1 or v.bugType == 3) then
  363. local rechargeCfg = SL:GetConfigTwoKeys("cfg_recharge", v.id, v.rechargeType, "parameter", "type")
  364. if rechargeCfg then
  365. if rechargeCfg.amount == 0 then
  366. local count, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(rechargeCfg.Countkey)
  367. if count > 0 then
  368. return true
  369. end
  370. end
  371. end
  372. end
  373. end
  374. return false
  375. end