--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by admin. --- DateTime: 2024/10/28 13:50 --- --- 定义一个类 RechargeData = { key = function() return "recharge" end, get = function() local obj = getdata(RechargeData.key()) local var = setmetatable(obj or {}, RechargeData) RechargeData.__index = RechargeData return var end, save = function(self) setdata(RechargeData.key(), self); end, --- 增加金额 totalMoney = function(self, money) if self.rechargeTotalMoney == nil then self.rechargeTotalMoney = 0; end if money ~= nil then self.rechargeTotalMoney = self.rechargeTotalMoney + money end return self.rechargeTotalMoney end, ---充值挡位 rechargeStallData = function(self, stallId) if not self.stallInfo then self.stallInfo = {} end local var = StallInfo.get(self.stallInfo[stallId]) self.stallInfo[stallId] = var return var end, } StallInfo = { get = function(data) gameDebug.print("dddd", _VERSION, data) local var = setmetatable(data or {}, StallInfo) StallInfo.__index = StallInfo return var end, ---获取当前挡位充值次数 rechargeCount = function(self, count) if self.count == nil then self.count = 0 end if count ~= nil then self.count = self.count + count end return self.count end, ---设置或者获取首次充值时间 firstRechargeTime = function(self, time) if time ~= nil then self.firstTime = time end return self.firstTime or 0 end, ---重置首充时间 againRechargeTime = function(self, time) if time ~= nil then self.againTime = time end return self.againTime or 0 end, ---重置首充时间 checkAgainRechargeTime = function(self, cfg, now) if self:firstRechargeTime() == 0 then return true --表示尚未首充过 end local resetTime = tonumber(cfg["resettime"]) if self:againRechargeTime() == 0 then local day = math.ceil(((now - self:firstRechargeTime()) / (24 * 60 * 60 * 1000))) if day > resetTime then return true end else local day = math.ceil((now - self:againRechargeTime()) / (24 * 60 * 60 * 1000)) if day > resetTime then return true end end return false end, } function printData() local rechargeData = RechargeData.get(); rechargeData:totalMoney(50) gameDebug.printType(rechargeData) local stallInfo = rechargeData:rechargeStallData("1") stallInfo:firstRechargeTime("1111") gameDebug.printType(stallInfo) local stallInfo2 = rechargeData:rechargeStallData("1") gameDebug.printType(stallInfo2) gameDebug.printType(rechargeData) rechargeData:save() gameDebug.printType(rechargeData) print("==============================") end