ActTotalRecharge.lua 5.8 KB

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