Files
monkey-ai-web/src/pages/Organization/OrgRecharge.jsx
T
qiubaishen 6160a23117 sync: 同步总仓库 luoguang/monkey-ai weiyuan@bfdfb339 的 web/ 改动
同步基准:总仓库 a2ca13cb(= 本仓库初始导入 d8f3aee2)
范围:a2ca13cb..bfdfb339 中触及 web/ 的提交(不含 web/.claude/settings.local.json)

- 8490ac02 feat(aliyun): integrate Wan 3 and Qwen Image models
- 2aff08ec perf(analytics): 运营看板概览改读汇总表,首屏从 19s 降到 0.4s
- dc69335e feat(experience): 体验中心图像/视频创作升级(能力 schema、估价、新创作台)
- b059c657 fix(org): 下线 /org/create 自助加入企业页与 POST /api/org/join
- 4fcf47e6 fix(i18n): 修复中/英/韩/繁体多语言错乱,补齐日/越/泰译文
- e4c301d5 fix: merge enterprise task record date filters
- c9369b95 feat: expose enterprise image and video task records
- a410fee5 feat(claude): 无断点请求自动注入 cache_control 断点(方案 2)
- 521b3376 feat(claude): 缓存命中率优化——上游粘性路由 + 缓存时长强制改写
- 73b615dd feat(pricing): 企业成员不论登录身份均按所属企业等级计价与扣费
- f73f55c3 feat(client): 新增 WeyAi 版本说明管理与公开读取接口
- 8cdf1994 fix(topup): reset amount when switching from PayPal
- 93a4ac34 feat(baidu): configure Seedance liveness header by channel
- cb1818c5 fix(weyai): 按评审修正内容清理竞态、默认适用端与中文退回(M21)
- 04214d83 feat(weyai): WeyAi 内容管理与客户端内容接口(M21 第二部分)
- e3c4a57c feat(weyai): 设置页新增 WeyAi 页签与内容专用 COS 桶(M21 第一部分)
- b5ee8e70 fix(auth): 会话角色/状态以 DB 为准,修复提升管理员后管理接口报权限不足
- e4618fc2 fix: 修复企业看板日志聚合死循环导致 CPU 打满,并降低看板查询开销
- 584aad52 style(web): 个人中心侧边栏按 prettier 换行
- b8d87064 fix: 小程序教程隐藏充值后保留原步骤编号,企业充值判断直接用 isMiniProgramWebView
- eee7f5b2 fix: 小程序里企业首页不落到充值页,隐藏钱包入口与教程充值步骤
- 8b254d49 fix: 小程序里隐藏企业充值入口与页面
- a67661b4 fix(web): 小程序里个人中心默认页跳过充值和发票,避免来回跳转
- cff6c543 feat(web): WeyAi 小程序里打开个人中心时不出现充值和开票
- c6c99eb6 feat(billing): Claude 全部缓存写入统一按 1h 倍率计费
- 0699d1bf fix(web): 小程序 web-view 里注册页同样只显示站内方式
- 04853331 feat(web): WeyAi 小程序 web-view 里登录页只显示站内登录方式
2026-11-10 11:05:34 +08:00

