Skip to content

Let's use AI to Earn!

vip 开通修改

DESKTOP-EMF2SH4\Administrator86ae22030bdc
diff --git a/src/api/vip.ts b/src/api/vip.ts
new file mode 100644
index 00000000..f4148496
--- /dev/null
+++ b/src/api/vip.ts
@@ -0,0 +1,18 @@
+import { request } from '@/utils/request';
+
+// 会员类型枚举
+export enum VipCycleType {
+ MONTH = 1, // 月卡会员
+ YEAR = 2, // 年卡会员
+}
+
+// 设置会员类型
+export const setVipApi = (cycleType: VipCycleType) => {
+ return request({
+ url: '/user/vip/set',
+ method: 'PUT',
+ data: {
+ cycleType
+ }
+ });
+};
\ No newline at end of file
diff --git a/src/app/[lng]/profile/page.tsx b/src/app/[lng]/profile/page.tsx
index 9b312311..4d11f052 100644
--- a/src/app/[lng]/profile/page.tsx
+++ b/src/app/[lng]/profile/page.tsx
@@ -2,7 +2,7 @@
import { useEffect, useState } from "react";
import { Card, Descriptions, Button, message, Modal, Form, Input } from "antd";
-import { CrownOutlined, TrophyOutlined, GiftOutlined, StarOutlined, RocketOutlined } from "@ant-design/icons";
+import { CrownOutlined, TrophyOutlined, GiftOutlined, StarOutlined, RocketOutlined, ThunderboltOutlined, HistoryOutlined, DollarOutlined } from "@ant-design/icons";
import { useRouter } from "next/navigation";
import { useUserStore } from "@/store/user";
import { getUserInfoApi, updateUserInfoApi } from "@/api/apiReq";
@@ -15,8 +15,10 @@ export default function ProfilePage() {
const [isModalOpen, setIsModalOpen] = useState(false);
const [form] = Form.useForm();
- // 模拟会员状态,实际应从 userInfo 或其他接口获取
- const isVip = userInfo?.isVip || false; // 假设 userInfo 中有一个 isVip 字段
+ // 获取会员状态和过期时间
+ const isVip = userInfo?.vipInfo?.id ? true : false;
+ const vipExpireTime = userInfo?.vipInfo?.expireTime ? new Date(userInfo.vipInfo.expireTime).toLocaleDateString() : '';
+ const vipCycleType = userInfo?.vipInfo?.cycleType === 1 ? '月度会员' : '年度会员';
// 会员权益数据
const vipBenefits = [
@@ -24,6 +26,9 @@ export default function ProfilePage() {
{ icon: <TrophyOutlined />, name: "高级功能" },
{ icon: <GiftOutlined />, name: "会员礼包" },
{ icon: <StarOutlined />, name: "优先支持" },
+ { icon: <DollarOutlined />, name: "优惠折扣" },
+ { icon: <HistoryOutlined />, name: "无限时长" },
+ { icon: <ThunderboltOutlined />, name: "极速体验" },
{ icon: <RocketOutlined />, name: "更多特权" },
];
@@ -84,7 +89,7 @@ export default function ProfilePage() {
};
const handleGoToVipPage = () => {
- router.push('/vip'); // 跳转到开通会员页面
+ router.push('/vip');
};
if (loading) {
@@ -99,9 +104,14 @@ export default function ProfilePage() {
<span className={styles.vipIcon}><CrownOutlined /></span>
<h2 className={styles.vipTitle}>PLUS会员</h2>
</div>
- <p className={styles.vipDescription}>
- 开通会员解锁全部功能,立享8种权益
+ {isVip ? (<p className={styles.vipDescription}>
+ 尊敬的VIP用户,您已解锁全部会员权益
</p>
+ ) : (
+ <p className={styles.vipDescription}>
+ 开通会员解锁全部功能,立享8种权益
+ </p>
+ )}
<div className={styles.benefitsGrid}>
{vipBenefits.map((benefit, index) => (
<div key={index} className={styles.benefitItem}>
@@ -111,9 +121,8 @@ export default function ProfilePage() {
))}
</div>
{isVip ? (
- <Button className={styles.activateButton} disabled>
- 已开通会员
- </Button>
+ <div className={styles.vipInfo}>
+ </div>
) : (
<button className={styles.activateButton} onClick={handleGoToVipPage}>
立即开通
@@ -143,6 +152,12 @@ export default function ProfilePage() {
<Descriptions.Item label="账号状态">
{userInfo?.status === 1 ? '正常' : '禁用'}
</Descriptions.Item>
+ {isVip && (
+ <>
+ <Descriptions.Item label="会员类型">{vipCycleType}</Descriptions.Item>
+ <Descriptions.Item label="会员到期时间">{vipExpireTime}</Descriptions.Item>
+ </>
+ )}
</Descriptions>
</Card>
diff --git a/src/app/[lng]/vip/page.tsx b/src/app/[lng]/vip/page.tsx
index 1c0a531b..91ff6ba6 100644
--- a/src/app/[lng]/vip/page.tsx
+++ b/src/app/[lng]/vip/page.tsx
@@ -2,10 +2,15 @@
import { useState } from "react";
import { CrownOutlined, TrophyOutlined, GiftOutlined, StarOutlined, RocketOutlined, DollarOutlined, HistoryOutlined, ThunderboltOutlined } from "@ant-design/icons";
+import { message } from "antd";
+import { useRouter } from "next/navigation";
+import { setVipApi, VipCycleType } from "@/api/vip";
import styles from "./vip.module.css";
export default function VipPage() {
- const [selectedPlan, setSelectedPlan] = useState('month'); // 'month', 'halfYear', 'year', 'special'
+ const router = useRouter();
+ const [selectedPlan, setSelectedPlan] = useState('month'); // 'month', 'year'
+ const [loading, setLoading] = useState(false);
// 会员权益数据 (8个)
const vipBenefits = [
@@ -19,9 +24,24 @@ export default function VipPage() {
{ icon: <RocketOutlined />, name: "更多特权" },
];
- const handleActivate = () => {
- // 这里可以添加实际的开通逻辑,例如跳转到支付页面或调用支付接口
- alert(`您选择了${selectedPlan === 'month' ? '月度会员' : selectedPlan === 'halfYear' ? '半年会员' : selectedPlan === 'year' ? '年度会员' : '特价会员'},即将开通。`);
+ const handleActivate = async () => {
+ try {
+ setLoading(true);
+ const cycleType = selectedPlan === 'month' ? VipCycleType.MONTH : VipCycleType.YEAR;
+ const response:any = await setVipApi(cycleType);
+
+ if (response?.code === 0) {
+ message.success('开通成功');
+ router.push('/profile'); // 开通成功后跳转到个人中心
+ } else {
+ message.error(response?.msg || '开通失败');
+ }
+ } catch (error) {
+ console.error('开通会员失败:', error);
+ message.error('开通失败,请稍后重试');
+ } finally {
+ setLoading(false);
+ }
};
return (
@@ -48,18 +68,6 @@ export default function VipPage() {
<h3 className={styles.title}>选择开通时长</h3>
<div className={styles.priceOptions}>
- <div
- className={`${styles.priceCard} ${selectedPlan === 'special' ? styles.selected : ''}`}
- onClick={() => setSelectedPlan('special')}
- >
- <span className={styles.badge}>限时特惠</span>
- <h4>特价会员</h4>
- <div>
- <span className={styles.originalPrice}>¥298</span>
- <span className={styles.discount}>3折</span>
- </div>
- <p className={styles.currentPrice}>¥<span>88</span></p>
- </div>
<div
className={`${styles.priceCard} ${selectedPlan === 'month' ? styles.selected : ''}`}
onClick={() => setSelectedPlan('month')}
@@ -72,18 +80,6 @@ export default function VipPage() {
</div>
<p className={styles.currentPrice}>¥<span>128</span></p>
</div>
- <div
- className={`${styles.priceCard} ${selectedPlan === 'halfYear' ? styles.selected : ''}`}
- onClick={() => setSelectedPlan('halfYear')}
- >
- <span className={styles.badge}>推荐</span>
- <h4>半年会员</h4>
- <div>
- <span className={styles.originalPrice}>¥988</span>
- <span className={styles.discount}>5.5折</span>
- </div>
- <p className={styles.currentPrice}>¥<span>548</span></p>
- </div>
<div
className={`${styles.priceCard} ${selectedPlan === 'year' ? styles.selected : ''}`}
onClick={() => setSelectedPlan('year')}
@@ -96,13 +92,16 @@ export default function VipPage() {
</div>
<p className={styles.currentPrice}>¥<span>998</span></p>
</div>
-
</div>
<p className={styles.subscriptionInfo}>自动续订,随时取消</p>
- <button className={styles.activateButton} onClick={handleActivate}>
- 立即开通
+ <button
+ className={styles.activateButton}
+ onClick={handleActivate}
+ disabled={loading}
+ >
+ {loading ? '开通中...' : '立即开通'}
</button>
</div>
);
diff --git a/src/store/user.ts b/src/store/user.ts
index d7493ec6..7bb7ad9b 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -13,6 +13,12 @@ export interface UserInfo {
_id: string;
avatar?: string;
isVip?: boolean;
+ vipInfo?: {
+ id: string;
+ cycleType: number;
+ expireTime: string;
+ _id: string;
+ };
}
export interface IUserStore {