ConsumerRank.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. --- 消费排行
  2. ConsumerRank = { }
  3. ConsumerRank.__index = ConsumerRank
  4. local this = {}
  5. local function _rechargeType()
  6. return "19"
  7. end
  8. local function _playerDbKey()
  9. return "T$CONSUMER_RANK"
  10. end
  11. function ConsumerRank.get(actor)
  12. local obj = getplaydef(actor, _playerDbKey())
  13. return setmetatable(obj or {}, ConsumerRank)
  14. end
  15. function ConsumerRank:save(actor)
  16. setplaydef(actor, _playerDbKey(), self);
  17. end
  18. --- 请求充值档位信息
  19. function ConsumerRank.reqRechargeAction(actor,mainGroup)
  20. -- 判断当前主活动是否开启了子直购活动
  21. local activity = {}
  22. local rank = ConfigDataManager.getTable("cfg_Activity_costRank","mainGroup",mainGroup)
  23. if table.isNullOrEmpty(rank) then
  24. return activity
  25. end
  26. local allRechargeInfo = ConsumerRank.get(actor)
  27. local numberId = tonumber(mainGroup)
  28. local rechargeInfo = allRechargeInfo[numberId]
  29. activity["ownInfo"] = rechargeInfo
  30. local topTen = this.getTopTen(numberId)
  31. activity["rank"] = topTen
  32. return activity
  33. end
  34. function this.getRankMoney(mainGroup)
  35. local money = 0
  36. local allRankMoney = ConfigDataManager.getTableValue("cfg_global","value","id",28004)
  37. if string.isNullOrEmpty(allRankMoney) then
  38. return money
  39. end
  40. local rankMoneyTable = string.split(allRankMoney,"|")
  41. for k, rankMoney in pairs(rankMoneyTable) do
  42. local rankMoneyInfo = string.split(rankMoney,"#")
  43. if tonumber(rankMoneyInfo[1]) == mainGroup then
  44. return tonumber(rankMoneyInfo[2])
  45. end
  46. end
  47. return money
  48. end
  49. -- 获取前十名
  50. function this.getTopTen(mainGroup)
  51. local consumerRank = {}
  52. local rankMoney = this.getRankMoney(mainGroup)
  53. local allRoleInfos = getallrolesummaryinfos()
  54. if not table.isNullOrEmpty(allRoleInfos) then
  55. for k, roleInfo in pairs(allRoleInfos) do
  56. local otherActor = roleInfo["actor"]
  57. local allOtherRechargeInfo = ConsumerRank.get(otherActor)
  58. if not table.isNullOrEmpty(allOtherRechargeInfo) then
  59. local otherRechargeInfo = allOtherRechargeInfo[mainGroup]
  60. if not table.isNullOrEmpty(otherRechargeInfo) and otherRechargeInfo.money >= rankMoney then
  61. table.insert(consumerRank,otherRechargeInfo)
  62. end
  63. end
  64. end
  65. end
  66. table.sort(consumerRank, function(a, b)
  67. if a.money == b.money and a.time ~= nil and b.time ~= nil then
  68. return a.time > b.time
  69. else
  70. return a.money > b.money
  71. end
  72. end)
  73. local topTen = {}
  74. if table.count(consumerRank) > 10 then
  75. for i = 1, 10 do
  76. local roleInfo = consumerRank[i]
  77. table.insert(topTen,roleInfo)
  78. end
  79. else
  80. topTen = consumerRank
  81. end
  82. return topTen
  83. end
  84. --- 触发充值
  85. function ConsumerRank.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  86. this.saveMoney(actor,amount,count)
  87. OperationalActivities.openSubActive(actor,{
  88. subType = ACTIVE_TYPE.CONSUMER_RANK
  89. })
  90. end
  91. -- 保存当前充值的钱
  92. function this.saveMoney(actor,amount,count)
  93. local currentActive = getsysvar(actor,CURRENT_ACTIVE)
  94. if table.isNullOrEmpty(currentActive) then
  95. return
  96. end
  97. if OperationalActivities.judgeActiveClose(actor,ACTIVE_TYPE.CONSUMER_RANK) then
  98. local numberId = tonumber(currentActive.mainActive.mainGroup)
  99. if amount ~= nil then
  100. local operationalActive = ConsumerRank.get(actor)
  101. local rechargeInfo = operationalActive[numberId]
  102. if table.isNullOrEmpty(rechargeInfo) then
  103. rechargeInfo = {
  104. rid = actor:toString(),
  105. name = getbaseinfo(actor,"rolename"),
  106. money = tonumber(amount) * tonumber(count),
  107. time = getbaseinfo(actor,"now")
  108. }
  109. operationalActive[numberId] = rechargeInfo
  110. else
  111. rechargeInfo.money = rechargeInfo.money + tonumber(amount) * tonumber(count)
  112. rechargeInfo.time = getbaseinfo(actor,"now")
  113. end
  114. operationalActive:save(actor)
  115. end
  116. end
  117. end
  118. --- 累充关闭
  119. function ConsumerRank.closeActive(mainGroup)
  120. local topTen = this.getTopTen(mainGroup)
  121. if table.isNullOrEmpty(topTen) then
  122. return
  123. end
  124. for index, rechargeInfo in pairs(topTen) do
  125. local rid = rechargeInfo.rid
  126. local actor = getactor(rid)
  127. local career = getbaseinfo(actor,"getbasecareer")
  128. local mail = ConfigDataManager.getTableValue("cfg_Activity_costRank","mail","mainGroup",mainGroup,"ranking",index)
  129. local mailTable = string.split(mail,"|")
  130. local item = {}
  131. for k, mailInfo in pairs(mailTable) do
  132. local mailDetail = string.split(mailInfo,"#")
  133. if table.count(mailDetail) == 3 and tonumber(mailDetail[3]) == career then
  134. local itemCfgId = tonumber(mailDetail[1])
  135. local itemCount = item[itemCfgId]
  136. if itemCount == nil then
  137. item[itemCfgId] = tonumber(mailDetail[2])
  138. else
  139. item[itemCfgId] = item[itemCfgId] + tonumber(mailDetail[2])
  140. end
  141. end
  142. if table.count(mailDetail) == 2 then
  143. local itemCfgId = tonumber(mailDetail[1])
  144. local itemCount = item[itemCfgId]
  145. if itemCount == nil then
  146. item[itemCfgId] = tonumber(mailDetail[2])
  147. else
  148. item[itemCfgId] = item[itemCfgId] + tonumber(mailDetail[2])
  149. end
  150. end
  151. end
  152. sendconfigmailbyrid(actor,actor:toString(), 900005, item)
  153. end
  154. end
  155. -- ------------------------------------------------------------- --
  156. this.log_open = false
  157. function this.debug(...)
  158. if not this.log_open then
  159. return
  160. end
  161. gameDebug.print(...)
  162. end
  163. function this.jprint(...)
  164. if not this.log_open then
  165. return
  166. end
  167. if param == nil then
  168. param = "error! 输出内容为空. nil"
  169. end
  170. jprint(...)
  171. end
  172. -- ------------------------------------------------------------- --
  173. EventListerTable.registerType("消费排行", _rechargeType(), _playerDbKey())
  174. RechargeEventListerTable:eventLister("0", "消费排行", ConsumerRank.rechargeEvent)