miduo_client/Assets/ManagedResources/~Lua/Modules/Common/MoneyUtil.lua

77 lines
1.5 KiB
Lua

MoneyUtil = {}
local this = MoneyUtil
this.RMB2O = {}
this.MT = 1
function this.Initialize()
this.MT = ConfigManager.GetConfigData(ConfigName.SpecialConfig, 79).Value
local er = ConfigManager.GetConfig(ConfigName.ExchangeRate)
for _, v in ConfigPairs(er) do
this.RMB2O[v.Price_1] = v
end
end
-- 获取相应的金额
function this.GetMoney(_rmbp)
local rmbp = tonumber(_rmbp)
if rmbp <= 0 then
return rmbp
end
if not this.RMB2O[rmbp] then
LogError("表 ExchangeRate 错误: 不包含档位:"..tostring(rmbp))
return 0
end
local m = this.RMB2O[rmbp]["Price_"..this.MT]
if not m then
LogError("表 ExchangeRate 错误: 档位:"..tostring(rmbp).." , 未找到对应的货币类型 "..this.MT)
return 0
end
return m
end
function this.GetCurMoneyType()
return this.MT
end
local _t2m = {
[1] = "",
[2] = "$",
}
-- 获取货币符号
function this.GetMoneyMark(mt)
if not mt then
mt = this.MT
end
mt = tonumber(mt)
if _t2m[mt] then
return _t2m[mt]
end
return _t2m[1]
end
-- 获取货币单位名称
local _t2n = {
[1] = Language[10383],
[2] = "$%s",
}
function this.GetMoneyUnitName(mt)
if not mt then
mt = this.MT
end
mt = tonumber(mt)
if _t2n[mt] then
return _t2n[mt]
end
return _t2n[1]
end
function this.GetMoneyUnitNameWithMoney(money)
local formater = this.GetMoneyUnitName()
return string.format(formater, money)
end
return MoneyUtil