ActTotalRecharge.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. -- 活动 - 七日累充
  2. ActTotalRecharge = {}
  3. ActTotalRecharge.__index = ActTotalRecharge
  4. local function _rechargeType()
  5. return "1003"
  6. end
  7. local function _playerDbKey()
  8. return "T$act_recharge_days_total_data"
  9. end
  10. -- 获取活动奖励
  11. local function _get_reward_items(id)
  12. local reward = ConfigDataManager.getTableValue("cfg_Activity_firstRecharge", "reward", "id", id)
  13. jprint("七日累充活动奖励", id, reward)
  14. local tmp = string.toIntIntMap(reward, "#", "|")
  15. if table.notNullOrEmpty(tmp) then
  16. local list = {}
  17. for k, v in pairs(tmp) do
  18. table.insert(list, {id = k, count = v})
  19. end
  20. return list
  21. end
  22. return {}
  23. end
  24. function ActTotalRecharge.getData(actor)
  25. local var = getplaydef(actor, _playerDbKey())
  26. local data = setmetatable(var or {}, ActTotalRecharge)
  27. -- 累计充值
  28. if not data.count then
  29. data.count = 0
  30. end
  31. -- 已领取奖励id
  32. if not data.rewardList then
  33. data.rewardList = {}
  34. end
  35. -- 结束时间
  36. local currTime = getbaseinfo("nowsec")
  37. if not data.endTime or data.endTime <= currTime then
  38. ActTotalRecharge.onEnd(actor)
  39. local weekSecs = 3600 * 24 * 7
  40. local openTimeSec = math.ceil(getbaseinfo(actor, "serveropentime") / 1000)
  41. jprint("openTimeSec:", openTimeSec)
  42. local weeks = math.floor((currTime - openTimeSec) / weekSecs)
  43. data.endTime = openTimeSec + (weeks + 1) * weekSecs
  44. data.count = 0
  45. data.rewardList = {}
  46. setplaydef(actor, _playerDbKey(), data)
  47. end
  48. return data
  49. end
  50. -- 活动结束
  51. function ActTotalRecharge.onEnd(actor)
  52. -- 未领取奖励,邮件发放
  53. local var = getplaydef(actor, _playerDbKey())
  54. local data = setmetatable(var or {}, ActTotalRecharge)
  55. if data.count and data.count > 0 then
  56. jprint("ActTotalRecharge.onEnd count:", data.count)
  57. local playerCareer = tonumber(getbaseinfo(actor, "getbasecareer"))
  58. local mapItems = {}
  59. local confs = ConfigDataManager.getList("cfg_Activity_daysTotalRecharge")
  60. for i = 1, #confs do
  61. jprint("ActTotalRecharge.onEnd count:", data.count)
  62. jprint("ActTotalRecharge.onEnd id:", confs[i].id)
  63. jprint("ActTotalRecharge.onEnd recharge:", confs[i].recharge)
  64. jprint("ActTotalRecharge.onEnd reward:", confs[i].reward)
  65. if confs[i].recharge and confs[i].id then
  66. if
  67. data.count >= tonumber(confs[i].recharge) and
  68. not (data.rewardList and table.contains(data.rewardList, confs[i].id))
  69. then
  70. local tmp = string.toIntIntMap4Career(playerCareer, confs[i].reward, "#", "|")
  71. if table.notNullOrEmpty(tmp) then
  72. for k, v in pairs(tmp) do
  73. if not mapItems[k] then
  74. mapItems[k] = v
  75. else
  76. mapItems[k] = mapItems[k] + v
  77. end
  78. end
  79. end
  80. end
  81. end
  82. end
  83. if table.notNullOrEmpty(mapItems) then
  84. -- 发放补充奖励邮件
  85. sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), MailConfig.ACT_DAYS_RECHARGES, mapItems, "")
  86. end
  87. end
  88. end
  89. function ActTotalRecharge:saveData(actor)
  90. setplaydef(actor, _playerDbKey(), self)
  91. end
  92. ---充值回调触发事件
  93. function ActTotalRecharge.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  94. jprint("更新[七日累充活动]数据 amount:", amount)
  95. local data = ActTotalRecharge.getData(actor)
  96. data.count = data.count + amount
  97. setplaydef(actor, _playerDbKey(), data)
  98. jprint("更新[七日累充活动]数据 count:", data.count)
  99. -- 前端同步累充金额
  100. ActTotalRecharge.sendModuleInfo(actor)
  101. end
  102. function ActTotalRecharge.gainReward(actor, reqParameter)
  103. local id = reqParameter["id"]
  104. local recharge = ConfigDataManager.getTableValue("cfg_Activity_daysTotalRecharge", "recharge", "id", id)
  105. if recharge == nil then
  106. tipinfo(actor, "无此档位")
  107. return
  108. end
  109. local data = ActTotalRecharge.getData(actor)
  110. -- 未充值
  111. if data.count < tonumber(recharge) then
  112. tipinfo(actor, "未达标")
  113. return
  114. end
  115. -- 已领取
  116. if data.rewardList and table.contains(data.rewardList, id) then
  117. tipinfo(actor, "已领取")
  118. return
  119. end
  120. -- 发放奖励
  121. local reward = ConfigDataManager.getTableValue("cfg_Activity_daysTotalRecharge", "reward", "id", id)
  122. local playerCareer = tonumber(getbaseinfo(actor, "getbasecareer"))
  123. local tmp = string.toIntIntMap4Career(playerCareer, reward, "#", "|")
  124. if table.notNullOrEmpty(tmp) then
  125. --奖励进入背包
  126. Bag.sendRewards(actor, tmp, "七日累充活动奖励")
  127. end
  128. -- 改变状态
  129. table.insert(data.rewardList, id)
  130. setplaydef(actor, _playerDbKey(), data)
  131. -- jprint("领奖豪礼数据",data)
  132. ActTotalRecharge.sendModuleInfo(actor)
  133. end
  134. -- 获取活动信息
  135. function ActTotalRecharge.getInfo(actor, msgData)
  136. ActTotalRecharge.sendModuleInfo(actor)
  137. end
  138. -- 推送活动模块数据
  139. function ActTotalRecharge.sendModuleInfo(actor, isStartShow)
  140. local data = ActTotalRecharge.getData(actor)
  141. jprint("ActTotalRecharge sendModuleInfo count:", data.count)
  142. sendluamsg(
  143. actor,
  144. LuaMessageIdToClient.RES_ACT_DAYS_RECHARGE_INFO,
  145. {
  146. count = data.count,
  147. rewardList = data.rewardList,
  148. endTime = data.endTime
  149. }
  150. )
  151. end
  152. function ActTotalRecharge.login(actor)
  153. ActTotalRecharge.sendModuleInfo(actor)
  154. end
  155. --TODO 一定要放到文件最后
  156. EventListerTable.registerType("七日累充活动", _rechargeType(), _playerDbKey())
  157. --注册充值事件
  158. RechargeEventListerTable:eventLister("0", "七日累充活动", ActTotalRecharge.rechargeEvent)