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

94 lines
2.0 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
MoneyUtil = {}
2020-08-22 15:31:14 +08:00
local this = MoneyUtil
this.RMB2O = {}
this.MT = MoneyType.RMB
2020-08-22 15:31:14 +08:00
function this.Initialize()
this.MT = tonumber(ConfigManager.GetConfigData(ConfigName.SpecialConfig, 79).Value)
2020-08-22 15:31:14 +08:00
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)
2020-09-27 18:27:20 +08:00
if rmbp <= 0 then
return rmbp
end
2020-08-22 15:31:14 +08:00
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] = "$",
2020-08-22 15:31:14 +08:00
}
-- 获取货币符号
function this.GetMoneyMark(mt)
if not mt then
mt = this.MT
end
if _t2m[mt] then
return _t2m[mt]
end
return _t2m[MoneyType.RMB]
2020-08-22 15:31:14 +08:00
end
-- 获取货币单位名称
local _t2n = {
2021-04-09 12:26:35 +08:00
[MoneyType.RMB] = Language[10383],
[MoneyType.USD] = "$%s",
2020-08-22 15:31:14 +08:00
}
function this.GetMoneyUnitName(mt)
if not mt then
mt = this.MT
end
if _t2n[mt] then
return _t2n[mt]
end
return _t2n[MoneyType.RMB]
2020-08-22 15:31:14 +08:00
end
2021-03-18 11:31:10 +08:00
function this.GetMoneyUnitNameWithMoney(money)
local formater = this.GetMoneyUnitName()
2021-04-07 16:38:26 +08:00
return string.format(formater, this.GetMoney(money))
2021-03-18 11:31:10 +08:00
end
2021-07-07 11:28:50 +08:00
-- 获取货币单位名称
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
2020-08-22 15:31:14 +08:00
return MoneyUtil