RechargeRecord.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. --- 充值记录
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by 無心道(15388152619).
  4. --- DateTime: 2024/11/4 19:32
  5. ---
  6. RechargeRecord = {}
  7. RechargeRecord.__index = RechargeRecord
  8. local function __rechargeType()
  9. return "0"
  10. end
  11. local function __playerDbKey()
  12. return "T$recharge_data"
  13. end
  14. function RechargeRecord.get(actor)
  15. local obj = getplaydef(actor, __playerDbKey())
  16. return setmetatable(obj or {}, RechargeRecord)
  17. end
  18. function RechargeRecord:save(actor)
  19. setplaydef(actor, __playerDbKey(), self);
  20. end
  21. --- 充值表id充值记录
  22. function RechargeRecord:stallRecord(cfgId)
  23. local var = self[cfgId]
  24. if not var then
  25. var = {}
  26. self[cfgId] = var;
  27. end
  28. return var
  29. end
  30. --- 充值每日记录
  31. function RechargeRecord:dailyRecord()
  32. local var = self["dailyData"]
  33. if not var then
  34. var = {}
  35. var.updateTime = getbaseinfo("nowsec")
  36. var.totalMoney = 0
  37. self["dailyData"] = var
  38. end
  39. return var
  40. end
  41. --- 累充记录
  42. ---@param cfgId number 充值表id
  43. ---@param money number 充值金额
  44. ---@param count number 充值次数
  45. ---@param nowSec number 时间戳
  46. function RechargeRecord:addRecord(actor, cfgId, money, count, nowSec)
  47. RechargeRecord.firstTime(self, nowSec)
  48. RechargeRecord.lastTime(self, nowSec)
  49. RechargeRecord.totalCount(self, count)
  50. RechargeRecord.totalMoney(self, money);
  51. RechargeRecord.stallFirstTime(self, cfgId, nowSec)
  52. RechargeRecord.stallLastTime(self, cfgId, nowSec)
  53. RechargeRecord.stallTotalMoney(self, cfgId, money)
  54. RechargeRecord.stallTotalCount(self, cfgId, count)
  55. RechargeRecord.totalDailyMoney(self, money)
  56. local level = getbaseinfo(actor, "level")
  57. info(actor, "充值记录", "actor", actor, "level=" .. tostring(level), "本次充值id", cfgId, "金额", money, "次数", count, self)
  58. end
  59. --- 首次充值时间
  60. ---@param cfgId number 充值表id
  61. function RechargeRecord:stallFirstTime(cfgId, nowSec)
  62. local record = RechargeRecord.stallRecord(self, cfgId)
  63. if nowSec ~= nil and record["_firstTime"] == nil then
  64. record["_firstTime"] = nowSec
  65. end
  66. return record["_firstTime"] or 0
  67. end
  68. --- 最后一次充值时间
  69. ---@param cfgId number 充值表id
  70. function RechargeRecord:stallLastTime(cfgId, nowSec)
  71. local record = RechargeRecord.stallRecord(self, cfgId)
  72. if nowSec ~= nil then
  73. record["_lastTime"] = nowSec
  74. end
  75. return record["_lastTime"] or 0
  76. end
  77. --- 某一个充值id累计充值金额
  78. ---@param cfgId number 充值表id
  79. function RechargeRecord:stallTotalMoney(cfgId, changeMoney)
  80. local record = RechargeRecord.stallRecord(self, cfgId)
  81. if changeMoney ~= nil then
  82. record["_totalMoney"] = tonumber(record["_totalMoney"] or 0) + changeMoney
  83. end
  84. return record["_totalMoney"] or 0
  85. end
  86. --- 某一个充值id累计充值次数
  87. ---@param cfgId number 充值表id
  88. function RechargeRecord:stallTotalCount(cfgId, changeCount)
  89. local record = RechargeRecord.stallRecord(self, cfgId)
  90. if changeCount ~= nil then
  91. record["_totalCount"] = tonumber(record["_totalCount"] or 0) + changeCount
  92. end
  93. return record["_totalCount"] or 0
  94. end
  95. --- 获取玩家首次充值时间
  96. function RechargeRecord.getLastTime(actor)
  97. local data = RechargeRecord.get(actor)
  98. return data:firstTime();
  99. end
  100. --- 首次充值时间
  101. function RechargeRecord:firstTime(nowSec)
  102. if nowSec ~= nil and self["_firstTime"] == nil then
  103. self["_firstTime"] = nowSec
  104. end
  105. return self["_firstTime"] or 0
  106. end
  107. --- 获取玩家最后一次充值的时间,
  108. function RechargeRecord.getLastTime(actor)
  109. local data = RechargeRecord.get(actor)
  110. return data:lastTime();
  111. end
  112. --- 最后一次充值时间
  113. function RechargeRecord:lastTime(nowSec)
  114. if nowSec ~= nil then
  115. self["_lastTime"] = nowSec
  116. end
  117. return self["_lastTime"] or 0
  118. end
  119. --- 获取玩家的总充值额度
  120. function RechargeRecord.getTotalMoney(actor)
  121. local data = RechargeRecord.get(actor)
  122. return data:totalMoney();
  123. end
  124. --- 累充金额
  125. function RechargeRecord:totalMoney(changeMoney)
  126. if changeMoney ~= nil then
  127. self["_totalMoney"] = tonumber(self["_totalMoney"] or 0) + changeMoney
  128. end
  129. return self["_totalMoney"] or 0
  130. end
  131. --- 获取玩家的累计充值次数
  132. function RechargeRecord.getTotalCount(actor)
  133. local data = RechargeRecord.get(actor)
  134. return data:totalCount();
  135. end
  136. --- 累计充值次数
  137. function RechargeRecord:totalCount(changeCount)
  138. if changeCount ~= nil then
  139. self["_totalCount"] = tonumber(self["_totalCount"] or 0) + changeCount
  140. end
  141. return self["_totalCount"] or 0
  142. end
  143. --- 每日累充金额
  144. function RechargeRecord.getDailyTotalMoney(actor)
  145. local now = getbaseinfo("nowsec")
  146. local rechargeRecord = RechargeRecord.get(actor)
  147. --充值记录0点更新
  148. rechargeRecord:zeroRefresh(actor, now)
  149. return rechargeRecord:totalDailyMoney()
  150. end
  151. --- 每日累充金额
  152. function RechargeRecord:totalDailyMoney(changeMoney)
  153. local record = RechargeRecord.dailyRecord(self)
  154. if changeMoney ~= nil then
  155. record["totalMoney"] = tonumber(record["totalMoney"] or 0) + changeMoney
  156. end
  157. return record["totalMoney"] or 0
  158. end
  159. ---判定凌晨刷新
  160. function RechargeRecord:zeroRefresh(actor, zeroTime)
  161. local record = RechargeRecord.dailyRecord(self)
  162. if not TimeUtil.isSameDay(zeroTime, record.updateTime) then
  163. record.totalMoney = 0
  164. record.updateTime = zeroTime
  165. self:save(actor)
  166. return true
  167. end
  168. return false
  169. end
  170. ---凌晨事件
  171. function RechargeRecord.zeroEvent(actor)
  172. local now = getbaseinfo("nowsec")
  173. local rechargeRecord = RechargeRecord.get(actor)
  174. --充值记录0点更新
  175. rechargeRecord:zeroRefresh(actor, now)
  176. RechargeRecord.sendMsg(actor)
  177. end
  178. function RechargeRecord.login(actor)
  179. RechargeRecord.zeroEvent(actor)
  180. end
  181. function RechargeRecord.sendMsg(actor)
  182. local rechargeRecord = RechargeRecord.get(actor)
  183. local record = rechargeRecord:dailyRecord()
  184. local data = {}
  185. data["dailyTotalMoney"] = record.totalMoney
  186. data["totalMoney"] = rechargeRecord._totalMoney
  187. Recharge.resAction(actor, "0", "record", data)
  188. end
  189. -- 凌晨刷新事件
  190. ZeroEventListerTable:eventLister("0", "充值记录", RechargeRecord.zeroEvent, 9998)
  191. -- 注册登录事件
  192. LoginEventListerTable:eventLister("0", "充值记录", RechargeRecord.login, 9998)
  193. return RechargeRecord