RechargeBackLogic.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. --- 打赏返利
  2. local Util = require("common.Util")
  3. local ObjHuman = require("core.ObjHuman")
  4. local Msg = require("core.Msg")
  5. local Grid = require("bag.Grid")
  6. local ItemDefine = require("bag.ItemDefine")
  7. local BuyLogic = require("topup.BuyLogic")
  8. local BagLogic = require("bag.BagLogic")
  9. local YunYingLogic = require("yunying.YunYingLogic")
  10. local PanelDefine = require("broadcast.PanelDefine")
  11. local YyHandler = require("yunying.Handler")
  12. local KingWorldLogic = require("present.KingWorldLogic")
  13. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  14. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  15. local AbsActLogic = require("absAct.AbsActLogic")
  16. local AbsActExcel = require("excel.absAct")
  17. local AbsActDefine = require("absAct.AbsActDefine")
  18. local YunYingExcel = require("excel.yunying")
  19. function sortomp(a, b)
  20. local r1 = AbsActExcel.rechargeBack[a].need
  21. local r2 = AbsActExcel.rechargeBack[b].need
  22. return r1 < r2
  23. end
  24. function query(human, id)
  25. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  26. -- local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_10)
  27. if not state then return end
  28. AbsActLogic.checkAbsActClean(human, id)
  29. local absAct = human.db.absAct[id]
  30. -- 没有活动数据
  31. if not absAct then
  32. return
  33. end
  34. local absConfig = AbsActExcel.absActivity[id]
  35. local msgRet = Msg.gc.GC_ABS_RECHARGE_BACK_QUERY
  36. msgRet.recharge = absAct.topupAcount or 0
  37. msgRet.maxCnt = 0
  38. msgRet.isEnd = 0
  39. msgRet.startTime = starTime
  40. msgRet.endTime = endTime
  41. msgRet.panelID = absConfig.panelID
  42. if absConfig.panelID == PanelDefine.PANEL_ID_3106 then
  43. msgRet.startTime = 0
  44. msgRet.endTime = 0
  45. end
  46. local maxCnt = 0
  47. local len = 0
  48. local getDb = absAct.rechargeBackGet or {}
  49. local list = {}
  50. for k, config in pairs(AbsActExcel.rechargeBack) do
  51. if config and config.actID == absConfig.actId then
  52. maxCnt = maxCnt + 1
  53. list[#list + 1] = k
  54. end
  55. end
  56. table.sort( list , sortomp )
  57. for k, h in ipairs(list) do
  58. local config = AbsActExcel.rechargeBack[h]
  59. if k > 3 and msgRet.recharge < AbsActExcel.rechargeBack[list[k - 1]].need then
  60. else
  61. len = len + 1
  62. local net = msgRet.list[len]
  63. net.id = h
  64. net.need = config.need
  65. net.state = getDb[h] and 1 or 0
  66. for j, h in ipairs(config.items) do
  67. Grid.makeItem(net.reward[j], h[1], h[2])
  68. end
  69. net.reward[0] = #config.items
  70. if len >= 10 then
  71. msgRet.isEnd = 0
  72. msgRet.list[0] = len
  73. Msg.send(msgRet, human.fd)
  74. len = 0
  75. end
  76. end
  77. end
  78. msgRet.maxCnt = maxCnt
  79. msgRet.isEnd = 1
  80. msgRet.list[0] = len
  81. -- Msg.tarce(msgRet)
  82. Msg.send(msgRet, human.fd)
  83. end
  84. function get(human, panelID, id)
  85. local absID
  86. if panelID == PanelDefine.PANEL_ID_3106 then
  87. absID = 11001
  88. elseif panelID == PanelDefine.PANEL_ID_3309 then
  89. absID = 7001
  90. end
  91. local state,endTime, starTime = AbsActLogic.isStarted(human, absID)
  92. if not state then
  93. return
  94. end
  95. --[[
  96. local state,absID = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_10)
  97. if not state then
  98. return
  99. end
  100. ]]
  101. AbsActLogic.checkAbsActClean(human, absID)
  102. local absConfig = AbsActExcel.absActivity[absID]
  103. if absConfig.type ~= AbsActDefine.ABS_ACT_TYPE_10 then
  104. return
  105. end
  106. local config = AbsActExcel.rechargeBack[id]
  107. if not config then return end
  108. if config.actID ~= absConfig.actId then
  109. return
  110. end
  111. local absAct = human.db.absAct[absID]
  112. -- 没有活动数据
  113. if not absAct then
  114. return
  115. end
  116. local rechargeNum = absAct.topupAcount or 0
  117. if config.need > rechargeNum then
  118. return
  119. end
  120. if absAct.rechargeBackGet and absAct.rechargeBackGet[id] then
  121. return
  122. end
  123. absAct.rechargeBackGet = absAct.rechargeBackGet or {}
  124. absAct.rechargeBackGet[id] = 1
  125. local logType = "abs_rechargeBack"
  126. if absConfig.panelID == PanelDefine.PANEL_ID_3106 then
  127. logType = "rechargeBack"
  128. end
  129. BagLogic.addItemList(human, config.items, logType)
  130. YunYingLogic.updateIcon(YYInfo[absID], human)
  131. YunYingLogic.sendGroupUpdate(YYInfo[absID], human, panelID)
  132. query(human, absID)
  133. end
  134. function onCharge(human, price, funcID)
  135. local state,endTime, starTime = AbsActLogic.isStarted(human, funcID)
  136. if not state then return end
  137. local absConfig = AbsActExcel.absActivity[funcID]
  138. if absConfig.type == AbsActDefine.ABS_ACT_TYPE_10 then
  139. AbsActLogic.checkAbsActClean(human, funcID)
  140. local absAct = human.db.absAct[funcID]
  141. absAct.topupAcount = absAct.topupAcount or 0
  142. absAct.topupAcount = absAct.topupAcount + price
  143. YunYingLogic.updateIcon(YYInfo[funcID], human)
  144. YunYingLogic.sendGroupUpdate(YYInfo[funcID], human, absConfig.panelID)
  145. end
  146. end
  147. function isRed(human,YYInfo, funcConfig)
  148. local id = funcConfig.funcID
  149. --[[
  150. if funcConfig.panelID == PanelDefine.PANEL_ID_3106 then
  151. id = 11001
  152. elseif funcConfig.panelID == PanelDefine.PANEL_ID_3309 then
  153. id = 7001
  154. end
  155. ]]
  156. local state,endTime, starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  157. if not state then
  158. return
  159. end
  160. AbsActLogic.checkAbsActClean(human, id)
  161. local absConfig = AbsActExcel.absActivity[id]
  162. local absAct = human.db.absAct[id]
  163. local now = os.time()
  164. local getDb = absAct.rechargeBackGet or {}
  165. local rechargeNum = absAct.topupAcount or 0
  166. for k, config in pairs(AbsActExcel.rechargeBack) do
  167. if config.actID == absConfig.actId and rechargeNum >= config.need and not getDb[k] then
  168. return true
  169. end
  170. end
  171. return false
  172. end
  173. function isOpen(human, YYInfo, funcConfig)
  174. local state,endTime, starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  175. if state then
  176. return true
  177. end
  178. --[[
  179. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_10)
  180. if not state then return end
  181. return true
  182. ]]
  183. end
  184. --
  185. function getLeftTime(human, YYInfo, funcConfig)
  186. if isOpen(human, YYInfo, funcConfig) then
  187. if funcConfig.panelID == PanelDefine.PANEL_ID_3309 then
  188. local absConfig = AbsActExcel.absActivity[7001]
  189. return absConfig.realEndTime - os.time()
  190. end
  191. end
  192. return 0
  193. end