import React, { useState } from 'react'; import { Card, Row, Col, Switch, Tag, Typography, Space, Button, Modal, Progress, Divider, Alert, Tabs, Table, message } from 'antd'; import { CrownOutlined, RobotOutlined, ShopOutlined, GlobalOutlined, LineChartOutlined, ApiOutlined, CheckCircleOutlined, CloseCircleOutlined, ThunderboltOutlined, StarOutlined, } from '@ant-design/icons'; import { useUser, FEATURES, ROLE_CONFIG } from '@/contexts/UserContext'; const { Title, Text, Paragraph } = Typography; interface FeatureConfig { key: string; name: string; description: string; icon: React.ReactNode; requiredPlan: string[]; benefits: string[]; limitations?: string[]; } const FEATURE_CONFIGS: FeatureConfig[] = [ { key: FEATURES.AI_OPERATIONS, name: 'AI运营中心', description: '智能运营助手,自动化执行日常运营任务', icon: , requiredPlan: ['basic', 'pro', 'enterprise'], benefits: [ '自动选品推荐', '智能定价策略', '自动上下架', 'AI决策日志追踪', '策略市场访问', ], limitations: [ '免费版: 每日仅3次AI调用', '基础版: 每日100次AI调用', '专业版: 无限AI调用', ], }, { key: FEATURES.AUTO_PRICING, name: '自动定价', description: '基于市场数据和竞争分析的智能定价系统', icon: , requiredPlan: ['pro', 'enterprise'], benefits: [ '实时竞品价格监控', '动态定价策略', '利润率自动优化', '价格预警通知', ], limitations: [ '基础版: 仅查看定价建议', '专业版: 自动执行定价', ], }, { key: FEATURES.MULTI_SHOP, name: '多店铺管理', description: '统一管理多个电商平台的店铺', icon: , requiredPlan: ['basic', 'pro', 'enterprise'], benefits: [ '跨平台商品同步', '统一库存管理', '多店铺数据报表', '批量操作支持', ], limitations: [ '免费版: 仅支持1个店铺', '基础版: 最多3个店铺', '专业版: 最多10个店铺', '企业版: 无限店铺', ], }, { key: FEATURES.B2B_TRADE, name: 'B2B贸易', description: '企业级批发贸易管理功能', icon: , requiredPlan: ['basic', 'pro', 'enterprise'], benefits: [ '供应商管理', '批量订单处理', 'B2B专属定价', '合同管理', ], }, { key: FEATURES.INDEPENDENT_SITE, name: '独立站', description: '创建和管理独立电商网站', icon: , requiredPlan: ['pro', 'enterprise'], benefits: [ '自定义品牌站点', '独立域名绑定', 'SEO优化工具', '独立支付集成', ], }, { key: FEATURES.ADVANCED_ANALYTICS, name: '高级数据分析', description: '深度数据分析和可视化报表', icon: , requiredPlan: ['pro', 'enterprise'], benefits: [ '自定义报表', '数据导出', '趋势预测', '竞品分析报告', ], limitations: [ '基础版: 仅基础报表', '专业版: 完整分析功能', ], }, { key: FEATURES.API_ACCESS, name: 'API访问', description: '开放API接口,支持系统集成', icon: , requiredPlan: ['enterprise'], benefits: [ 'RESTful API', 'Webhook支持', 'SDK下载', '技术文档', ], }, ]; const PLAN_DETAILS = { free: { name: '免费版', price: 0, color: 'default', features: ['基础商品管理', '订单管理', '基础报表'], limitations: ['1个店铺', '每日3次AI调用', '无API访问'], }, basic: { name: '基础版', price: 99, color: 'blue', features: ['多店铺管理(3个)', 'AI运营(100次/日)', 'B2B贸易', '基础定价建议'], limitations: ['无独立站', '无API访问'], }, pro: { name: '专业版', price: 299, color: 'gold', features: ['多店铺管理(10个)', '无限AI调用', '自动定价', '独立站', '高级分析'], limitations: ['无API访问'], }, enterprise: { name: '企业版', price: 999, color: 'purple', features: ['无限店铺', '全部功能', 'API访问', '专属客服', '定制开发'], limitations: [], }, }; const SubscriptionManage: React.FC = () => { const { currentUser, hasFeature, isPaidUser, getPlanLabel } = useUser(); const [previewFeature, setPreviewFeature] = useState(null); const [simulatedPlan, setSimulatedPlan] = useState(null); const currentPlan = currentUser.subscription?.plan || 'free'; const handleFeaturePreview = (feature: FeatureConfig) => { setPreviewFeature(feature); }; const handleSimulatePlan = (plan: string) => { setSimulatedPlan(plan); message.info(`已切换到${PLAN_DETAILS[plan as keyof typeof PLAN_DETAILS].name}预览模式`); }; const isFeatureAvailable = (featureKey: string) => { if (simulatedPlan) { const feature = FEATURE_CONFIGS.find(f => f.key === featureKey); return feature?.requiredPlan.includes(simulatedPlan) ?? false; } return hasFeature(featureKey); }; const columns = [ { title: '功能', dataIndex: 'name', key: 'name', render: (name: string, record: FeatureConfig) => ( {record.icon} {name} ), }, { title: '免费版', key: 'free', render: (_: any, record: FeatureConfig) => record.requiredPlan.includes('free') ? : , }, { title: '基础版', key: 'basic', render: (_: any, record: FeatureConfig) => record.requiredPlan.includes('basic') ? : , }, { title: '专业版', key: 'pro', render: (_: any, record: FeatureConfig) => record.requiredPlan.includes('pro') ? : , }, { title: '企业版', key: 'enterprise', render: (_: any, record: FeatureConfig) => record.requiredPlan.includes('enterprise') ? : , }, { title: '当前状态', key: 'status', render: (_: any, record: FeatureConfig) => ( {isFeatureAvailable(record.key) ? '已开通' : '未开通'} ), }, { title: '操作', key: 'action', render: (_: any, record: FeatureConfig) => ( ), }, ]; return (
<CrownOutlined style={{ marginRight: 8 }} /> 订阅管理中心 管理您的订阅计划和付费功能,预览不同套餐的功能差异
{Object.entries(PLAN_DETAILS).map(([key, plan]) => ( handleSimulatePlan(key)} >
{plan.name} {currentPlan === key && ( 当前套餐 )} {simulatedPlan === key && currentPlan !== key && ( 预览中 )} ¥{plan.price} <Text type="secondary" style={{ fontSize: 14 }}>/月</Text>
{plan.features.map((f, i) => (
{f}
))} {plan.limitations.map((l, i) => (
{l}
))}
))}
{getPlanLabel()} 当前套餐 {currentUser.subscription?.expiresAt ? `到期时间: ${currentUser.subscription.expiresAt}` : '永久有效'}
{currentUser.subscription?.features.length || 0} 已开通功能
{FEATURE_CONFIGS.filter(f => !hasFeature(f.key)).length} 可升级功能
setPreviewFeature(null)} footer={[ , !isFeatureAvailable(previewFeature?.key || '') && ( ), ]} width={600} > {previewFeature && (
{previewFeature.description} 功能权益 {previewFeature.benefits.map((b, i) => (
{b}
))} {previewFeature.limitations && ( <> 版本限制 {previewFeature.limitations.map((l, i) => (
• {l}
))} )} 所需套餐 {previewFeature.requiredPlan.map(p => ( {PLAN_DETAILS[p as keyof typeof PLAN_DETAILS]?.name} ))}
{isFeatureAvailable(previewFeature.key) ? '✓ 您已拥有此功能' : '✗ 需要升级套餐'}
)}
); }; export default SubscriptionManage;