From 4f97241268f8c78b1aded0776c55247d3a745ef3 Mon Sep 17 00:00:00 2001 From: yezian Date: Fri, 14 Feb 2025 16:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=87=E7=94=A8=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=B8=A0=E9=81=93=EF=BC=9B=E6=8F=90=E7=8E=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=AA=97=E5=8F=A3=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pay/page.jsx | 122 +++++++++++++++++- app/vip/page.jsx | 110 +++++++++++++++- app/withdrawal/page.jsx | 32 +++-- .../[zid]/[product_id]/[moment_id]/page.jsx | 114 ++++++++++++++-- 4 files changed, 352 insertions(+), 26 deletions(-) diff --git a/app/pay/page.jsx b/app/pay/page.jsx index 56da298..42b5562 100644 --- a/app/pay/page.jsx +++ b/app/pay/page.jsx @@ -29,6 +29,9 @@ export default function Pay() { //选择任意金额充值 const [customCoin, setCustomCoin] = useState({ selected: false, num: 1000 }); + //备用支付渠道是否展示 + const [isBackupPaymentVisible, setIsBackupPaymentVisible] = useState(false); + //任意金额充值的金币数量 const handleChangeCustomCoin = (e) => { let newValue = parseInt(e.target.value, 10); @@ -42,6 +45,11 @@ export default function Pay() { } }; + //备用支付渠道是否展示 + const handleBackupPaymentVisible = () => { + setIsBackupPaymentVisible(true); + }; + //获取当前充值档位 const [isFetching, setIsFetching] = useState(true); const getBase = useCallback( @@ -171,6 +179,88 @@ export default function Pay() { } }; + //创建备用充值订单 + const createBackupPaymentOrder = async (type = "alipay_h5") => { + if (!selectedPrice.id && !customCoin.selected) { + Toast.show({ + content: "请选择充值档位", + }); + return; + } + if (customCoin.selected && customCoin.num < 10) { + Toast.show({ + content: "最低充值1元哦~", + }); + return; + } + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); + + const body = { + ...base, + product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id, + custom_coins: customCoin.selected ? customCoin.num : 0, + pay_type: type, + redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "", + from: searchParams.get("base") ? "web" : "app", + ver: "aliv2", + }; + + //如果是微信jsapi支付直接跳转到中间页 + if (type === "wxpay_jsapi") { + router.push(`/pay/${encodeURIComponent(JSON.stringify(body))}`); + return; + } + + setIsLoading(true); + + const signature = generateSignature(body); + try { + const response = await fetch( + `/api/vas/create_order?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + } + ); + const data = await response.json(); + if (data.ret === -1) { + Toast.show({ + content: data.msg, + }); + return; + } + switch (type) { + case "yeepay_alipay_h5": + router.push(`${data.data.yeepay_alipay_h5_param_str}`); + break; + case "yeepay_wxpay_h5": + router.push(`${data.data.yeepay_wxpay_h5_param_str}`); + break; + case "alipay_h5": + router.push(`${data.data.alipay_h5_param_str}`); + break; + case "wxpay_h5": + router.push( + `https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent( + data.data.wxpay_h5_param_str + )}` + ); + break; + default: + router.push(`${data.data.alipay_h5_param_str}`); + break; + } + } catch (error) { + console.error(error); + } finally { + setIsLoading(false); + } + }; + const PriceItem = ({ item }) => { const handleClickPrice = (item) => { setSelectedPrice(item); @@ -315,7 +405,37 @@ export default function Pay() { -

+ {isBackupPaymentVisible ? ( +

+
createBackupPaymentOrder("alipay_h5")} + className="flex flex-row cursor-pointer gap-1.5 h-11 items-center justify-center bg-primary rounded-full" + > + +

+ 【备用】支付宝支付 +

+
+
+ ) : ( +

+ 若无法支付,请尝试 + + 备用支付渠道 + +

+ )} +

