diff --git a/.gitignore b/.gitignore index 8f322f0..eaaee16 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +package-lock.json \ No newline at end of file diff --git a/app/bill/[type]/page.jsx b/app/bill/[type]/page.jsx index 465fb06..eb89278 100644 --- a/app/bill/[type]/page.jsx +++ b/app/bill/[type]/page.jsx @@ -1,14 +1,25 @@ "use client"; -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import { Toast } from "antd-mobile"; import { generateSignature } from "@/utils/crypto"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; +import { useSearchParams } from "next/navigation"; import Link from "next/link"; export default function BillDetail({ params }) { const [data, setData] = useState([]); const [isFetching, setIsFetching] = useState(true); + const searchParams = useSearchParams(); + const getBase = useCallback((webviewBase)=>{ + let searchParamsObj=null; + let currentBaseCode = searchParams.get("base") + if(currentBaseCode){ + let currentBase = JSON.parse(currentBaseCode); + searchParamsObj={...currentBase}; + } + return searchParamsObj || webviewBase; + },[searchParams]); useEffect(() => { const getData = async () => { let type; @@ -29,7 +40,8 @@ export default function BillDetail({ params }) { break; } try { - const base = webviewBaseRequest(); + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); const signature = generateSignature({ type: type, offset: 0, @@ -97,7 +109,10 @@ export default function BillDetail({ params }) { return (
{params.type == "income" && ( - +

查看近一周收益情况

)} diff --git a/app/pay/page.jsx b/app/pay/page.jsx index 1c46f0d..170fd8c 100644 --- a/app/pay/page.jsx +++ b/app/pay/page.jsx @@ -1,7 +1,7 @@ "use client"; -import React, { useState, useEffect } from "react"; -import { useRouter } from "next/navigation"; +import React, { useState, useEffect,useCallback } from "react"; +import { useRouter, useSearchParams } from "next/navigation"; import { Toast } from "antd-mobile"; import { generateSignature } from "@/utils/crypto"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; @@ -9,9 +9,16 @@ import Link from "next/link"; export default function Pay() { const router = useRouter(); - - //是否显示被隐藏的支付方式 - const [isPaymentHided, setIsPaymentHided] = useState(true); + const searchParams = useSearchParams(); + const alipayBlock = () => { + if (base?.b_mid === 161) { + createOrder("alipay_h5"); + return; + } + Toast.show({ + content: "支付渠道维护升级中,请24小时后再试", + }); + }; //商品列表 const [productList, setProductList] = useState([]); @@ -37,9 +44,19 @@ export default function Pay() { //获取当前充值档位 const [isFetching, setIsFetching] = useState(true); + const getBase = useCallback((webviewBase)=>{ + let searchParamsObj=null; + let currentBaseCode = searchParams.get("base") + if(currentBaseCode){ + let currentBase = JSON.parse(currentBaseCode); + searchParamsObj={...currentBase}; + } + return searchParamsObj || webviewBase; + },[searchParams]); useEffect(() => { const getData = async () => { - const base = webviewBaseRequest(); + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); const body = { ...base }; const signature = generateSignature(body); try { @@ -84,15 +101,16 @@ export default function Pay() { }); return; } - - const base = webviewBaseRequest(); + 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: "app", + from: searchParams.get("base")?"web":"app", }; //如果是微信jsapi支付直接跳转到中间页 diff --git a/app/vip/page.jsx b/app/vip/page.jsx index 9094653..5acaf5d 100644 --- a/app/vip/page.jsx +++ b/app/vip/page.jsx @@ -1,25 +1,42 @@ "use client"; -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import { generateSignature } from "@/utils/crypto"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; import Link from "next/link"; import { Toast } from "antd-mobile"; -import { useRouter } from "next/navigation"; - +import { useRouter, useSearchParams } from "next/navigation"; export default function Vip() { const router = useRouter(); - - //是否显示被隐藏的支付方式 - const [isPaymentHided, setIsPaymentHided] = useState(true); + const searchParams = useSearchParams(); + const alipayBlock = () => { + if (base?.b_mid === 161) { + createOrder("alipay_h5"); + return; + } + Toast.show({ + content: "支付渠道维护升级中,请24小时后再试", + }); + }; //检查用户是否是vip const [isVip, setIsVip] = useState(false); const [name, setName] = useState(""); const [isFetching, setIsFetching] = useState(true); + + const getBase = useCallback((webviewBase)=>{ + let searchParamsObj=null; + let currentBaseCode = searchParams.get("base") + if(currentBaseCode){ + let currentBase = JSON.parse(currentBaseCode); + searchParamsObj={...currentBase}; + } + return searchParamsObj || webviewBase; + },[searchParams]); const getUserData = async () => { + const webviewBase = webviewBaseRequest(); + let base = getBase(webviewBase) try { - const base = webviewBaseRequest(); const signature = generateSignature({ ...base, mid: base.b_mid, @@ -56,9 +73,9 @@ export default function Vip() { setTimeout(() => { getUserData(); }, 500); - const intervalId = setInterval(() => { - getUserData(); - }, 2000); + // const intervalId = setInterval(() => { + // getUserData(); + // }, 2000); return () => clearInterval(intervalId); }, []); @@ -77,7 +94,7 @@ export default function Vip() { product_id: "membership", pay_type: type, redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "", - from: "app", + from: searchParams.get("base")?"web":"app", }; //如果是微信jsapi支付直接跳转到中间页 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 0f02672..d5e0776 100644 --- a/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx +++ b/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx @@ -1,35 +1,46 @@ "use client"; -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import Divider from "@/components/Divider"; import Link from "next/link"; import { Toast, Switch } from "antd-mobile"; import { generateSignature } from "@/utils/crypto"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; -import { useRouter } from "next/navigation"; +import { useRouter, useSearchParams } from "next/navigation"; export default function Pay({ params }) { const router = useRouter(); - - //是否显示被隐藏的支付方式 - const [isPaymentHided, setIsPaymentHided] = useState(true); - + const searchParams = useSearchParams(); //当前选购的商品数据 const [data, setData] = useState({}); //超粉商品数据 const [superfanshipData, setSuperfanshipData] = useState(); const [isFetching, setIsFetching] = useState(true); - + const getBase = useCallback( + (webviewBase) => { + let searchParamsObj = null; + let currentBaseCode = searchParams.get("base"); + // console.log("currentBaseCode", currentBaseCode); + if (currentBaseCode) { + let currentBase = JSON.parse(currentBaseCode); + searchParamsObj = { ...currentBase }; + } + return searchParamsObj || webviewBase; + }, + [searchParams] + ); //获取当前选购的商品数据 const getData = async () => { try { - const base = webviewBaseRequest(); + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); const body = { zid: parseInt(params.zid), moment_id: parseInt(params.moment_id), product_id: params.product_id, ...base, }; + // console.log("body1", body); const signature = generateSignature(body); const response = await fetch( `/api/zone/get_cashier?signature=${signature}`, @@ -58,12 +69,14 @@ export default function Pay({ params }) { //获取超粉商品数据 const getSuperfanshipData = async () => { try { - const base = webviewBaseRequest(); + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); const body = { zid: parseInt(params.zid), product_id: "h5_zone_superfanship", ...base, }; + // console.log("body2", body); const signature = generateSignature(body); const response = await fetch( `/api/zone/get_cashier?signature=${signature}`, @@ -89,11 +102,11 @@ export default function Pay({ params }) { getData(); getSuperfanshipData(); }, 500); - const intervalId = setInterval(() => { - getData(); - getSuperfanshipData(); - }, 2000); - return () => clearInterval(intervalId); + // const intervalId = setInterval(() => { + // getData(); + // getSuperfanshipData(); + // }, 2000); + // return () => clearInterval(intervalId); }, []); //是否勾选购买超粉switch组件 @@ -104,7 +117,8 @@ export default function Pay({ params }) { //创建订单 const [isLoading, setIsLoading] = useState(false); const createOrder = async (type = "alipay_h5") => { - const base = webviewBaseRequest(); + const webviewBase = webviewBaseRequest(); + const base = getBase(webviewBase); const body = { ...base, zid: parseInt(params.zid), @@ -112,9 +126,9 @@ export default function Pay({ params }) { product_id: checked ? "h5_zone_superfanship" : params.product_id, pay_type: type, redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "", - from: "app", + from: searchParams.get("base") ? "web" : "app", }; - + // console.log("body", body); setIsLoading(true); const signature = generateSignature(body);