94 lines
2.0 KiB
Lua
94 lines
2.0 KiB
Lua
MoneyUtil = {}
|
|
local this = MoneyUtil
|
|
|
|
|
|
this.RMB2O = {}
|
|
this.MT = MoneyType.RMB
|
|
|
|
|
|
function this.Initialize()
|
|
this.MT = tonumber(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 = {
|
|
[MoneyType.RMB] = "¥",
|
|
[MoneyType.USD] = "$",
|
|
}
|
|
-- 获取货币符号
|
|
function this.GetMoneyMark(mt)
|
|
if not mt then
|
|
mt = this.MT
|
|
end
|
|
if _t2m[mt] then
|
|
return _t2m[mt]
|
|
end
|
|
return _t2m[MoneyType.RMB]
|
|
end
|
|
|
|
-- 获取货币单位名称
|
|
local _t2n = {
|
|
[MoneyType.RMB] = Language[10383],
|
|
[MoneyType.USD] = "$%s",
|
|
}
|
|
function this.GetMoneyUnitName(mt)
|
|
if not mt then
|
|
mt = this.MT
|
|
end
|
|
if _t2n[mt] then
|
|
return _t2n[mt]
|
|
end
|
|
return _t2n[MoneyType.RMB]
|
|
end
|
|
|
|
function this.GetMoneyUnitNameWithMoney(money)
|
|
local formater = this.GetMoneyUnitName()
|
|
return string.format(formater, this.GetMoney(money))
|
|
end
|
|
|
|
-- 获取货币单位名称
|
|
local _t2n2 = {
|
|
[MoneyType.RMB] = "%s\n元",
|
|
[MoneyType.USD] = "$\n%s",
|
|
}
|
|
function this.GetMoneyUnitName1(mt)
|
|
if not mt then
|
|
mt = this.MT
|
|
end
|
|
if _t2n2[mt] then
|
|
return _t2n2[mt]
|
|
end
|
|
return _t2n2[MoneyType.RMB]
|
|
end
|
|
function this.GetMoneyUnitNameWithMoney1(money)
|
|
local formater = this.GetMoneyUnitName1()
|
|
return string.format(formater, this.GetMoney(money))
|
|
end
|
|
|
|
|
|
return MoneyUtil |