确认购买即视为同意 { + setIsBackupPaymentVisible(true); + }; + const getBase = useCallback( (webviewBase) => { let searchParamsObj = null; @@ -141,6 +149,74 @@ export default function Vip() { } }; + //创建备用充值订单 + const createBackupPaymentOrder = async (type = "alipay_h5") => { + const webviewBase = webviewBaseRequest(); + let base = getBase(webviewBase); + const body = { + ...base, + product_id: "membership", + pay_type: type, + redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "", + from: searchParams.get("base") ? "web" : "app", + ver: "aliv2", + }; + + //如果是微信jsapi支付直接跳转到中间页 + if (type === "wxpay_jsapi") { + router.push(`/pay/${encodeURIComponent(JSON.stringify(body))}`); + return; + } + + setIsLoading(true); + + const signature = generateSignature(body); + try { + const response = await fetch( + `/api/vas/create_order?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + } + ); + const data = await response.json(); + if (data.ret === -1) { + Toast.show({ + content: data.msg, + }); + return; + } + switch (type) { + case "yeepay_alipay_h5": + router.push(`${data.data.yeepay_alipay_h5_param_str}`); + break; + case "yeepay_wxpay_h5": + router.push(`${data.data.yeepay_wxpay_h5_param_str}`); + break; + case "alipay_h5": + router.push(`${data.data.alipay_h5_param_str}`); + break; + case "wxpay_h5": + router.push( + `https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent( + data.data.wxpay_h5_param_str + )}` + ); + break; + default: + router.push(`${data.data.alipay_h5_param_str}`); + break; + } + } catch (error) { + console.error(error); + } finally { + setIsLoading(false); + } + }; + if (isFetching) { return (

@@ -167,7 +243,7 @@ export default function Vip() { src={process.env.NEXT_PUBLIC_CDN_URL + "/public/images/viptitle.png"} alt="" /> -
+
{isVip ? (
-

+ {isBackupPaymentVisible ? ( +

+
createBackupPaymentOrder("alipay_h5")} + className="flex flex-row cursor-pointer gap-1.5 h-11 items-center justify-center bg-primary rounded-full" + > + +

+ 【备用】支付宝支付 +

+
+
+ ) : ( +

+ 若无法支付,请尝试 + + 备用支付渠道 + +

+ )} +

确认购买即视为同意

- 4.自助提现渠道每日只能提现一次,若有更多提现需求,请联系客服。 + 4.提现窗口期为每日8点至22点,请在此时间段进行提现操作; +

+

+ 5.自助提现渠道每日只能提现一次,若有更多提现需求,请联系客服。

diff --git a/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx b/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx index 4f870c6..3d6534a 100644 --- a/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx +++ b/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx @@ -1,7 +1,6 @@ "use client"; import React, { useState, useEffect, useCallback } from "react"; -import Divider from "@/components/Divider"; import Link from "next/link"; import { Toast, Switch, Image } from "antd-mobile"; import { generateSignature } from "@/utils/crypto"; @@ -15,6 +14,14 @@ export default function Pay({ params }) { //当前选购的商品数据 const [data, setData] = useState({}); + //备用支付渠道是否展示 + const [isBackupPaymentVisible, setIsBackupPaymentVisible] = useState(false); + + //备用支付渠道是否展示 + const handleBackupPaymentVisible = () => { + setIsBackupPaymentVisible(true); + }; + //超粉商品数据 const [superfanshipData, setSuperfanshipData] = useState(); const [isFetching, setIsFetching] = useState(true); @@ -206,6 +213,68 @@ export default function Pay({ params }) { } }; + //创建备用充值订单 + const createBackupPaymentOrder = async (type = "alipay_h5") => { + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); + const body = { + ...base, + zid: parseInt(params.zid), + moment_id: parseInt(params.moment_id), + product_id: checked ? superId : params.product_id, + pay_type: type, + redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "", + from: searchParams.get("base") ? "web" : "app", + ver: "aliv2", + }; + setIsLoading(true); + const signature = generateSignature(body); + try { + const response = await fetch( + `/api/zone/create_order?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + } + ); + const data = await response.json(); + if (data.ret === -1) { + Toast.show({ + content: data.msg, + }); + return; + } + switch (type) { + case "yeepay_alipay_h5": + router.push(`${data.data.yeepay_alipay_h5_param_str}`); + break; + case "yeepay_wxpay_h5": + router.push(`${data.data.yeepay_wxpay_h5_param_str}`); + break; + case "alipay_h5": + router.push(`${data.data.alipay_h5_param_str}`); + break; + case "wxpay_h5": + router.push( + `https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent( + data.data.wxpay_h5_param_str + )}` + ); + break; + default: + router.push(`${data.data.alipay_h5_param_str}`); + break; + } + } catch (error) { + console.error(error); + } finally { + setIsLoading(false); + } + }; + const handleSelectSuper = (it) => { selectedIndex = it.index; setSuperChecked({ ...it, selected: it.index }); @@ -313,17 +382,6 @@ export default function Pay({ params }) { : "/public/icon/superFan_price_select.png") } /> - {/* setChecked(!checked)} - > */} - {/* setChecked(!checked)} - style={{ - "--checked-color": "#FFE9AB", - }} - /> */}
)} {params.product_id === "h5_zone_superfanship" && ( @@ -479,7 +537,37 @@ export default function Pay({ params }) {
-

+ {isBackupPaymentVisible ? ( +

+
createBackupPaymentOrder("alipay_h5")} + className="flex flex-row cursor-pointer gap-1.5 h-11 items-center justify-center bg-primary rounded-full" + > + +

+ 【备用】支付宝支付 +

+
+
+ ) : ( +

+ 若无法支付,请尝试 + + 备用支付渠道 + +

+ )} +

确认购买即视为同意