diff --git a/web/src/components/topup/modals/TopupHistoryModal.jsx b/web/src/components/topup/modals/TopupHistoryModal.jsx index 1abd45df6260..b3a4e4ae57f3 100644 --- a/web/src/components/topup/modals/TopupHistoryModal.jsx +++ b/web/src/components/topup/modals/TopupHistoryModal.jsx @@ -34,7 +34,7 @@ import { } from '@douyinfe/semi-illustrations'; import { Coins } from 'lucide-react'; import { IconSearch } from '@douyinfe/semi-icons'; -import { API, timestamp2string } from '../../../helpers'; +import { API, timestamp2string, convertUSDToCurrency, convertCNYToCurrency } from '../../../helpers'; import { isAdmin } from '../../../helpers/utils'; import { useIsMobile } from '../../../hooks/common/useIsMobile'; const { Text } = Typography; @@ -56,6 +56,25 @@ const PAYMENT_METHOD_MAP = { wxpay: '微信', }; +// Providers that store Money in CNY; all others store Money in USD. +const CNY_PROVIDERS = new Set(['epay']); +const CNY_METHODS = new Set(['alipay', 'wxpay']); + +function renderPaymentAmount(money, record) { + if (money == null || isNaN(money)) { + return -; + } + const provider = record?.payment_provider || ''; + const method = record?.payment_method || ''; + const isCNY = + CNY_PROVIDERS.has(provider) || + (provider === '' && CNY_METHODS.has(method)); + const display = isCNY + ? convertCNYToCurrency(money) + : convertUSDToCurrency(money); + return {display}; +} + const TopupHistoryModal = ({ visible, onCancel, t }) => { const [loading, setLoading] = useState(false); const [topups, setTopups] = useState([]); @@ -207,7 +226,7 @@ const TopupHistoryModal = ({ visible, onCancel, t }) => { title: t('支付金额'), dataIndex: 'money', key: 'money', - render: (money) => ¥{money.toFixed(2)}, + render: (money, record) => renderPaymentAmount(money, record), }, { title: t('状态'), diff --git a/web/src/helpers/render.jsx b/web/src/helpers/render.jsx index f5ce1f0391df..a03dbc64300d 100644 --- a/web/src/helpers/render.jsx +++ b/web/src/helpers/render.jsx @@ -1139,6 +1139,26 @@ export function convertUSDToCurrency(usdAmount, digits = 2) { return symbol + convertedAmount.toFixed(digits); } +/** + * 将人民币金额转换为当前选择的货币 + * @param {number} cnyAmount - 人民币金额 + * @param {number} digits - 小数位数 + * @returns {string} - 格式化后的货币字符串 + */ +export function convertCNYToCurrency(cnyAmount, digits = 2) { + const { symbol, type } = getCurrencyConfig(); + if (type === 'CNY') { + return symbol + Number(cnyAmount).toFixed(digits); + } + // Convert CNY → USD using usd_exchange_rate, then to display currency + let usdExchangeRate = 7; + try { + const s = JSON.parse(localStorage.getItem('status') || '{}'); + usdExchangeRate = s?.usd_exchange_rate || 7; + } catch (e) {} + return convertUSDToCurrency(cnyAmount / usdExchangeRate, digits); +} + export function renderQuota(quota, digits = 2) { let quotaPerUnit = localStorage.getItem('quota_per_unit'); const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD';