ActTotalRecharge.lua 5.5 KB

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