123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- --- 充值记录
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by 無心道(15388152619).
- --- DateTime: 2024/11/4 19:32
- ---
- RechargeRecord = {}
- RechargeRecord.__index = RechargeRecord
- local function __rechargeType()
- return "0"
- end
- local function __playerDbKey()
- return "T$recharge_data"
- end
- function RechargeRecord.get(actor)
- local obj = getplaydef(actor, __playerDbKey())
- return setmetatable(obj or {}, RechargeRecord)
- end
- function RechargeRecord:save(actor)
- setplaydef(actor, __playerDbKey(), self);
- end
- --- 充值表id充值记录
- function RechargeRecord:stallRecord(cfgId)
- local var = self[cfgId]
- if not var then
- var = {}
- self[cfgId] = var;
- end
- return var
- end
- --- 充值每日记录
- function RechargeRecord:dailyRecord()
- local var = self["dailyData"]
- if not var then
- var = {}
- var.updateTime = getbaseinfo("nowsec")
- var.totalMoney = 0
- self["dailyData"] = var
- end
- return var
- end
- --- 累充记录
- ---@param cfgId number 充值表id
- ---@param money number 充值金额
- ---@param count number 充值次数
- ---@param nowSec number 时间戳
- function RechargeRecord:addRecord(actor, cfgId, money, count, nowSec)
- RechargeRecord.firstTime(self, nowSec)
- RechargeRecord.lastTime(self, nowSec)
- RechargeRecord.totalCount(self, count)
- RechargeRecord.totalMoney(self, money);
- RechargeRecord.stallFirstTime(self, cfgId, nowSec)
- RechargeRecord.stallLastTime(self, cfgId, nowSec)
- RechargeRecord.stallTotalMoney(self, cfgId, money)
- RechargeRecord.stallTotalCount(self, cfgId, count)
- RechargeRecord.totalDailyMoney(self, money)
- info(actor, "充值记录", actor, "本次充值id", cfgId, "金额", money, "次数", count, self)
- end
- --- 首次充值时间
- ---@param cfgId number 充值表id
- function RechargeRecord:stallFirstTime(cfgId, nowSec)
- local record = RechargeRecord.stallRecord(self, cfgId)
- if nowSec ~= nil and record["_firstTime"] == nil then
- record["_firstTime"] = nowSec
- end
- return record["_firstTime"] or 0
- end
- --- 最后一次充值时间
- ---@param cfgId number 充值表id
- function RechargeRecord:stallLastTime(cfgId, nowSec)
- local record = RechargeRecord.stallRecord(self, cfgId)
- if nowSec ~= nil then
- record["_lastTime"] = nowSec
- end
- return record["_lastTime"] or 0
- end
- --- 某一个充值id累计充值金额
- ---@param cfgId number 充值表id
- function RechargeRecord:stallTotalMoney(cfgId, changeMoney)
- local record = RechargeRecord.stallRecord(self, cfgId)
- if changeMoney ~= nil then
- record["_totalMoney"] = tonumber(record["_totalMoney"] or 0) + changeMoney
- end
- return record["_totalMoney"] or 0
- end
- --- 某一个充值id累计充值次数
- ---@param cfgId number 充值表id
- function RechargeRecord:stallTotalCount(cfgId, changeCount)
- local record = RechargeRecord.stallRecord(self, cfgId)
- if changeCount ~= nil then
- record["_totalCount"] = tonumber(record["_totalCount"] or 0) + changeCount
- end
- return record["_totalCount"] or 0
- end
- --- 获取玩家首次充值时间
- function RechargeRecord.getLastTime(actor)
- local data = RechargeRecord.get(actor)
- return data:firstTime();
- end
- --- 首次充值时间
- function RechargeRecord:firstTime(nowSec)
- if nowSec ~= nil and self["_firstTime"] == nil then
- self["_firstTime"] = nowSec
- end
- return self["_firstTime"] or 0
- end
- --- 获取玩家最后一次充值的时间,
- function RechargeRecord.getLastTime(actor)
- local data = RechargeRecord.get(actor)
- return data:lastTime();
- end
- --- 最后一次充值时间
- function RechargeRecord:lastTime(nowSec)
- if nowSec ~= nil then
- self["_lastTime"] = nowSec
- end
- return self["_lastTime"] or 0
- end
- --- 获取玩家的总充值额度
- function RechargeRecord.getTotalMoney(actor)
- local data = RechargeRecord.get(actor)
- return data:totalMoney();
- end
- --- 累充金额
- function RechargeRecord:totalMoney(changeMoney)
- if changeMoney ~= nil then
- self["_totalMoney"] = tonumber(self["_totalMoney"] or 0) + changeMoney
- end
- return self["_totalMoney"] or 0
- end
- --- 获取玩家的累计充值次数
- function RechargeRecord.getTotalCount(actor)
- local data = RechargeRecord.get(actor)
- return data:totalCount();
- end
- --- 累计充值次数
- function RechargeRecord:totalCount(changeCount)
- if changeCount ~= nil then
- self["_totalCount"] = tonumber(self["_totalCount"] or 0) + changeCount
- end
- return self["_totalCount"] or 0
- end
- --- 每日累充金额
- function RechargeRecord.getDailyTotalMoney(actor)
- local now = getbaseinfo("nowsec")
- local rechargeRecord = RechargeRecord.get(actor)
- --充值记录0点更新
- rechargeRecord:zeroRefresh(actor, now)
- return rechargeRecord:totalDailyMoney()
- end
- --- 每日累充金额
- function RechargeRecord:totalDailyMoney(changeMoney)
- local record = RechargeRecord.dailyRecord(self)
- if changeMoney ~= nil then
- record["totalMoney"] = tonumber(record["totalMoney"] or 0) + changeMoney
- end
- return record["totalMoney"] or 0
- end
- ---判定凌晨刷新
- function RechargeRecord:zeroRefresh(actor, zeroTime)
- local record = RechargeRecord.dailyRecord(self)
- if not TimeUtil.isSameDay(zeroTime, record.updateTime) then
- record.totalMoney = 0
- record.updateTime = zeroTime
- self:save(actor)
- return true
- end
- return false
- end
- ---凌晨事件
- function RechargeRecord.zeroEvent(actor)
- local now = getbaseinfo("nowsec")
- local rechargeRecord = RechargeRecord.get(actor)
- --充值记录0点更新
- rechargeRecord:zeroRefresh(actor, now)
- RechargeRecord.sendMsg(actor)
- end
- function RechargeRecord.login(actor)
- RechargeRecord.zeroEvent(actor)
- end
- function RechargeRecord.sendMsg(actor)
- local rechargeRecord = RechargeRecord.get(actor)
- local record = rechargeRecord:dailyRecord()
- local data = {}
- data["dailyTotalMoney"] = record.totalMoney
- data["totalMoney"] = rechargeRecord._totalMoney
- Recharge.resAction(actor, "0", "record", data)
- end
- -- 凌晨刷新事件
- ZeroEventListerTable:eventLister("0", "充值记录", RechargeRecord.zeroEvent, 9998)
- -- 注册登录事件
- LoginEventListerTable:eventLister("0", "充值记录", RechargeRecord.login, 9998)
- return RechargeRecord
|