ActTotalRecharge.lua 5.8 KB

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