Skip to content

Let's use AI to Earn!

dingyuetanchuang

bulaienaofutuojiesenzhang1dd50debc9bf
diff --git a/src/app/i18n/locales/en/vip.json b/src/app/i18n/locales/en/vip.json
index aeff330a..a88045bb 100644
--- a/src/app/i18n/locales/en/vip.json
+++ b/src/app/i18n/locales/en/vip.json
@@ -39,6 +39,15 @@
"month": "Monthly",
"year": "Yearly"
},
+ "subscriptionManagement": "Subscription Management",
+ "subscriptionPlanManagement": "Subscription Plan Management",
+ "purchaseHistory": "Purchase History",
+ "myMembership": "My Membership",
+ "basicMembership": "Basic Membership",
+ "validUntil": "Valid Until",
+ "activatedAutoRenewalPlans": "Activated Auto-renewal Plans",
+ "noAutoRenewalItems": "You haven't activated any auto-renewal items yet",
+ "viewMorePlans": "View More Plans",
"modal": {
"title": "7-Day Free Trial",
"highlight": "Get 100 Points",
diff --git a/src/app/i18n/locales/zh-CN/vip.json b/src/app/i18n/locales/zh-CN/vip.json
index 8e6a668d..3f428824 100644
--- a/src/app/i18n/locales/zh-CN/vip.json
+++ b/src/app/i18n/locales/zh-CN/vip.json
@@ -39,6 +39,15 @@
"month": "月度订阅",
"year": "年度订阅"
},
+ "subscriptionManagement": "订阅管理",
+ "subscriptionPlanManagement": "订阅计划管理",
+ "purchaseHistory": "购买记录",
+ "myMembership": "我的会员",
+ "basicMembership": "基础会员",
+ "validUntil": "有效期至",
+ "activatedAutoRenewalPlans": "已开通的自动续费套餐",
+ "noAutoRenewalItems": "你还没有开通自动续费项目哦",
+ "viewMorePlans": "查看更多套餐",
"modal": {
"title": "免费试用7天会员",
"highlight": "立得100积分",
diff --git a/src/components/modals/SubscriptionManagementModal.tsx b/src/components/modals/SubscriptionManagementModal.tsx
new file mode 100644
index 00000000..f482ec9c
--- /dev/null
+++ b/src/components/modals/SubscriptionManagementModal.tsx
@@ -0,0 +1,444 @@
+"use client";
+
+import { memo, useState, useEffect } from "react";
+import { Modal, Tabs, Table, Card, Button, Tag, Descriptions, message } from "antd";
+import { useTransClient } from "@/app/i18n/client";
+import { useUserStore } from "@/store/user";
+import {
+ getOrderListApi,
+ getSubscriptionListApi,
+ getOrderDetailApi,
+ refundOrderApi,
+ unsubscribeApi
+} from "@/api/payment";
+import { Order, OrderListParams, SubscriptionListParams, RefundParams, UnsubscribeParams, OrderStatus, PaymentType } from "@/api/types/payment";
+import styles from "./subscriptionManagementModal.module.css";
+
+const { TabPane } = Tabs;
+
+interface SubscriptionManagementModalProps {
+ open: boolean;
+ onClose: () => void;
+}
+
+const SubscriptionManagementModal = memo(({ open, onClose }: SubscriptionManagementModalProps) => {
+ const { t: tProfile } = useTransClient('profile');
+ const { t: tVip } = useTransClient('vip');
+ const { userInfo } = useUserStore();
+
+ // 订单相关状态
+ const [orders, setOrders] = useState<Order[]>([]);
+ const [subscriptions, setSubscriptions] = useState<Order[]>([]);
+ const [ordersLoading, setOrdersLoading] = useState(false);
+ const [subscriptionsLoading, setSubscriptionsLoading] = useState(false);
+ const [ordersPagination, setOrdersPagination] = useState({
+ current: 1,
+ pageSize: 10,
+ total: 0
+ });
+ const [subscriptionsPagination, setSubscriptionsPagination] = useState({
+ current: 1,
+ pageSize: 10,
+ total: 0
+ });
+
+ // 订单详情弹窗状态
+ const [orderDetailVisible, setOrderDetailVisible] = useState(false);
+ const [orderDetailLoading, setOrderDetailLoading] = useState(false);
+ const [currentOrderDetail, setCurrentOrderDetail] = useState<Order | null>(null);
+
+ // 获取购买记录
+ const fetchOrders = async (params: OrderListParams) => {
+ setOrdersLoading(true);
+ try {
+ const response = await getOrderListApi(params);
+ if (response?.code === 0 && response.data) {
+ setOrders((response.data as any).list || []);
+ setOrdersPagination({
+ current: params.page + 1,
+ pageSize: params.size,
+ total: (response.data as any).count || 0
+ });
+ }
+ } catch (error) {
+ console.error('获取订单列表失败:', error);
+ } finally {
+ setOrdersLoading(false);
+ }
+ };
+
+ // 获取订阅列表
+ const fetchSubscriptions = async (params: SubscriptionListParams) => {
+ setSubscriptionsLoading(true);
+ try {
+ const response:any = await getSubscriptionListApi(params);
+ if (response?.code === 0 && response.data) {
+ setSubscriptions((response.data as any).list || []);
+ setSubscriptionsPagination({
+ current: params.page + 1,
+ pageSize: params.size,
+ total: (response.data as any).count || 0
+ });
+ }
+ } catch (error) {
+ console.error('获取订阅列表失败:', error);
+ } finally {
+ setSubscriptionsLoading(false);
+ }
+ };
+
+ // 处理退款
+ const handleRefund = async (order: Order) => {
+ try {
+ const params: RefundParams = {
+ charge: order.id,
+ payment_intent: order.payment_intent || order.id,
+ userId: userInfo?.id || ''
+ };
+ const response = await refundOrderApi(params);
+ if (response?.code === 0) {
+ message.success(tProfile('refundSubmitted'));
+ fetchOrders({ page: ordersPagination.current - 1, size: ordersPagination.pageSize });
+ } else {
+ message.error(response?.message || tProfile('refundFailed'));
+ }
+ } catch (error) {
+ console.error('退款失败:', error);
+ message.error(tProfile('refundFailed'));
+ }
+ };
+
+ // 处理退订
+ const handleUnsubscribe = async (order: Order) => {
+ try {
+ const params: UnsubscribeParams = {
+ id: order.id,
+ userId: userInfo?.id || ''
+ };
+ const response = await unsubscribeApi(params);
+ if (response?.code === 0) {
+ message.success(tProfile('unsubscribeSuccess'));
+ fetchSubscriptions({ page: subscriptionsPagination.current - 1, size: subscriptionsPagination.pageSize });
+ } else {
+ message.error(response?.message || tProfile('unsubscribeFailed'));
+ }
+ } catch (error) {
+ console.error('退订失败:', error);
+ message.error(tProfile('unsubscribeFailed'));
+ }
+ };
+
+ // 获取订单详情
+ const fetchOrderDetail = async (orderId: string) => {
+ setOrderDetailLoading(true);
+ try {
+ const response: any = await getOrderDetailApi(orderId);
+ if (response?.code === 0 && response.data) {
+ setCurrentOrderDetail(response.data[0]);
+ setOrderDetailVisible(true);
+ } else {
+ message.error(tProfile('getOrderDetailFailed'));
+ }
+ } catch (error) {
+ console.error('获取订单详情失败:', error);
+ message.error(tProfile('getOrderDetailFailed'));
+ } finally {
+ setOrderDetailLoading(false);
+ }
+ };
+
+ // 订单状态标签
+ const getOrderStatusTag = (status: OrderStatus) => {
+ const statusMap = {
+ [OrderStatus.SUCCEEDED]: { color: 'green', text: tProfile('paymentSuccess') },
+ [OrderStatus.CREATED]: { color: 'orange', text: tProfile('waitingForPayment') },
+ [OrderStatus.REFUNDED]: { color: 'purple', text: tProfile('refundSuccess') },
+ [OrderStatus.EXPIRED]: { color: 'red', text: tProfile('orderCancelled') }
+ };
+ const config = statusMap[status] || { color: 'default', text: `状态${status}` };
+ return <Tag color={config.color}>{config.text}</Tag>;
+ };
+
+ // 支付类型文本
+ const getPaymentTypeText = (paymentType: string) => {
+ const typeMap: any = {
+ [PaymentType.ONCE_MONTH]: tProfile('oneTimeMonthly'),
+ [PaymentType.MONTH]: tProfile('monthlySubscription'),
+ [PaymentType.YEAR]: tProfile('yearlySubscription')
+ };
+ return typeMap[paymentType as PaymentType] || paymentType || tProfile('unknown');
+ };
+
+ // 订单表格列
+ const orderColumns = [
+ {
+ title: tProfile('orderId'),
+ dataIndex: 'id',
+ key: 'id',
+ ellipsis: true,
+ width: 200,
+ },
+ {
+ title: tProfile('packageType'),
+ dataIndex: 'metadata',
+ key: 'packageType',
+ width: 120,
+ render: (metadata: any) => getPaymentTypeText(metadata?.payment),
+ },
+ {
+ title: tProfile('amount'),
+ dataIndex: 'amount',
+ key: 'amount',
+ width: 100,
+ render: (amount: number) => `¥${(amount / 100).toFixed(2)}`,
+ },
+ {
+ title: tProfile('status'),
+ dataIndex: 'status',
+ key: 'status',
+ width: 120,
+ render: (status: OrderStatus) => getOrderStatusTag(status),
+ },
+ {
+ title: tProfile('createTime'),
+ dataIndex: 'created',
+ key: 'created',
+ width: 150,
+ render: (created: number) => new Date(created * 1000).toLocaleString(),
+ },
+ {
+ title: tProfile('actions'),
+ key: 'actions',
+ width: 120,
+ render: (_: any, record: Order) => (
+ <div className={styles.actionButtons}>
+ <Button
+ size="small"
+ onClick={(e) => {
+ e.stopPropagation();
+ fetchOrderDetail(record.id);
+ }}
+ >
+ {tProfile('viewDetails')}
+ </Button>
+ {record.status === OrderStatus.SUCCEEDED && (
+ <Button
+ size="small"
+ danger
+ onClick={(e) => {
+ e.stopPropagation();
+ handleRefund(record);
+ }}
+ >
+ {tProfile('points.refund')}
+ </Button>
+ )}
+ </div>
+ ),
+ },
+ ];
+
+ // 订阅表格列
+ const subscriptionColumns = [
+ {
+ title: tProfile('subscriptionId'),
+ dataIndex: 'id',
+ key: 'id',
+ ellipsis: true,
+ width: 200,
+ },
+ {
+ title: tProfile('packageType'),
+ dataIndex: 'metadata',
+ key: 'packageType',
+ width: 120,
+ render: (metadata: any) => getPaymentTypeText(metadata?.payment),
+ },
+ {
+ title: tProfile('amount'),
+ dataIndex: 'amount',
+ key: 'amount',
+ width: 100,
+ render: (amount: number) => `¥${(amount / 100).toFixed(2)}`,
+ },
+ {
+ title: tProfile('status'),
+ dataIndex: 'status',
+ key: 'status',
+ width: 120,
+ render: (status: OrderStatus) => {
+ const statusMap = {
+ 1: { color: 'green', text: tProfile('subscriptionSuccess') },
+ 2: { color: 'red', text: tProfile('subscriptionCancelled') },
+ 3: { color: 'purple', text: tProfile('refundSuccess') },
+ 4: { color: 'orange', text: tProfile('orderCancelled') }
+ };
+ const config = statusMap[status] || { color: 'default', text: `状态${status}` };
+ return <Tag color={config.color}>{config.text}</Tag>;
+ },
+ },
+ {
+ title: tProfile('createTime'),
+ dataIndex: 'created',
+ key: 'created',
+ width: 150,
+ render: (created: number) => new Date(created * 1000).toLocaleString(),
+ },
+ {
+ title: tProfile('actions'),
+ key: 'actions',
+ width: 120,
+ render: (_: any, record: Order) => (
+ <div className={styles.actionButtons}>
+ <Button
+ size="small"
+ onClick={(e) => {
+ e.stopPropagation();
+ fetchOrderDetail(record.id);
+ }}
+ >
+ {tProfile('viewDetails')}
+ </Button>
+ {record.status === 1 && (
+ <Button
+ size="small"
+ danger
+ onClick={(e) => {
+ e.stopPropagation();
+ handleUnsubscribe(record);
+ }}
+ >
+ {tProfile('cancelSubscription')}
+ </Button>
+ )}
+ </div>
+ ),
+ },
+ ];
+
+ // 弹窗打开时加载数据
+ useEffect(() => {
+ if (open) {
+ fetchOrders({ page: 0, size: 10 });
+ fetchSubscriptions({ page: 0, size: 10 });
+ }
+ }, [open]);
+
+
+ return (
+ <>
+ <Modal
+ title={tVip('subscriptionManagement' as any)}
+ open={open}
+ onCancel={onClose}
+ footer={null}
+ width={1000}
+ className={styles.subscriptionModal}
+ destroyOnClose
+ centered
+ >
+ <div className={styles.modalContent}>
+ <Tabs defaultActiveKey="subscriptions">
+ <TabPane tab={tVip('subscriptionPlanManagement' as any)} key="subscriptions">
+ <div className={styles.myMembership}>
+ <h3>{tVip('myMembership' as any)}</h3>
+ <div className={styles.membershipCard}>
+ <div className={styles.membershipInfo}>
+ <div className={styles.membershipIcon}>💎</div>
+ <div className={styles.membershipDetails}>
+ <div className={styles.membershipName}>{tVip('basicMembership' as any)}</div>
+ <div className={styles.membershipExpire}>
+ {tVip('validUntil' as any)} 2025-09-29 15:04
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div className={styles.autoRenewal}>
+ <h3>{tVip('activatedAutoRenewalPlans' as any)}</h3>
+ <div className={styles.emptyState}>
+ <p>{tVip('noAutoRenewalItems' as any)}</p>
+ <Button className={styles.viewMoreBtn}>{tVip('viewMorePlans' as any)}</Button>
+ </div>
+ </div>
+ </TabPane>
+
+ <TabPane tab={tVip('purchaseHistory' as any)} key="orders">
+ <Card>
+ <Table
+ columns={orderColumns}
+ dataSource={orders}
+ loading={ordersLoading}
+ rowKey="_id"
+ onRow={(record) => ({
+ onClick: () => {
+ fetchOrderDetail(record.id);
+ },
+ style: { cursor: 'pointer' }
+ })}
+ pagination={{
+ current: ordersPagination.current,
+ pageSize: ordersPagination.pageSize,
+ total: ordersPagination.total,
+ onChange: (page, size) => {
+ fetchOrders({ page: page - 1, size: size || 10 });
+ },
+ showSizeChanger: true,
+ showQuickJumper: true,
+ showTotal: (total) => tProfile('totalRecords', { total }),
+ pageSizeOptions: ['10', '20', '50'],
+ }}
+ scroll={{ x: 1200 }}
+ locale={{
+ emptyText: ordersLoading ? tProfile('loading') : tProfile('noOrderRecords')
+ }}
+ />
+ </Card>
+ </TabPane>
+ </Tabs>
+ </div>
+ </Modal>
+
+ {/* 订单详情弹窗 */}
+ <Modal
+ title={tProfile('orderDetails')}
+ open={orderDetailVisible}
+ onCancel={() => setOrderDetailVisible(false)}
+ className={styles.orderDetailModal}
+ footer={[
+ <Button key="close" onClick={() => setOrderDetailVisible(false)}>
+ {tProfile('close')}
+ </Button>
+ ]}
+ width={600}
+ loading={orderDetailLoading}
+ >
+ {currentOrderDetail && (
+ <Descriptions bordered column={1} size="small">
+ <Descriptions.Item label={tProfile('orderId')}>{currentOrderDetail.id}</Descriptions.Item>
+ <Descriptions.Item label={tProfile('internalId')}>{currentOrderDetail._id}</Descriptions.Item>
+ <Descriptions.Item label={tProfile('packageType')}>
+ {getPaymentTypeText(currentOrderDetail.metadata?.payment)}
+ </Descriptions.Item>
+ <Descriptions.Item label={tProfile('subscriptionMode')}>{currentOrderDetail.mode}</Descriptions.Item>
+ <Descriptions.Item label={tProfile('amount')}>
+ ¥{(currentOrderDetail.amount / 100).toFixed(2)}
+ </Descriptions.Item>
+ <Descriptions.Item label={tProfile('status')}>
+ {getOrderStatusTag(currentOrderDetail.status)}
+ </Descriptions.Item>
+ <Descriptions.Item label={tProfile('createTime')}>
+ {new Date(currentOrderDetail.created * 1000).toLocaleString()}
+ </Descriptions.Item>
+ <Descriptions.Item label={tProfile('paymentMethod' as any)}>
+ {(currentOrderDetail as any).payment_method || tProfile('unknown')}
+ </Descriptions.Item>
+ </Descriptions>
+ )}
+ </Modal>
+ </>
+ );
+});
+
+export default SubscriptionManagementModal;
diff --git a/src/components/modals/VipContentModal.tsx b/src/components/modals/VipContentModal.tsx
index 0ef53510..664b96bf 100644
--- a/src/components/modals/VipContentModal.tsx
+++ b/src/components/modals/VipContentModal.tsx
@@ -10,6 +10,7 @@ import vipStyles from "./vipContentModal.module.css";
import PointsDetailModal from "@/components/modals/PointsDetailModal";
import { useUserStore } from "@/store/user";
import PointsRechargeModal from "@/components/modals/PointsRechargeModal";
+import SubscriptionManagementModal from "@/components/modals/SubscriptionManagementModal";
import logo from '@/assets/images/logo.png';
import Image from "next/image";
@@ -21,6 +22,7 @@ interface VipContentModalProps {
const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
const [pointsModalVisible, setPointsModalVisible] = useState(false);
+ const [subscriptionModalVisible, setSubscriptionModalVisible] = useState(false);
const userStore = useUserStore();
const router = useRouter();
const { t } = useTransClient('vip');
@@ -136,7 +138,7 @@ const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
centered
>
<div className={vipStyles.wrapper}>
- {/* 顶部区域 */}
+ {/* 非会员顶部区域 */}
{
!isVip && (
<div className={vipStyles.header}
@@ -177,10 +179,10 @@ const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
{/* <div className={vipStyles.userEmail}>{userStore.userInfo.mail}</div> */}
</div>
</div>
- <div className={vipStyles.vipActions}>
- <Button className={vipStyles.detailBtn} onClick={() => setPointsModalVisible(true)}>{translate('modal.pointsDetail')}</Button>
- <Button className={vipStyles.subscriptionBtn}>{translate('modal.vipInfo.subscription')}</Button>
- </div>
+ <div className={vipStyles.vipActions}>
+ <Button className={vipStyles.detailBtn} onClick={() => setPointsModalVisible(true)}>{translate('modal.pointsDetail')}</Button>
+ <Button className={vipStyles.subscriptionBtn} onClick={() => setSubscriptionModalVisible(true)}>{translate('modal.vipInfo.subscription')}</Button>
+ </div>
</div>
<div className={vipStyles.vipPlanInfo}>
@@ -453,6 +455,9 @@ const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
<PointsDetailModal open={pointsModalVisible} onClose={() => setPointsModalVisible(false)} />
<PointsRechargeModal open={rechargeVisible} onClose={() => setRechargeVisible(false)} />
+
+ {/* 订阅管理弹窗 */}
+ <SubscriptionManagementModal open={subscriptionModalVisible} onClose={() => setSubscriptionModalVisible(false)} />
</Modal>
);
});
diff --git a/src/components/modals/subscriptionManagementModal.module.css b/src/components/modals/subscriptionManagementModal.module.css
new file mode 100644
index 00000000..6d1cd7a6
--- /dev/null
+++ b/src/components/modals/subscriptionManagementModal.module.css
@@ -0,0 +1,173 @@
+/* 订阅管理弹窗样式 */
+.subscriptionModal {
+ background: white;
+}
+
+.modalContent {
+ background: white;
+ padding: 0;
+}
+
+/* 我的会员区域 */
+.myMembership {
+ margin-bottom: 24px;
+}
+
+.myMembership h3 {
+ margin: 0 0 16px 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: #111827;
+}
+
+.membershipCard {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 16px;
+ border: 1px solid #e5e7eb;
+}
+
+.membershipInfo {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.membershipIcon {
+ font-size: 24px;
+ width: 40px;
+ height: 40px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: #e0e7ff;
+ border-radius: 8px;
+}
+
+.membershipDetails {
+ flex: 1;
+}
+
+.membershipName {
+ font-size: 16px;
+ font-weight: 600;
+ color: #111827;
+ margin-bottom: 4px;
+}
+
+.membershipExpire {
+ font-size: 14px;
+ color: #6b7280;
+}
+
+/* 自动续费区域 */
+.autoRenewal {
+ margin-bottom: 24px;
+}
+
+.autoRenewal h3 {
+ margin: 0 0 16px 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: #111827;
+}
+
+.emptyState {
+ text-align: center;
+ padding: 40px 20px;
+ background: #f8f9fa;
+ border-radius: 8px;
+ border: 1px solid #e5e7eb;
+}
+
+.emptyState p {
+ margin: 0 0 16px 0;
+ color: #6b7280;
+ font-size: 14px;
+}
+
+.viewMoreBtn {
+ background: #374151;
+ border-color: #374151;
+ color: white;
+ border-radius: 6px;
+ font-weight: 500;
+}
+
+.viewMoreBtn:hover {
+ background: #4b5563;
+ border-color: #4b5563;
+}
+
+/* 操作按钮 */
+.actionButtons {
+ display: flex;
+ gap: 8px;
+ flex-wrap: wrap;
+}
+
+.actionButtons .ant-btn {
+ font-size: 12px;
+ padding: 4px 8px;
+ height: auto;
+}
+
+/* 订单详情弹窗 */
+.orderDetailModal .ant-descriptions-item-label {
+ font-weight: 600;
+ color: #374151;
+ width: 120px;
+}
+
+.orderDetailModal .ant-descriptions-item-content {
+ color: #111827;
+}
+
+/* 表格样式优化 */
+.ant-table-thead > tr > th {
+ background: #f8f9fa;
+ font-weight: 600;
+ color: #374151;
+ border-bottom: 2px solid #e5e7eb;
+}
+
+.ant-table-tbody > tr:hover > td {
+ background: #f8f9fa;
+}
+
+/* 分页样式 */
+.ant-pagination {
+ margin-top: 16px;
+ text-align: right;
+}
+
+/* 标签样式 */
+.ant-tag {
+ border-radius: 4px;
+ font-size: 12px;
+ font-weight: 500;
+ padding: 2px 8px;
+}
+
+/* 响应式设计 */
+@media (max-width: 768px) {
+ .subscriptionModal {
+ width: 95% !important;
+ max-width: none;
+ }
+
+ .membershipInfo {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 8px;
+ }
+
+ .actionButtons {
+ flex-direction: column;
+ gap: 4px;
+ }
+
+ .actionButtons .ant-btn {
+ width: 100%;
+ }
+}