RechargeRecord.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. info(actor, "充值记录", actor, "本次充值id", cfgId, "金额", money, "次数", count, self)
  57. end
  58. --- 首次充值时间
  59. ---@param cfgId number 充值表id
  60. function RechargeRecord:stallFirstTime(cfgId, nowSec)
  61. local record = RechargeRecord.stallRecord(self, cfgId)
  62. if nowSec ~= nil and record["_firstTime"] == nil then
  63. record["_firstTime"] = nowSec
  64. end
  65. return record["_firstTime"] or 0
  66. end
  67. --- 最后一次充值时间
  68. ---@param cfgId number 充值表id
  69. function RechargeRecord:stallLastTime(cfgId, nowSec)
  70. local record = RechargeRecord.stallRecord(self, cfgId)
  71. if nowSec ~= nil then
  72. record["_lastTime"] = nowSec
  73. end
  74. return record["_lastTime"] or 0
  75. end
  76. --- 某一个充值id累计充值金额
  77. ---@param cfgId number 充值表id
  78. function RechargeRecord:stallTotalMoney(cfgId, changeMoney)
  79. local record = RechargeRecord.stallRecord(self, cfgId)
  80. if changeMoney ~= nil then
  81. record["_totalMoney"] = tonumber(record["_totalMoney"] or 0) + changeMoney
  82. end
  83. return record["_totalMoney"] or 0
  84. end
  85. --- 某一个充值id累计充值次数
  86. ---@param cfgId number 充值表id
  87. function RechargeRecord:stallTotalCount(cfgId, changeCount)
  88. local record = RechargeRecord.stallRecord(self, cfgId)
  89. if changeCount ~= nil then
  90. record["_totalCount"] = tonumber(record["_totalCount"] or 0) + changeCount
  91. end
  92. return record["_totalCount"] or 0
  93. end
  94. --- 获取玩家首次充值时间
  95. function RechargeRecord.getLastTime(actor)
  96. local data = RechargeRecord.get(actor)
  97. return data:firstTime();
  98. end
  99. --- 首次充值时间
  100. function RechargeRecord:firstTime(nowSec)
  101. if nowSec ~= nil and self["_firstTime"] == nil then
  102. self["_firstTime"] = nowSec
  103. end
  104. return self["_firstTime"] or 0
  105. end
  106. --- 获取玩家最后一次充值的时间,
  107. function RechargeRecord.getLastTime(actor)
  108. local data = RechargeRecord.get(actor)
  109. return data:lastTime();
  110. end
  111. --- 最后一次充值时间
  112. function RechargeRecord:lastTime(nowSec)
  113. if nowSec ~= nil then
  114. self["_lastTime"] = nowSec
  115. end
  116. return self["_lastTime"] or 0
  117. end
  118. --- 获取玩家的总充值额度
  119. function RechargeRecord.getTotalMoney(actor)
  120. local data = RechargeRecord.get(actor)
  121. return data:totalMoney();
  122. end
  123. --- 累充金额
  124. function RechargeRecord:totalMoney(changeMoney)
  125. if changeMoney ~= nil then
  126. self["_totalMoney"] = tonumber(self["_totalMoney"] or 0) + changeMoney
  127. end
  128. return self["_totalMoney"] or 0
  129. end
  130. --- 获取玩家的累计充值次数
  131. function RechargeRecord.getTotalCount(actor)
  132. local data = RechargeRecord.get(actor)
  133. return data:totalCount();
  134. end
  135. --- 累计充值次数
  136. function RechargeRecord:totalCount(changeCount)
  137. if changeCount ~= nil then
  138. self["_totalCount"] = tonumber(self["_totalCount"] or 0) + changeCount
  139. end
  140. return self["_totalCount"] or 0
  141. end
  142. --- 每日累充金额
  143. function RechargeRecord.getDailyTotalMoney(actor)
  144. local now = getbaseinfo("nowsec")
  145. local rechargeRecord = RechargeRecord.get(actor)
  146. --充值记录0点更新
  147. rechargeRecord:zeroRefresh(actor, now)
  148. return rechargeRecord:totalDailyMoney()
  149. end
  150. --- 每日累充金额
  151. function RechargeRecord:totalDailyMoney(changeMoney)
  152. local record = RechargeRecord.dailyRecord(self)
  153. if changeMoney ~= nil then
  154. record["totalMoney"] = tonumber(record["totalMoney"] or 0) + changeMoney
  155. end
  156. return record["totalMoney"] or 0
  157. end
  158. ---判定凌晨刷新
  159. function RechargeRecord:zeroRefresh(actor, zeroTime)
  160. local record = RechargeRecord.dailyRecord(self)
  161. if not TimeUtil.isSameDay(zeroTime, record.updateTime) then
  162. record.totalMoney = 0
  163. record.updateTime = zeroTime
  164. self:save(actor)
  165. return true
  166. end
  167. return false
  168. end
  169. ---凌晨事件
  170. function RechargeRecord.zeroEvent(actor)
  171. local now = getbaseinfo("nowsec")
  172. local rechargeRecord = RechargeRecord.get(actor)
  173. --充值记录0点更新
  174. rechargeRecord:zeroRefresh(actor, now)
  175. RechargeRecord.sendMsg(actor)
  176. end
  177. function RechargeRecord.login(actor)
  178. RechargeRecord.zeroEvent(actor)
  179. end
  180. function RechargeRecord.sendMsg(actor)
  181. local rechargeRecord = RechargeRecord.get(actor)
  182. local record = rechargeRecord:dailyRecord()
  183. local data = {}
  184. data["dailyTotalMoney"] = record.totalMoney
  185. data["totalMoney"] = rechargeRecord._totalMoney
  186. Recharge.resAction(actor, "0", "record", data)
  187. end
  188. -- 凌晨刷新事件
  189. ZeroEventListerTable:eventLister("0", "充值记录", RechargeRecord.zeroEvent, 9998)
  190. -- 注册登录事件
  191. LoginEventListerTable:eventLister("0", "充值记录", RechargeRecord.login, 9998)
  192. return RechargeRecord