tiefen_space_web/app/withdrawal/page.jsx

148 lines
4.9 KiB
React
Raw Normal View History

2024-01-03 01:07:16 +08:00
"use client";
import React, { useState, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { setCookie, getCookie } from "cookies-next";
import { useRouter } from "next/navigation";
import baseRequest from "@/utils/baseRequest";
import { Toast } from "antd-mobile";
import { generateSignature } from "@/utils/crypto";
export default function WithDrawal() {
const router = useRouter();
const searchParams = useSearchParams();
const mid = searchParams.get("mid");
const token = searchParams.get("token");
const mobile_phone = searchParams.get("mobile_phone");
//将searchParams中的mid和token写入cookie并重定向到没有searchParams的路由
useEffect(() => {
if (mid && token && mobile_phone) {
setCookie("mid", mid);
setCookie("token", token);
setCookie("mobile_phone", mobile_phone);
router.replace("/withdrawal");
}
}, [mid, token, mobile_phone]);
2024-06-25 17:38:49 +08:00
//查看主播实名认证情况和可提现数额
2024-01-03 01:07:16 +08:00
const [data, setData] = useState({});
useEffect(() => {
const getData = async () => {
const mid = getCookie("mid");
if (!mid) return;
try {
const base = baseRequest();
2024-06-25 17:38:49 +08:00
const body = {
2024-01-03 01:07:16 +08:00
...base,
2024-06-25 17:38:49 +08:00
};
const signature = generateSignature(body);
2024-01-03 01:07:16 +08:00
const verificationResponse = await fetch(
2024-06-25 17:38:49 +08:00
`/api/hvyogo/query_agree_state?signature=${signature}`,
2024-01-03 01:07:16 +08:00
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
2024-06-25 17:38:49 +08:00
body: JSON.stringify(body),
2024-01-03 01:07:16 +08:00
}
);
const verificationData = await verificationResponse.json();
if (verificationData.ret === -1) {
Toast.show({
content: verificationData.msg,
});
}
const signature2 = generateSignature({
...base,
});
const withdrawalResponse = await fetch(
`/api/vas/withdraw_page?signature=${signature2}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
...base,
}),
}
);
const withdrawalData = await withdrawalResponse.json();
if (withdrawalData.ret === -1) {
Toast.show({
content: withdrawalData.msg,
});
2024-01-03 01:07:16 +08:00
return;
}
setData({
2024-06-25 17:38:49 +08:00
verificationStatus: verificationData.data?.agree_state,
withdrawal_diamond: withdrawalData.data.withdraw_diamonds,
2024-06-28 23:14:36 +08:00
diamonds: withdrawalData.data.diamonds,
2024-01-03 01:07:16 +08:00
});
} catch (error) {
console.error(error);
}
};
getData();
}, []);
2024-06-25 17:38:49 +08:00
//跳转实名认证
const handleVerify = () => {
const token = getCookie("token");
2024-06-28 23:14:36 +08:00
const huiYongGongUrl = `https://h5-channel.hvyogo.com/?channel=CDLX&token=${token}`;
2024-06-25 17:38:49 +08:00
router.push(huiYongGongUrl);
2024-01-03 01:07:16 +08:00
};
return (
<section className="container flex flex-col flex-1 p-4">
2024-06-25 17:38:49 +08:00
<div className="flex flex-row justify-between items-center bg-[#FFFFFF1A] rounded-2xl p-4">
<p className="text-secondary text-base font-medium">
可提现钻石
<span className="text-white text-xl font-medium">
2024-01-03 01:07:16 +08:00
{data?.withdrawal_diamond}
2024-06-25 17:38:49 +08:00
</span>
2024-01-03 01:07:16 +08:00
</p>
2024-06-25 17:38:49 +08:00
{data?.verificationStatus === 2 ? (
<button
onClick={() => router.push("/withdrawal/checkout")}
className="btn btn-sm btn-primary text-white rounded-full"
>
提现
</button>
) : (
2024-01-03 01:07:16 +08:00
<button
2024-06-25 17:38:49 +08:00
onClick={handleVerify}
className="btn btn-sm btn-primary text-white rounded-full"
2024-01-03 01:07:16 +08:00
>
2024-06-25 17:38:49 +08:00
实名认证
2024-01-03 01:07:16 +08:00
</button>
2024-06-25 17:38:49 +08:00
)}
2024-01-03 01:07:16 +08:00
</div>
2024-06-25 17:38:49 +08:00
<div className="flex flex-row justify-between items-center bg-[#FFFFFF1A] rounded-2xl p-4 my-4">
<p className="text-secondary text-base font-medium">
钻石总额
2024-06-28 23:14:36 +08:00
<span className="text-white text-xl font-medium">
{data?.diamonds}
</span>
2024-06-25 17:38:49 +08:00
</p>
</div>
<p className="text-secondary text-base mt-2">注意事项</p>
<p className="text-secondary text-sm">
1.需实名认证并绑定收款方式后方可提现
</p>
<p className="text-secondary text-sm">
2.平台将收取提现金额的3%作为提现手续费用该笔费用将用于为收款人缴纳相关税费
2024-01-03 01:07:16 +08:00
</p>
2024-06-25 17:38:49 +08:00
<p className="text-secondary text-sm">
3.收款账户需与实名认证本人保持一致
2024-01-03 01:07:16 +08:00
</p>
2024-06-25 17:38:49 +08:00
<p className="text-secondary text-sm">
4.单笔最低提现金额为100元即1,000钻石单月最高提现金额为95,000即950,000钻石
2024-01-03 01:07:16 +08:00
</p>
2024-06-25 17:38:49 +08:00
<p className="text-secondary text-sm">
5.自助提现渠道每日只能提现一次若有更多提现需求请联系客服
2024-01-03 01:07:16 +08:00
</p>
</section>
);
}