diff --git a/package.json b/package.json index 79dfbfc..cbdd13d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lanhu-web", - "version": "1.13.1", + "version": "1.14.0", "private": true, "scripts": { "dev": "next dev -H 0.0.0.0 --turbopack", diff --git a/src/actions/resource.ts b/src/actions/resource.ts index b6c3ade..0e14afd 100644 --- a/src/actions/resource.ts +++ b/src/actions/resource.ts @@ -80,12 +80,14 @@ export async function completeResource(props: { }) { return callByUser('/api/trade/complete', props) } - +type PayCloseData = { + status: 0 | 1 | 2 +} export async function payClose(props: { trade_no: string method: number }) { - return callByUser('/api/trade/cancel', props) + return callByUser('/api/trade/finish', props) } export async function getPrice(props: CreateResourceReq) { diff --git a/src/components/composites/payment/payment-modal.tsx b/src/components/composites/payment/payment-modal.tsx index f399a2c..53d0ea3 100644 --- a/src/components/composites/payment/payment-modal.tsx +++ b/src/components/composites/payment/payment-modal.tsx @@ -8,7 +8,7 @@ import {payClose} from '@/actions/resource' import {useEffect} from 'react' import {UniversalDesktopPayment} from './universal-desktop-payment' import {useAppStore} from '@/components/stores/app' - +import {toast} from 'sonner' export type PaymentModalProps = { onConfirm: (showFail: boolean) => Promise onClose: () => void @@ -17,45 +17,49 @@ export type PaymentModalProps = { export function PaymentModal(props: PaymentModalProps) { // 手动关闭时的处理 const handleClose = async () => { - // try { - // const res = await payClose({ - // trade_no: props.inner_no, - // method: props.method, - // }) - // if (!res.success) { - // throw new Error(res.message) - // } - // } - // catch (error) { - // console.error('关闭订单失败:', error) - // } - // finally { - props.onClose?.() - // } + try { + const res = await payClose({ + trade_no: props.inner_no, + method: props.method, + }) + + if (!res.success) { + throw new Error(res.message || '请求失败') + } + if (res.data.status === 1) { + toast.success('已支付成功!') + } + } + catch (error) { + console.error('关闭订单失败:', error) + } + finally { + props.onClose?.() + } } // SSE处理方式检查支付状态 - const apiUrl = useAppStore('apiUrl') - useEffect(() => { - const eventSource = new EventSource( - `${apiUrl}/api/trade/check?trade_no=${props.inner_no}&method=${props.method}`, - ) - eventSource.onmessage = async (event) => { - switch (event.data) { - case '1': - props.onConfirm?.(true) - case '2': - props.onClose?.() - } - } - eventSource.onerror = (error) => { - console.error('SSE 连接错误:', error) - } + // const apiUrl = useAppStore('apiUrl') + // useEffect(() => { + // const eventSource = new EventSource( + // `${apiUrl}/api/trade/check?trade_no=${props.inner_no}&method=${props.method}`, + // ) + // eventSource.onmessage = async (event) => { + // switch (event.data) { + // case '1': + // props.onConfirm?.(true) + // case '2': + // props.onClose?.() + // } + // } + // eventSource.onerror = (error) => { + // console.error('SSE 连接错误:', error) + // } - return () => { - eventSource.close() - } - }, [apiUrl, props]) + // return () => { + // eventSource.close() + // } + // }, [apiUrl, props]) return (