858 lines
30 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { timestamp2string } from '../../helpers/utils';
import { useTranslation } from 'react-i18next';
import {
Typography,
Button,
Spin,
Table,
Tag,
InputNumber,
Select,
} from '@douyinfe/semi-ui';
import {
CreditCard,
Wallet,
TrendingUp,
Coins,
History,
CheckCircle,
Clock,
XCircle,
Pencil,
} from 'lucide-react';
import {
API,
showError,
showInfo,
showSuccess,
renderQuota,
getQuotaPerUnit,
} from '../../helpers';
import AmountCard from '../Recharge/AmountCard';
import WechatQRModal from '../../components/topup/modals/WechatQRModal';
import PaymentConfirmModal from '../../components/topup/modals/PaymentConfirmModal';
import OrgPageHeader from './components/OrgPageHeader';
import OrgPanel from './components/OrgPanel';
import { orgStatusColor } from './components/orgStatus';
import {
formatPayPalUSD,
getPayPalReturnState,
parsePayPalQuote,
requestPayPalOrder,
removePayPalReturnState,
} from '../../helpers/paypalPayment';
const { Text, Title } = Typography;
const OrgRecharge = ({ orgId }) => {
const { t } = useTranslation();
// 企业信息
const [orgQuota, setOrgQuota] = useState(0);
const [orgUsedQuota, setOrgUsedQuota] = useState(0);
// 充值配置
const [presetAmounts, setPresetAmounts] = useState([]);
const [payMethods, setPayMethods] = useState([]);
const [enableWechatTopUp, setEnableWechatTopUp] = useState(false);
const [enableAlipayTopUp, setEnableAlipayTopUp] = useState(false);
const [enablePayPalTopUp, setEnablePayPalTopUp] = useState(false);
const [infoLoading, setInfoLoading] = useState(true);
// 充值交互状态
const [selectedPreset, setSelectedPreset] = useState(null);
const [selectedPresetObj, setSelectedPresetObj] = useState(null);
const [payWay, setPayWay] = useState('');
const [confirmOpen, setConfirmOpen] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const [amountLoading, setAmountLoading] = useState(false);
const [payPalQuote, setPayPalQuote] = useState(null);
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
const [isCustomMode, setIsCustomMode] = useState(false);
const [customAmount, setCustomAmount] = useState(null);
const [customUnit, setCustomUnit] = useState(1000); // 1000=千 / 10000=万
const customEffectiveAmount = useMemo(() => {
if (!customAmount || customAmount < 1) return 0;
return Math.floor(Number(customAmount)) * customUnit;
}, [customAmount, customUnit]);
const customValid = customEffectiveAmount >= 1000;
// 当前生效的金额/折扣/赠送(自定义优先)
const effectiveAmountYuan = isCustomMode
? customEffectiveAmount
: selectedPresetObj?.value || 0;
const effectiveDiscount = isCustomMode
? 1.0
: selectedPresetObj?.discount || 1.0;
const effectiveBonus = isCustomMode ? 0 : selectedPresetObj?.bonus || 0;
// 微信二维码
const [wechatQRVisible, setWechatQRVisible] = useState(false);
const [wechatOrderData, setWechatOrderData] = useState(null);
// 充值记录
const [history, setHistory] = useState([]);
const [historyTotal, setHistoryTotal] = useState(0);
const [historyPage, setHistoryPage] = useState(1);
const [historyLoading, setHistoryLoading] = useState(false);
const [refreshHistory, setRefreshHistory] = useState(0);
const orgHeaders = { 'X-Org-Id': String(orgId) };
// 获取企业配额
const fetchOrgQuota = useCallback(async () => {
try {
const res = await API.get('/api/org/quota', { headers: orgHeaders });
if (res.data.success) {
const { quota, used_quota } = res.data.data;
setOrgQuota(quota || 0);
setOrgUsedQuota(used_quota || 0);
}
} catch (e) {
// ignore
}
}, [orgId]);
// 获取充值配置
const fetchTopUpInfo = useCallback(async () => {
setInfoLoading(true);
try {
const res = await API.get('/api/org/topup/info', { headers: orgHeaders });
if (res.data.success) {
const data = res.data.data;
setEnableWechatTopUp(data.enable_wechat_topup || false);
setEnableAlipayTopUp(data.enable_alipay_topup || false);
setEnablePayPalTopUp(data.enable_paypal_topup || false);
setPayMethods(data.pay_methods || []);
if (data.amount_options_v2 && data.amount_options_v2.length > 0) {
const sorted = [...data.amount_options_v2].sort(
(a, b) => (a.sort || 0) - (b.sort || 0),
);
setPresetAmounts(
sorted.map((opt) => ({
id: opt.id,
value: opt.amount,
discount: opt.discount || 1.0,
label: opt.label,
badge: opt.badge,
badgeColor: opt.badge_color,
isRecommend: opt.is_recommend,
isHot: opt.is_hot,
bonus: opt.bonus,
minVipLevel: opt.min_vip_level,
})),
);
}
}
} catch (e) {
showError(t('获取充值配置失败'));
} finally {
setInfoLoading(false);
}
}, [orgId]);
// 获取充值记录
const fetchHistory = useCallback(
async (page = 1) => {
setHistoryLoading(true);
try {
const res = await API.get(`/api/org/topup?p=${page}&page_size=10`, {
headers: orgHeaders,
});
if (res.data.success) {
const data = res.data.data;
setHistory(data.items || []);
setHistoryTotal(data.total || 0);
}
} catch (e) {
// ignore
} finally {
setHistoryLoading(false);
}
},
[orgId],
);
useEffect(() => {
fetchOrgQuota();
fetchTopUpInfo();
}, [fetchOrgQuota, fetchTopUpInfo]);
useEffect(() => {
fetchHistory(historyPage);
}, [fetchHistory, historyPage, refreshHistory]);
useEffect(() => {
const result = getPayPalReturnState(window.location.search);
if (!result) return;
if (result.status === 'success') showSuccess(t('PayPal 充值成功'));
else if (result.status === 'pending')
showInfo(t('PayPal 支付处理中,请稍后查看充值记录'));
else if (result.status === 'cancelled') showInfo(t('已取消 PayPal 支付'));
else showError(t('PayPal 支付确认失败,请稍后重试'));
fetchOrgQuota();
setRefreshHistory((previous) => previous + 1);
window.history.replaceState(
{},
'',
removePayPalReturnState(window.location.href),
);
// The callback query must be consumed exactly once on page entry.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const selectPreset = (preset) => {
setSelectedPreset(preset.id);
setSelectedPresetObj(preset);
setIsCustomMode(false);
setCustomAmount(null);
};
const handleCustomAmountChange = (v) => {
setCustomAmount(v);
if (v && Number(v) > 0) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
} else {
setIsCustomMode(false);
}
};
const handleCustomUnitChange = (v) => {
setCustomUnit(v);
if (customAmount && Number(customAmount) > 0) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
}
};
// 自定义充值快速选择档位
const customQuickPicks = [
{ amount: 1, unit: 1000 },
{ amount: 5, unit: 1000 },
{ amount: 1, unit: 10000 },
{ amount: 5, unit: 10000 },
{ amount: 10, unit: 10000 },
];
const applyCustomQuickPick = (amount, unit) => {
setCustomAmount(amount);
setCustomUnit(unit);
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
};
// 自定义充值预览额度(与后端 service.CalculateQuota 一致:originalMoney * QuotaPerUnit + bonus,自定义 bonus=0)
const customPreviewQuota =
customEffectiveAmount > 0
? customEffectiveAmount * (getQuotaPerUnit() || 500000)
: 0;
const handlePreTopUp = async (paymentType) => {
if (isCustomMode) {
if (!customValid) {
showError(t('自定义充值金额最少为 1000 元'));
return;
}
} else if (!selectedPresetObj) {
showError(t('请先选择充值金额'));
return;
}
setPayWay(paymentType);
if (paymentType === 'paypal') {
if (!enablePayPalTopUp) {
showError(t('管理员未开启 PayPal 充值!'));
return;
}
setAmountLoading(true);
try {
const response = await API.post(
'/api/org/topup/paypal/amount',
buildPayBody(),
{ headers: orgHeaders },
);
if (!response.data.success) {
throw new Error(response.data.message || t('获取金额失败'));
}
setPayPalQuote(parsePayPalQuote(response));
} catch (error) {
showError(error?.message || t('获取金额失败'));
return;
} finally {
setAmountLoading(false);
}
}
setConfirmOpen(true);
};
const buildPayBody = () =>
isCustomMode
? { custom_amount: customEffectiveAmount }
: { amount_option_id: selectedPresetObj.id };
const isMobile = /iPhone|Android|iPad|Mobile/i.test(navigator.userAgent);
const handleConfirmPay = async () => {
if (!isCustomMode && !selectedPresetObj) return;
if (isCustomMode && !customValid) return;
setConfirmLoading(true);
try {
let res;
const payBody = buildPayBody();
if (payWay === 'wxpay' && enableWechatTopUp) {
const wechatEndpoint = isMobile
? '/api/org/topup/wechat/h5'
: '/api/org/topup/wechat/native';
res = await API.post(wechatEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
if (isMobile) {
// H5:直接跳转微信支付页
window.location.href = res.data.data.h5_url;
setConfirmOpen(false);
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
} else {
// Native:弹出二维码
setWechatOrderData(res.data.data);
setConfirmOpen(false);
setWechatQRVisible(true);
}
return;
}
} else if (payWay === 'paypal' && enablePayPalTopUp) {
res = await requestPayPalOrder(
API,
'/api/org/topup/paypal',
{ ...payBody, quote_token: payPalQuote?.quoteToken },
{ headers: orgHeaders, skipErrorHandler: true },
);
if (res.data.success && res.data.data?.approval_url) {
setPayPalQuote(parsePayPalQuote(res));
window.location.href = res.data.data.approval_url;
return;
}
if (
res.status === 202 &&
res.data?.message === 'PAYPAL_ORDER_CREATING'
) {
showInfo(t('PayPal 订单创建中,请稍后重试'));
return;
}
} else if (payWay === 'alipay' && enableAlipayTopUp) {
const alipayEndpoint = isMobile
? '/api/org/topup/alipay/wap'
: '/api/org/topup/alipay/pc';
res = await API.post(alipayEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
// Safari 会拦截 await 之后的 window.open(用户手势已过期),改为同标签跳转
const isSafari =
navigator.userAgent.indexOf('Safari') > -1 &&
navigator.userAgent.indexOf('Chrome') < 1;
if (isSafari) {
window.location.href = res.data.data.pay_url;
return;
}
window.open(res.data.data.pay_url, '_blank');
setConfirmOpen(false);
// 用户从支付宝标签页切回时自动刷新余额和记录
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
return;
}
}
// 失败处理
const msg = res?.data?.message || t('支付请求失败');
showError(msg);
} catch (e) {
const code = e?.response?.data?.message;
if (payWay === 'paypal' && code?.startsWith('PAYPAL_QUOTE_')) {
try {
const response = await API.post(
'/api/org/topup/paypal/amount',
buildPayBody(),
{ headers: orgHeaders },
);
if (!response.data.success) throw new Error(response.data.message);
setPayPalQuote(parsePayPalQuote(response));
showInfo(t('PayPal 报价已更新,请重新确认'));
} catch {
showError(t('获取金额失败'));
}
} else {
showError(e?.response?.data?.message || t('支付请求失败'));
}
} finally {
setConfirmLoading(false);
}
};
const handleWechatComplete = (success) => {
setWechatQRVisible(false);
setWechatOrderData(null);
if (success) {
showSuccess(t('充值成功!'));
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
}
};
const renderAmount = () => {
if (payWay === 'paypal') {
return formatPayPalUSD(payPalQuote?.payAmount);
}
if (effectiveAmountYuan <= 0) return '';
const pay = effectiveAmountYuan * effectiveDiscount;
return `${pay.toFixed(2)} ${t('元')}`;
};
// 充值记录状态渲染
const renderStatus = (status) => {
const map = {
success: {
icon: <CheckCircle size={12} />,
text: t('成功'),
},
pending: {
icon: <Clock size={12} />,
text: t('待支付'),
},
expired: { icon: <XCircle size={12} />, text: t('已过期') },
};
const s = map[status] || { icon: null, text: status };
return (
<Tag
color={orgStatusColor(status)}
size='small'
className='flex items-center gap-1'
>
{s.icon}
{s.text}
</Tag>
);
};
const historyColumns = [
{
title: t('订单号'),
dataIndex: 'trade_no',
render: (v) => (
<Text size='small' className='font-mono'>
{v}
</Text>
),
ellipsis: true,
},
{
title: t('金额'),
dataIndex: 'money',
render: (v) => <Text size='small'>¥{Number(v).toFixed(2)}</Text>,
width: 90,
},
{
title: t('获得额度'),
dataIndex: 'amount',
render: (v) => <Text size='small'>{renderQuota(v)}</Text>,
width: 110,
},
{
title: t('支付方式'),
dataIndex: 'payment_channel',
render: (v) => (
<Text size='small'>
{v === 'paypal_checkout' ? 'PayPal' : v || '-'}
</Text>
),
width: 110,
},
{
title: t('状态'),
dataIndex: 'status',
render: (v) => renderStatus(v),
width: 90,
},
{
title: t('时间'),
dataIndex: 'create_time',
render: (v) => <Text size='small'>{timestamp2string(v)}</Text>,
width: 160,
},
];
const hasAnyPayment =
enableWechatTopUp || enableAlipayTopUp || enablePayPalTopUp;
return (
<div className='p-4 sm:p-6 lg:p-8 space-y-6'>
<OrgPageHeader title={t('企业充值')} subtitle={t('为企业账户充值额度')} />
{/* 签名时刻:余额展示区(本页唯一的品牌渐变区,渐变走 --brand-* token 随预设切换) */}
<div className='relative overflow-hidden bg-gradient-to-r from-brand-from via-brand-via to-brand-to rounded-xl p-5 shadow-[var(--elevation-md)]'>
<div className='flex items-center justify-between gap-4 flex-wrap'>
<div className='flex items-center gap-3'>
<div className='p-2 bg-white/15 rounded-lg'>
<Wallet size={20} className='text-white' />
</div>
<div>
<Text className='!text-white/80 text-xs font-medium block'>
{t('企业可用余额')}
</Text>
<Title heading={4} className='!text-white !mb-0 tabular-nums'>
{renderQuota(orgQuota)}
</Title>
</div>
</div>
<div className='w-px h-10 bg-white/20 flex-shrink-0' />
<div className='flex items-center gap-3'>
<div className='p-2 bg-white/10 rounded-lg'>
<TrendingUp size={18} className='text-white/80' />
</div>
<div>
<Text className='!text-white/60 text-xs block'>
{t('累计消耗')}
</Text>
<Text className='!text-white font-semibold text-sm tabular-nums'>
{renderQuota(orgUsedQuota)}
</Text>
</div>
</div>
</div>
</div>
{/* 充值区域 */}
<OrgPanel icon={Coins} title={t('选择充值档位')}>
{infoLoading ? (
<div className='py-10 flex justify-center'>
<Spin />
</div>
) : presetAmounts.length > 0 ? (
<>
<div className='grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2.5 mb-4'>
{presetAmounts.map((preset, idx) => (
<AmountCard
key={idx}
preset={preset}
selected={selectedPreset === preset.id}
onClick={() => selectPreset(preset)}
topupInfo={{ amount_options: [], discount: {} }}
priceRatio={1}
t={t}
/>
))}
</div>
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
<div
className={`mb-5 rounded-xl border-2 border-dashed transition-all ${
isCustomMode
? 'border-emerald-400 bg-gradient-to-br from-emerald-50/60 to-emerald-50/25 dark:from-emerald-900/15 dark:to-emerald-900/10 dark:border-emerald-600 shadow-sm shadow-emerald-500/5'
: 'border-gray-200 dark:border-neutral-700 hover:border-emerald-300 dark:hover:border-emerald-700'
}`}
>
{/* 头部 */}
<div className='px-4 pt-3.5 pb-2.5 flex items-center justify-between flex-wrap gap-1.5'>
<div className='flex items-center gap-1.5'>
<div className='p-1 rounded-md bg-emerald-100 dark:bg-emerald-900/40'>
<Pencil
size={12}
className='text-emerald-600 dark:text-emerald-400'
/>
</div>
<Text
strong
className='text-gray-800 dark:text-gray-200 text-sm'
>
{t('自定义充值')}
</Text>
{isCustomMode && (
<Tag color='green' size='small'>
{t('已选')}
</Tag>
)}
</div>
<Text type='tertiary' size='small'>
{t('原价到账,不参与折扣')}
</Text>
</div>
{/* 输入区 */}
<div className='px-4 pb-3'>
<div className='flex items-center gap-2'>
<InputNumber
value={customAmount}
onChange={handleCustomAmountChange}
min={1}
precision={0}
hideButtons
size='large'
placeholder={t('请输入整数,如 1、5、10')}
className='!flex-1'
style={{ width: '100%' }}
/>
<Select
value={customUnit}
onChange={handleCustomUnitChange}
size='large'
style={{ width: 96 }}
optionList={[
{ label: t('千'), value: 1000 },
{ label: t('万'), value: 10000 },
]}
/>
</div>
{/* 快速选择 */}
<div className='mt-2.5 flex items-center gap-1.5 flex-wrap'>
<Text
type='tertiary'
size='small'
className='!text-xs flex-shrink-0'
>
{t('快速选择:')}
</Text>
{customQuickPicks.map((pick) => {
const active =
isCustomMode &&
Number(customAmount) === pick.amount &&
customUnit === pick.unit;
const label = `${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`;
return (
<button
key={`${pick.amount}-${pick.unit}`}
type='button'
onClick={() =>
applyCustomQuickPick(pick.amount, pick.unit)
}
className={`px-2.5 py-0.5 rounded-md text-xs font-medium transition-colors border ${
active
? 'bg-emerald-500 text-white border-emerald-500 shadow-sm shadow-emerald-500/20'
: 'bg-white dark:bg-neutral-800 text-gray-600 dark:text-gray-300 border-gray-200 dark:border-neutral-700 hover:border-emerald-300 hover:text-emerald-600 dark:hover:border-emerald-700 dark:hover:text-emerald-400'
}`}
>
{label}
</button>
);
})}
</div>
</div>
{/* 实时预览(仅在金额合法时显示) */}
{customEffectiveAmount > 0 && customValid && (
<div className='mx-4 mb-3 rounded-lg p-3 bg-[var(--surface-card)] border border-[var(--border-subtle)]'>
<div className='flex items-center justify-between gap-3 flex-wrap'>
<div className='flex items-center gap-2'>
<div className='w-7 h-7 rounded-lg bg-rose-500/10 text-rose-600 dark:text-rose-400 flex items-center justify-center'>
<Wallet size={14} />
</div>
<div>
<Text
type='tertiary'
size='small'
className='!text-xs block leading-tight'
>
{t('实付金额')}
</Text>
<Text
strong
className='!text-rose-600 dark:!text-rose-400 text-base leading-tight'
>
¥{customEffectiveAmount.toLocaleString()}
</Text>
</div>
</div>
<div className='flex items-center gap-2'>
<div className='w-7 h-7 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400 flex items-center justify-center'>
<Coins size={14} />
</div>
<div className='text-right'>
<Text
type='tertiary'
size='small'
className='!text-xs block leading-tight'
>
{t('获得额度')}
</Text>
<Text
strong
className='!text-amber-600 dark:!text-amber-400 text-base leading-tight'
>
{renderQuota(customPreviewQuota)}
</Text>
</div>
</div>
</div>
</div>
)}
{/* 底部说明(金额不达标时变橙色) */}
<div className='px-4 pb-3'>
<Text
size='small'
className={`!text-xs ${
customEffectiveAmount > 0 && !customValid
? '!text-amber-600 dark:!text-amber-400'
: '!text-gray-400 dark:!text-gray-500'
}`}
>
{customEffectiveAmount > 0 && !customValid
? t('当前 ¥{{amount}},未达到最低 ¥1,000', {
amount: customEffectiveAmount.toLocaleString(),
})
: t('最少 1000 元,必须为 1000 元的整倍数')}
</Text>
</div>
</div>
{/* 支付方式 */}
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 rounded-lg bg-brand/10 text-brand'>
<CreditCard size={14} />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('支付方式')}
</Text>
</div>
{hasAnyPayment ? (
<div className='flex flex-wrap gap-3'>
{payMethods.map((method) => {
const isWechat = method.type === 'wxpay';
const isAlipay = method.type === 'alipay';
const isPayPal = method.type === 'paypal';
const disabled =
(isWechat && !enableWechatTopUp) ||
(isAlipay && !enableAlipayTopUp) ||
(isPayPal && !enablePayPalTopUp);
return (
<Button
key={method.type}
theme={payWay === method.type ? 'solid' : 'light'}
type={payWay === method.type ? 'primary' : 'tertiary'}
disabled={disabled}
loading={amountLoading && payWay === method.type}
onClick={() => handlePreTopUp(method.type)}
className={`!rounded-lg !px-5 !py-2.5 !h-auto transition-colors ${
payWay === method.type
? ''
: 'hover:!bg-brand/5 dark:hover:!bg-brand-deep/20 hover:!border-brand-from'
}`}
>
{method.name}
</Button>
);
})}
</div>
) : (
<Text type='tertiary' size='small'>
{t('暂无可用的支付方式,请联系管理员配置')}
</Text>
)}
</>
) : (
<Text type='tertiary'>{t('暂无充值档位,请联系管理员配置')}</Text>
)}
</OrgPanel>
{/* 充值记录 */}
<OrgPanel
icon={History}
title={t('充值记录')}
bodyClassName='overflow-x-auto'
>
<Table
columns={historyColumns}
dataSource={history}
loading={historyLoading}
pagination={{
currentPage: historyPage,
total: historyTotal,
pageSize: 10,
onPageChange: setHistoryPage,
}}
size='small'
empty={<Text type='tertiary'>{t('暂无充值记录')}</Text>}
/>
</OrgPanel>
{/* 支付确认弹窗 */}
<PaymentConfirmModal
t={t}
open={confirmOpen}
onlineTopUp={handleConfirmPay}
handleCancel={() => setConfirmOpen(false)}
confirmLoading={confirmLoading}
topUpCount={effectiveAmountYuan}
renderQuotaWithAmount={() => {
if (payWay === 'paypal' && payPalQuote?.quota) {
return renderQuota(payPalQuote.quota);
}
if (effectiveAmountYuan <= 0) return renderQuota(0);
// 额度 = 原始金额 × QuotaPerUnit + 赠送额度(与后端 CalculateQuota 逻辑一致,折扣只影响实付金额,不影响获得的额度)
const quotaPerUnit = getQuotaPerUnit() || 500000;
const baseQuota = effectiveAmountYuan * quotaPerUnit;
return renderQuota(baseQuota + effectiveBonus);
}}
amountLoading={amountLoading}
renderAmount={renderAmount}
payWay={payWay}
payMethods={payMethods}
amountNumber={
payWay === 'paypal' ? 0 : effectiveAmountYuan * effectiveDiscount
}
discountRate={payWay === 'paypal' ? 1 : effectiveDiscount}
payPalQuote={payPalQuote}
/>
{/* 微信二维码弹窗 */}
<WechatQRModal
visible={wechatQRVisible}
onClose={handleWechatComplete}
orderData={wechatOrderData}
pollFn={async (tradeNo) => {
const res = await API.get(
`/api/org/topup?p=1&page_size=1&keyword=${tradeNo}`,
{ headers: orgHeaders },
);
const items = res.data.data?.items || [];
return items.length > 0 ? items[0] : null;
}}
/>
</div>
);
};
export default OrgRecharge;