import { CheckCircleOutlined, CloseOutlined, CrownOutlined, RocketOutlined } from "@ant-design/icons"; import { useMemo, useState, type ReactNode } from "react"; import "../../styles/components/recharge-modal.css"; import { keyServerClient, type RechargeOrderResult } from "../../api/keyServerClient"; import { toast } from "../toast/toastStore"; type RechargeAudience = "personal" | "enterprise"; type PaymentMethod = "wechat" | "alipay" | "bank"; interface MembershipPlan { id: string; audience: RechargeAudience; name: string; subtitle: string; period: string; price: string; grant: string; comparisonLabel: string; badge?: string; icon: ReactNode; benefits: string[]; } const membershipPlans: MembershipPlan[] = [ { id: "pro-month", audience: "personal", name: "专业版", subtitle: "Pro", period: "月付", price: "299 元 / 月", grant: "每月赠送 10000 积分,30 天有效", comparisonLabel: "专业版基础权益", icon: , benefits: ["通用大模型全解锁", "积分与 API 消耗 9 折", "并发提升到 3 个", "去水印、插队加速、专属客服"], }, { id: "pro-quarter", audience: "personal", name: "专业版", subtitle: "Pro", period: "季付", price: "897 元 / 季", grant: "连续 3 个月按月发放 Pro 积分", comparisonLabel: "相比月付新增", badge: "季度", icon: , benefits: ["一次覆盖 3 个月使用周期", "每月延续 Pro 权益", "适合短期项目排期"], }, { id: "pro-year", audience: "personal", name: "专业版", subtitle: "Pro", period: "年付", price: "1990 元 / 年", grant: "全年合计 140000 积分,默认按月分摊", comparisonLabel: "相比季付新增", badge: "年费优惠", icon: , benefits: ["折合 10 个月费用", "前 100 名额外赠 20000 积分", "适合全年持续高频使用"], }, { id: "enterprise-month", audience: "enterprise", name: "企业版", subtitle: "Enterprise", period: "月付", price: "499 元 / 月", grant: "每月赠送 2000 积分,30 天有效", comparisonLabel: "企业版基础权益", icon: , benefits: ["企业私有模型与高性能模型", "默认 10 并发,可申请提升", "积分与 API 消耗 8 折", "用量报表与正式 API 权限"], }, { id: "enterprise-quarter", audience: "enterprise", name: "企业版", subtitle: "Enterprise", period: "季付", price: "1497 元 / 季", grant: "连续 3 个月按月发放企业版积分", comparisonLabel: "相比月付新增", badge: "季度", icon: , benefits: ["一次覆盖季度项目周期", "延续企业资源池与高并发", "适合阶段性团队投放"], }, { id: "enterprise-year", audience: "enterprise", name: "企业版", subtitle: "Enterprise", period: "年付", price: "4990 元 / 年", grant: "全年合计 340000 积分,默认按月分摊", comparisonLabel: "相比季付新增", badge: "企业年费", icon: , benefits: ["折合 10 个月费用", "前 100 名额外赠 100000 积分", "支持对公充值与子账户额度分配"], }, ]; const defaultSelectedPlanIds: Record = { personal: "pro-month", enterprise: "enterprise-month", }; const rechargeRules = [ "充值比例:固定 1 元 = 100 积分,平台可限时活动额外赠送积分", "有效期:充值积分到账起有效期 12 个月,系统按先进先出自动消耗", "退费规则:充值积分到账后不支持退换、折现,仅限平台内消费", ]; const paymentMethods: Array<{ id: PaymentMethod; label: string; hint: string }> = [ { id: "wechat", label: "微信支付", hint: "生成支付链接或二维码" }, { id: "alipay", label: "支付宝", hint: "生成支付链接或二维码" }, { id: "bank", label: "对公转账", hint: "企业客户可联系客服确认" }, ]; export interface RechargeModalProps { open: boolean; onClose: () => void; currentBalance?: number; } export function RechargeModal({ open, onClose, currentBalance }: RechargeModalProps) { const [activeAudience, setActiveAudience] = useState("personal"); const [selectedPlanIds, setSelectedPlanIds] = useState>(defaultSelectedPlanIds); const [paymentMethod, setPaymentMethod] = useState("wechat"); const [submitting, setSubmitting] = useState(false); const [order, setOrder] = useState(null); const visiblePlans = useMemo(() => membershipPlans.filter((plan) => plan.audience === activeAudience), [activeAudience]); const selectedPlanId = selectedPlanIds[activeAudience]; const selectedPlan = membershipPlans.find((plan) => plan.id === selectedPlanId) ?? visiblePlans[0]; const handlePlanSelect = (plan: MembershipPlan) => { setSelectedPlanIds((current) => ({ ...current, [plan.audience]: plan.id, })); setOrder(null); }; const handleCreateOrder = async () => { if (!selectedPlan || submitting) return; setSubmitting(true); try { const nextOrder = await keyServerClient.createRechargeOrder({ planId: selectedPlan.id, paymentMethod }); setOrder(nextOrder); if (nextOrder.payUrl) { window.open(nextOrder.payUrl, "_blank", "noopener,noreferrer"); } toast.success("充值订单已创建"); } catch (error) { const message = error instanceof Error ? error.message : "订单创建失败,请联系客服处理。"; toast.error(message); setOrder({ orderId: `support-${Date.now()}`, status: "manual-review", message: "支付接口暂不可用,请通过页面联系方式联系客服完成充值。", }); } finally { setSubmitting(false); } }; if (!open) return null; return (
{visiblePlans.map((plan) => { const isSelected = plan.id === selectedPlanId; return (
{plan.badge ? {plan.badge} : null}
{plan.icon}

{plan.name}

{plan.subtitle}
{plan.period}
{plan.price}

{plan.grant}

{plan.comparisonLabel}
    {plan.benefits.map((benefit) => (
  • {benefit}
  • ))}
); })}

积分充值规则

    {rechargeRules.map((rule) => (
  1. {rule}
  2. ))}
支付确认

{selectedPlan.name} · {selectedPlan.period}

{selectedPlan.price},{selectedPlan.grant}

{paymentMethods.map((method) => ( ))}
{order ? (
订单号:{order.orderId} 状态:{order.status} {order.qrCodeUrl ? 支付二维码 : null} {order.payUrl ? 打开支付链接 : null}

{order.message || "支付完成后积分将自动入账,如长时间未到账请联系客服。"}

) : null}
); }