首页接口更新&&支付页面调试
This commit is contained in:
@@ -14,4 +14,15 @@ export default createMDX({
|
||||
mdxType: 'gfm',
|
||||
},
|
||||
},
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'pay.rscygroup.com',
|
||||
port: '',
|
||||
pathname: '/api/scan/imgs/*',
|
||||
search: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
19
src/actions/announcement.ts
Normal file
19
src/actions/announcement.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
'use server'
|
||||
|
||||
import {PageRecord} from '@/lib/api'
|
||||
import {Announcement} from '@/lib/models'
|
||||
import {callByUser} from './base'
|
||||
|
||||
export async function listAnnouncements(props: {
|
||||
page: number
|
||||
size: number
|
||||
title?: string
|
||||
type?: number
|
||||
status?: number
|
||||
create_after?: Date
|
||||
create_before?: Date
|
||||
update_after?: Date
|
||||
update_before?: Date
|
||||
}) {
|
||||
return await callByUser<PageRecord<Announcement>>('/api/announcement/list', props)
|
||||
}
|
||||
@@ -1,34 +1,11 @@
|
||||
'use server'
|
||||
|
||||
import {ApiResponse, ExtraResp} from '@/lib/api'
|
||||
import {callByUser} from './base'
|
||||
|
||||
export async function listInitialization(props: {
|
||||
page: number
|
||||
size: number
|
||||
title?: string
|
||||
type?: number
|
||||
status?: number
|
||||
create_after?: Date
|
||||
create_before?: Date
|
||||
update_after?: Date
|
||||
update_before?: Date
|
||||
short_term_package?: number
|
||||
}) {
|
||||
return await callByUser<{
|
||||
short_term: string
|
||||
short_term_monthly: string
|
||||
long_term: string
|
||||
long_term_monthly: string
|
||||
list: {
|
||||
id: number
|
||||
title: string
|
||||
created_at: Date
|
||||
}[]
|
||||
}>('/api/announcement/list', props)
|
||||
}
|
||||
import {listAnnouncements} from './announcement'
|
||||
|
||||
type listAccountReq = {
|
||||
resource_no: string
|
||||
resource_no?: string
|
||||
create_after: Date
|
||||
create_before: Date
|
||||
}
|
||||
@@ -39,5 +16,68 @@ type listAccountResp = {
|
||||
}[]
|
||||
|
||||
export async function listAccount(props: listAccountReq) {
|
||||
return await callByUser<listAccountResp>('/api/account/list', props)
|
||||
return await callByUser<listAccountResp>('/api/resource/statistics/usage', props)
|
||||
}
|
||||
|
||||
export async function statisticsResourceFree() {
|
||||
return await callByUser<{
|
||||
long: {
|
||||
ResourceCount: number
|
||||
ResourceDailyFreeSum: number
|
||||
ResourceQuotaSum: number
|
||||
}
|
||||
short: {
|
||||
ResourceCount: number
|
||||
ResourceDailyFreeSum: number
|
||||
ResourceQuotaSum: number
|
||||
}
|
||||
}>('/api/resource/statistics/free')
|
||||
}
|
||||
|
||||
type listInitializationResp = {
|
||||
anno: ExtraResp<typeof listAnnouncements>
|
||||
free: ExtraResp<typeof statisticsResourceFree>
|
||||
usage: ExtraResp<typeof listAccount>
|
||||
}
|
||||
export async function listInitialization(): Promise<ApiResponse<listInitializationResp>> {
|
||||
const free = await statisticsResourceFree()
|
||||
if (!free.success) {
|
||||
return {
|
||||
success: false,
|
||||
status: 500,
|
||||
message: '套餐剩余数据获取失败',
|
||||
}
|
||||
}
|
||||
const anno = await listAnnouncements({
|
||||
page: 1,
|
||||
size: 5,
|
||||
})
|
||||
if (!anno.success) {
|
||||
return {
|
||||
success: false,
|
||||
status: 500,
|
||||
message: '公告数据获取失败',
|
||||
}
|
||||
}
|
||||
const usage = await listAccount({
|
||||
create_after: new Date(),
|
||||
create_before: new Date(),
|
||||
})
|
||||
if (!usage.success) {
|
||||
return {
|
||||
success: false,
|
||||
status: 500,
|
||||
message: '套餐用量数据获取失败',
|
||||
}
|
||||
}
|
||||
const data = {
|
||||
anno: anno.data,
|
||||
free: free.data,
|
||||
usage: usage.data,
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,8 @@ import mask from './_assets/Mask group.webp'
|
||||
export type DashboardPageProps = {}
|
||||
|
||||
export default async function DashboardPage(props: DashboardPageProps) {
|
||||
const resp = await listInitialization({
|
||||
page: 1,
|
||||
size: 5,
|
||||
})
|
||||
|
||||
const resp = await listInitialization()
|
||||
console.log(resp, 'respresprespresprespresp')
|
||||
if (!resp.success) {
|
||||
return (
|
||||
<div className="col-start-4 row-start-3 row-span-2 flex justify-center items-center">
|
||||
@@ -47,10 +44,10 @@ export default async function DashboardPage(props: DashboardPageProps) {
|
||||
{/* 磁贴集 */}
|
||||
{initData && (
|
||||
<Pins
|
||||
short_term={String(initData.short_term)}
|
||||
short_term_monthly={String(initData.short_term_monthly)}
|
||||
long_term={String(initData.long_term)}
|
||||
long_term_monthly={String(initData.long_term_monthly)}
|
||||
short_term={String(initData.free.short.ResourceCount)}
|
||||
short_term_monthly={String(initData.free.short.ResourceQuotaSum)}
|
||||
long_term={String(initData.free.long.ResourceCount)}
|
||||
long_term_monthly={String(initData.free.long.ResourceDailyFreeSum)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -65,7 +62,7 @@ export default async function DashboardPage(props: DashboardPageProps) {
|
||||
{/* 通知 */}
|
||||
<div className="md:col-start-4 md:row-start-3 md:row-span-2">
|
||||
{initData && (
|
||||
<Announcements list={initData.list}/>
|
||||
<Announcements list={initData.anno.list}/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
11
src/app/callback/sftpay/page.tsx
Normal file
11
src/app/callback/sftpay/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import {ReactNode} from 'react'
|
||||
|
||||
export type SftpayPageProps = {
|
||||
|
||||
}
|
||||
|
||||
export default async function SftpayPage(props: SftpayPageProps) {
|
||||
return (
|
||||
<div>111</div>
|
||||
)
|
||||
}
|
||||
@@ -3,45 +3,19 @@ import {DialogContent, DialogHeader, DialogTitle} from '@/components/ui/dialog'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {completeResource} from '@/actions/resource'
|
||||
import {toast} from 'sonner'
|
||||
import {CheckCircle, Loader} from 'lucide-react'
|
||||
import {Loader} from 'lucide-react'
|
||||
import {useState, useEffect, useRef} from 'react'
|
||||
import * as qrcode from 'qrcode'
|
||||
import Image from 'next/image'
|
||||
import {TradeMethod} from '@/lib/models/trade'
|
||||
import {PaymentModalProps} from './payment-modal'
|
||||
|
||||
export function DesktopPayment(props: PaymentModalProps) {
|
||||
console.log(props, 'props')
|
||||
const [paymentVerified, setPaymentVerified] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!canvasRef.current || props.method === TradeMethod.Alipay) return
|
||||
qrcode.toCanvas(canvasRef.current, props.pay_url, {width: 200})
|
||||
.catch((err) => {
|
||||
console.error('生成二维码失败:', err)
|
||||
toast.error('生成支付二维码失败')
|
||||
})
|
||||
}, [props.method, props.pay_url])
|
||||
|
||||
const handleComplete = async () => {
|
||||
const onSubmit = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const resp = await completeResource({trade_no: props.inner_no})
|
||||
if (!resp.success) throw new Error(resp.message)
|
||||
toast.success('支付成功')
|
||||
setPaymentVerified(true)
|
||||
setTimeout(() => props.onSuccess?.(), 2000)
|
||||
}
|
||||
catch (e) {
|
||||
toast.error('支付验证失败', {description: (e as Error).message})
|
||||
}
|
||||
finally {
|
||||
setLoading(false)
|
||||
}
|
||||
await props.onConfirm?.()
|
||||
setLoading(false)
|
||||
}
|
||||
console.log(props.decoration.text, 'props.decoration.text')
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
@@ -62,52 +36,44 @@ export function DesktopPayment(props: PaymentModalProps) {
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{paymentVerified ? (
|
||||
<div className="text-center py-8">
|
||||
<CheckCircle className="mx-auto text-green-500 w-12 h-12"/>
|
||||
<p className="mt-4 text-lg font-medium">支付验证成功</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<div className="bg-gray-100 w-52 h-52 flex items-center justify-center">
|
||||
{props.method === TradeMethod.Alipay ? (
|
||||
<iframe src={props.pay_url} className="w-full h-full"/>
|
||||
) : (
|
||||
<canvas ref={canvasRef} className="w-full h-full"/>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-gray-600">
|
||||
请使用
|
||||
{props.decoration.text}
|
||||
扫码支付
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<Image
|
||||
src={props.pay_url}
|
||||
width={208}
|
||||
height={208}
|
||||
alt="二维码"
|
||||
/>
|
||||
<p className="text-sm text-gray-600">
|
||||
请使用
|
||||
{props.decoration.text}
|
||||
扫码支付
|
||||
</p>
|
||||
|
||||
<div className="w-full text-center space-y-2">
|
||||
<p className="text-sm font-medium">
|
||||
支付金额:
|
||||
{' '}
|
||||
<span className="text-accent">
|
||||
¥
|
||||
{props.amount?.toFixed(2) || '0.00'}
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
订单号:
|
||||
{props.inner_no}
|
||||
</p>
|
||||
|
||||
<div className="w-full text-center space-y-2">
|
||||
<p className="text-sm font-medium">
|
||||
支付金额:
|
||||
{' '}
|
||||
<span className="text-accent">
|
||||
¥
|
||||
{props.amount?.toFixed(2) || '0.00'}
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
订单号:
|
||||
{props.inner_no}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4 w-full justify-center">
|
||||
<Button onClick={handleComplete} >
|
||||
{loading && <Loader className="animate-spin mr-2"/>}
|
||||
已完成支付
|
||||
</Button>
|
||||
<Button theme="outline" onClick={() => props.onClose?.()}>
|
||||
关闭
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-4 w-full justify-center">
|
||||
<Button onClick={onSubmit}>
|
||||
{loading && <Loader className="animate-spin mr-2"/>}
|
||||
已完成支付
|
||||
</Button>
|
||||
<Button theme="outline" onClick={() => props.onClose?.()}>
|
||||
关闭
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,91 +9,62 @@ import Image from 'next/image'
|
||||
import {PaymentModalProps} from './payment-modal'
|
||||
|
||||
export function MobilePayment(props: PaymentModalProps) {
|
||||
console.log(props, 'props')
|
||||
|
||||
const [paymentVerified, setPaymentVerified] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const handleComplete = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const resp = await completeResource({trade_no: props.inner_no})
|
||||
if (!resp.success) throw new Error(resp.message)
|
||||
toast.success('支付成功')
|
||||
setPaymentVerified(true)
|
||||
props.onClose?.()
|
||||
}
|
||||
catch (e) {
|
||||
toast.error('支付验证失败', {description: (e as Error).message})
|
||||
}
|
||||
finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent className="max-w-[95vw] rounded-lg">
|
||||
{paymentVerified ? (
|
||||
<div className="py-6 text-center">
|
||||
<CheckCircle className="mx-auto h-14 w-14 text-green-500"/>
|
||||
<p className="mt-4 text-lg font-medium">支付验证成功</p>
|
||||
<div className="flex flex-col gap-6">
|
||||
{/* 支付确认信息 */}
|
||||
<div className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 text-blue-500">
|
||||
<CreditCard className="h-8 w-8"/>
|
||||
</div>
|
||||
<h3 className="text-lg font-semibold text-gray-800">确认支付</h3>
|
||||
<p className="text-gray-500">请确认以下支付信息</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
{/* 支付确认信息 */}
|
||||
<div className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 text-blue-500">
|
||||
<CreditCard className="h-8 w-8"/>
|
||||
</div>
|
||||
<h3 className="text-lg font-semibold text-gray-800">确认支付</h3>
|
||||
<p className="text-gray-500">请确认以下支付信息</p>
|
||||
</div>
|
||||
|
||||
{/* 支付详情 */}
|
||||
<div className="space-y-4 rounded-lg bg-gray-50 p-4">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">订单号</span>
|
||||
<span className="font-medium">{props.inner_no}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">支付方式</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{props.decoration.icon && (
|
||||
<Image
|
||||
src={props.decoration.icon}
|
||||
alt={props.decoration.text}
|
||||
width={28}
|
||||
height={28}
|
||||
className="rounded-md"
|
||||
/>
|
||||
)}
|
||||
<span>{props.decoration.text}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">支付金额</span>
|
||||
<span className="text-lg font-bold text-blue-600">
|
||||
¥
|
||||
{' '}
|
||||
{props.amount.toFixed(2)}
|
||||
</span>
|
||||
{/* 支付详情 */}
|
||||
<div className="space-y-4 rounded-lg bg-gray-50 p-4">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">订单号</span>
|
||||
<span className="font-medium">{props.inner_no}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">支付方式</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{props.decoration.icon && (
|
||||
<Image
|
||||
src={props.decoration.icon}
|
||||
alt={props.decoration.text}
|
||||
width={28}
|
||||
height={28}
|
||||
className="rounded-md"
|
||||
/>
|
||||
)}
|
||||
<span>{props.decoration.text}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
theme="outline"
|
||||
className="flex-1 py-3 text-base"
|
||||
onClick={props.onClose} >
|
||||
取消
|
||||
</Button>
|
||||
<Button className="flex-1 py-3 text-base" onClick={() => window.location.href = props.pay_url} >
|
||||
确认支付
|
||||
</Button>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-600">支付金额</span>
|
||||
<span className="text-lg font-bold text-blue-600">
|
||||
¥
|
||||
{' '}
|
||||
{props.amount.toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
theme="outline"
|
||||
className="flex-1 py-3 text-base"
|
||||
onClick={props.onClose} >
|
||||
取消
|
||||
</Button>
|
||||
<Button className="flex-1 py-3 text-base" onClick={() => window.location.href = props.pay_url} >
|
||||
确认支付
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export function PaymentButton({
|
||||
{trade && (
|
||||
<PaymentModal
|
||||
{...trade}
|
||||
onSuccess={onSuccess}
|
||||
onConfirm={onSuccess}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -6,17 +6,11 @@ import {Dialog} from '@/components/ui/dialog'
|
||||
import {PaymentProps} from './type'
|
||||
|
||||
export type PaymentModalProps = {
|
||||
onSuccess?: () => void
|
||||
onConfirm?: () => Promise<void>
|
||||
onClose?: () => void
|
||||
} & PaymentProps
|
||||
|
||||
export function PaymentModal(props: PaymentModalProps) {
|
||||
const handleClose = (success: boolean) => {
|
||||
if (success && props.onSuccess) {
|
||||
props.onSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
defaultOpen={true}
|
||||
|
||||
@@ -25,8 +25,6 @@ export type PayProps = {
|
||||
}
|
||||
|
||||
export default function Pay(props: PayProps) {
|
||||
console.log(props, 'props')
|
||||
|
||||
const profile = useProfileStore(store => store.profile)
|
||||
const refreshProfile = useProfileStore(store => store.refreshProfile)
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -44,7 +42,6 @@ export default function Pay(props: PayProps) {
|
||||
: props.method === 'alipay'
|
||||
? TradeMethod.SftAlipay
|
||||
: TradeMethod.SftWechat
|
||||
console.log(method, 'methodConfig')
|
||||
|
||||
const res = {
|
||||
...props.resource,
|
||||
@@ -111,7 +108,6 @@ export default function Pay(props: PayProps) {
|
||||
立即支付
|
||||
</Button>
|
||||
|
||||
{/* 余额支付对话框 */}
|
||||
{/* 余额支付对话框 */}
|
||||
{props.method === 'balance' && (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
@@ -186,11 +182,21 @@ export default function Pay(props: PayProps) {
|
||||
{props.method !== 'balance' && trade && (
|
||||
<PaymentModal
|
||||
{...trade}
|
||||
onSuccess={() => {
|
||||
toast.success('支付成功')
|
||||
setTrade(null)
|
||||
setOpen(false)
|
||||
refreshProfile()
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
const resp = await completeResource({trade_no: trade.inner_no})
|
||||
if (!resp.success) {
|
||||
throw new Error(resp.message)
|
||||
}
|
||||
|
||||
toast.success('支付成功')
|
||||
setTrade(null)
|
||||
setOpen(false)
|
||||
refreshProfile()
|
||||
}
|
||||
catch (e) {
|
||||
toast.error('支付验证失败', {description: (e as Error).message})
|
||||
}
|
||||
}}
|
||||
onClose={() => {
|
||||
setTrade(null)
|
||||
|
||||
@@ -14,7 +14,7 @@ import FormOption from '@/components/composites/purchase/option'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import {zodResolver} from '@hookform/resolvers/zod'
|
||||
import {toast} from 'sonner'
|
||||
import {useMemo, useState} from 'react'
|
||||
import {useState} from 'react'
|
||||
import {RechargePrepare} from '@/actions/user'
|
||||
import {useProfileStore} from '@/components/stores-provider'
|
||||
import {merge} from '@/lib/utils'
|
||||
@@ -75,6 +75,7 @@ export default function RechargeModal(props: RechargeModelProps) {
|
||||
console.log(req, '请求参数')
|
||||
|
||||
const result = await RechargePrepare(req)
|
||||
console.log(result, 'result返回结果')
|
||||
|
||||
if (result.success) {
|
||||
setTrade({
|
||||
@@ -98,15 +99,22 @@ export default function RechargeModal(props: RechargeModelProps) {
|
||||
}
|
||||
|
||||
const handlePaymentSuccess = async () => {
|
||||
if (!trade) return
|
||||
try {
|
||||
await refreshProfile()
|
||||
const resp = await RechargeComplete({trade_no: trade.inner_no})
|
||||
if (!resp.success) {
|
||||
throw new Error(resp.message)
|
||||
}
|
||||
|
||||
toast.success('充值成功')
|
||||
setTrade(undefined) // 清除交易状态
|
||||
setOpen(false) // 关闭弹窗
|
||||
form.reset() // 重置表单
|
||||
|
||||
await refreshProfile()
|
||||
}
|
||||
catch (e) {
|
||||
toast.error('刷新账户信息失败')
|
||||
toast.error('支付验证失败', {description: (e as Error).message})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +225,7 @@ export default function RechargeModal(props: RechargeModelProps) {
|
||||
) : (
|
||||
<PaymentModal
|
||||
{...trade}
|
||||
onSuccess={handlePaymentSuccess}
|
||||
onConfirm={handlePaymentSuccess}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user