Compare commits
4 Commits
v1.9.0
...
3dfe8a2b52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dfe8a2b52 | ||
|
|
ea26e2fa1b | ||
|
|
b82f4cab1c | ||
|
|
e70cfbd9a8 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lanhu-admin",
|
"name": "lanhu-admin",
|
||||||
"version": "1.9.0",
|
"version": "1.10.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ export async function createCust(data: {
|
|||||||
return callByUser<PageRecord<User>>("/api/admin/user/create", data)
|
return callByUser<PageRecord<User>>("/api/admin/user/create", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDeposit(params: { user_id: number; amount: string }) {
|
export async function getDeposit(params: {
|
||||||
|
user_id: number
|
||||||
|
amount: string
|
||||||
|
remark: string
|
||||||
|
}) {
|
||||||
return callByUser<PageRecord<User>>(
|
return callByUser<PageRecord<User>>(
|
||||||
"/api/admin/user/update/balance-inc",
|
"/api/admin/user/update/balance-inc",
|
||||||
params,
|
params,
|
||||||
@@ -54,6 +58,7 @@ export async function getDeposit(params: { user_id: number; amount: string }) {
|
|||||||
export async function getDeduction(params: {
|
export async function getDeduction(params: {
|
||||||
user_id: number
|
user_id: number
|
||||||
amount: string
|
amount: string
|
||||||
|
remark: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<User>>(
|
return callByUser<PageRecord<User>>(
|
||||||
"/api/admin/user/update/balance-dec",
|
"/api/admin/user/update/balance-dec",
|
||||||
|
|||||||
@@ -30,3 +30,46 @@ export async function getTrade(params: {
|
|||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Trade>>("/api/admin/trade/page/of-user", params)
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/page/of-user", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateTradeRemark(params: {
|
||||||
|
trade_no: string
|
||||||
|
remark: string
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/update/remark", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PayCloseData = {
|
||||||
|
Status: 0 | 1 | 2
|
||||||
|
TransId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTradeCheckk(params: {
|
||||||
|
trade_no: string
|
||||||
|
method: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PayCloseData>("/api/admin/trade/check", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function tradeComplete(params: {
|
||||||
|
trade_no: string
|
||||||
|
method: number
|
||||||
|
user_id: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PayCloseData>("/api/admin/trade/complete", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function tradeConvert(params: {
|
||||||
|
trade_no: string
|
||||||
|
method: number
|
||||||
|
user_id: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PayCloseData>("/api/admin/trade/convert", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function tradeCancel(params: {
|
||||||
|
trade_no: string
|
||||||
|
method: number
|
||||||
|
user_id: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PayCloseData>("/api/admin/trade/cancel", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
BarChart3,
|
|
||||||
ChevronsLeft,
|
ChevronsLeft,
|
||||||
ChevronsRight,
|
ChevronsRight,
|
||||||
CircleDollarSign,
|
CircleDollarSign,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
import type { User } from "@/models/user"
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
const Schema = z.object({
|
const Schema = z.object({
|
||||||
@@ -26,6 +27,7 @@ const Schema = z.object({
|
|||||||
.min(1, "请输入扣款金额")
|
.min(1, "请输入扣款金额")
|
||||||
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||||
.refine(val => Number(val) >= 0, "金额不能为负数"),
|
.refine(val => Number(val) >= 0, "金额不能为负数"),
|
||||||
|
remark: z.string().min(1, "请输入操作说明"),
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof Schema>
|
type FormValues = z.infer<typeof Schema>
|
||||||
@@ -52,6 +54,7 @@ export function DeductionDialog({
|
|||||||
resolver: zodResolver(Schema),
|
resolver: zodResolver(Schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
deduction: "",
|
deduction: "",
|
||||||
|
remark: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -61,6 +64,7 @@ export function DeductionDialog({
|
|||||||
const result = await getDeduction({
|
const result = await getDeduction({
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
amount: data.deduction,
|
amount: data.deduction,
|
||||||
|
remark: data.remark,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
@@ -123,6 +127,15 @@ export function DeductionDialog({
|
|||||||
/>
|
/>
|
||||||
<FieldError>{errors.deduction?.message}</FieldError>
|
<FieldError>{errors.deduction?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field data-invalid={!!errors.remark}>
|
||||||
|
<FieldLabel>操作说明</FieldLabel>
|
||||||
|
<Textarea
|
||||||
|
placeholder="请输入操作说明(必填)"
|
||||||
|
{...register("remark")}
|
||||||
|
rows={3}
|
||||||
|
/>
|
||||||
|
<FieldError>{errors.remark?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
import type { User } from "@/models/user"
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
const Schema = z.object({
|
const Schema = z.object({
|
||||||
@@ -26,6 +27,7 @@ const Schema = z.object({
|
|||||||
.min(1, "请输入余额")
|
.min(1, "请输入余额")
|
||||||
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||||
.refine(val => Number(val) >= 0, "余额不能为负数"),
|
.refine(val => Number(val) >= 0, "余额不能为负数"),
|
||||||
|
remark: z.string().min(1, "请输入操作说明"),
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof Schema>
|
type FormValues = z.infer<typeof Schema>
|
||||||
@@ -49,6 +51,7 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
|||||||
resolver: zodResolver(Schema),
|
resolver: zodResolver(Schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
deposit: "",
|
deposit: "",
|
||||||
|
remark: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -58,6 +61,7 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
|||||||
const result = await getDeposit({
|
const result = await getDeposit({
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
amount: data.deposit,
|
amount: data.deposit,
|
||||||
|
remark: data.remark,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
@@ -120,6 +124,15 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
|||||||
/>
|
/>
|
||||||
<FieldError>{errors.deposit?.message}</FieldError>
|
<FieldError>{errors.deposit?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field data-invalid={!!errors.remark}>
|
||||||
|
<FieldLabel>操作说明</FieldLabel>
|
||||||
|
<Textarea
|
||||||
|
placeholder="请输入操作说明(必填)"
|
||||||
|
{...register("remark")}
|
||||||
|
rows={3}
|
||||||
|
/>
|
||||||
|
<FieldError>{errors.remark?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import { Auth } from "@/components/auth"
|
|||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Page } from "@/components/page"
|
import { Page } from "@/components/page"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes"
|
import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes"
|
||||||
import type { Gateway } from "@/models/gateway"
|
import type { Gateway } from "@/models/gateway"
|
||||||
import CreatePage from "./create"
|
import CreatePage from "./create"
|
||||||
@@ -168,7 +174,8 @@ export default function GatewayPage() {
|
|||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
<div className="flex gap-2 ">
|
<div className="flex gap-2 ">
|
||||||
<Button
|
<Button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -178,24 +185,41 @@ export default function GatewayPage() {
|
|||||||
variant={
|
variant={
|
||||||
row.original.status === 0 ? "default" : "destructive"
|
row.original.status === 0 ? "default" : "destructive"
|
||||||
}
|
}
|
||||||
|
size="sm"
|
||||||
>
|
>
|
||||||
{row.original.status === 0 ? "启用" : "停用"}
|
{row.original.status === 0 ? "启用" : "停用"}
|
||||||
</Button>
|
</Button>
|
||||||
<Auth scope={ScopeChannelWriteClearExpired}>
|
<DropdownMenu>
|
||||||
<Button onClick={() => clearExpired(row.original)}>
|
<DropdownMenuTrigger asChild>
|
||||||
清理过期连接
|
<Button size="sm" variant="outline">
|
||||||
|
打开菜单
|
||||||
</Button>
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-8">
|
||||||
|
<Auth scope={ScopeChannelWriteClearExpired}>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => clearExpired(row.original)}
|
||||||
|
>
|
||||||
|
清理过期连接
|
||||||
|
</DropdownMenuItem>
|
||||||
</Auth>
|
</Auth>
|
||||||
<Auth scope={ScopeProxyWrite}>
|
<Auth scope={ScopeProxyWrite}>
|
||||||
<Button onClick={() => createPort(row.original)}>
|
<DropdownMenuItem
|
||||||
|
onClick={() => createPort(row.original)}
|
||||||
|
>
|
||||||
重建端口池
|
重建端口池
|
||||||
</Button>
|
</DropdownMenuItem>
|
||||||
<Button onClick={() => createChains(row.original)}>
|
<DropdownMenuItem
|
||||||
|
onClick={() => createChains(row.original)}
|
||||||
|
>
|
||||||
重建代理链
|
重建代理链
|
||||||
</Button>
|
</DropdownMenuItem>
|
||||||
</Auth>
|
</Auth>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
),
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ export default function ResourcesPage() {
|
|||||||
>
|
>
|
||||||
<ResourceList resourceType="short" />
|
<ResourceList resourceType="short" />
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="long" className="flex flex-col gap-4">
|
<TabsContent value="long" className="flex flex-col gap-4 overflow-hidden">
|
||||||
<ResourceList resourceType="long" />
|
<ResourceList resourceType="long" />
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -268,7 +268,6 @@ function ResourceList({ resourceType }: ResourceListProps) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const table = useDataTable<Resources>(fetchResources)
|
const table = useDataTable<Resources>(fetchResources)
|
||||||
console.log(table, "table")
|
|
||||||
|
|
||||||
const handleStatusChange = useCallback(
|
const handleStatusChange = useCallback(
|
||||||
async (resource: Resources, newStatusValue: string) => {
|
async (resource: Resources, newStatusValue: string) => {
|
||||||
|
|||||||
@@ -1,15 +1,32 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { CheckCircle, Clock, XCircle } from "lucide-react"
|
import { CheckCircle, Clock, Loader2, XCircle } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { Suspense, useCallback, useState } from "react"
|
import { Suspense, useCallback, useState } from "react"
|
||||||
import { Controller, useForm } from "react-hook-form"
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { getPageTrade } from "@/actions/trade"
|
import {
|
||||||
|
getPageTrade,
|
||||||
|
getTradeCheckk,
|
||||||
|
tradeCancel,
|
||||||
|
tradeComplete,
|
||||||
|
tradeConvert,
|
||||||
|
updateTradeRemark,
|
||||||
|
} from "@/actions/trade"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Page } from "@/components/page"
|
import { Page } from "@/components/page"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import {
|
import {
|
||||||
@@ -294,6 +311,21 @@ export default function TradePage() {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
header: "订单金额",
|
||||||
|
accessorKey: "amount",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const amount =
|
||||||
|
typeof row.original.amount === "string"
|
||||||
|
? parseFloat(row.original.amount)
|
||||||
|
: row.original.amount || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span>¥{amount.toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: "支付状态",
|
header: "支付状态",
|
||||||
accessorKey: "status",
|
accessorKey: "status",
|
||||||
@@ -365,9 +397,262 @@ export default function TradePage() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ header: "渠道订单号", accessorKey: "outer_no" },
|
{ header: "渠道订单号", accessorKey: "outer_no" },
|
||||||
|
{
|
||||||
|
header: "备注信息",
|
||||||
|
accessorKey: "remark",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "操作",
|
||||||
|
id: "actions",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
{row.original.status === 0 && (
|
||||||
|
<CheckOrder
|
||||||
|
trade={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<UpdateRole trade={row.original} onSuccess={table.refresh} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
type PayCloseData = {
|
||||||
|
Status: 0 | 1 | 2
|
||||||
|
TransId?: string
|
||||||
|
}
|
||||||
|
function CheckOrder(props: { trade: Trade; onSuccess: () => void }) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [data, setData] = useState<PayCloseData | null>(null)
|
||||||
|
|
||||||
|
const handleCheck = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await getTradeCheckk({
|
||||||
|
trade_no: props.trade.inner_no,
|
||||||
|
method: Number(props.trade.method),
|
||||||
|
})
|
||||||
|
console.log(res, "res")
|
||||||
|
|
||||||
|
if (res.success) {
|
||||||
|
setData(res.data)
|
||||||
|
} else {
|
||||||
|
toast.error(res.message)
|
||||||
|
}
|
||||||
|
setOpen(true)
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`检查失败,请重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [props])
|
||||||
|
|
||||||
|
const headerClick = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await tradeComplete({
|
||||||
|
trade_no: props.trade.inner_no,
|
||||||
|
method: Number(props.trade.method),
|
||||||
|
user_id: Number(props.trade.user_id),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("订单已完成")
|
||||||
|
props.onSuccess?.()
|
||||||
|
} else {
|
||||||
|
toast.error(result.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`检查失败,请重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [props])
|
||||||
|
|
||||||
|
const convert = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await tradeConvert({
|
||||||
|
trade_no: props.trade.inner_no,
|
||||||
|
method: Number(props.trade.method),
|
||||||
|
user_id: Number(props.trade.user_id),
|
||||||
|
})
|
||||||
|
console.log(result, "resultresultresult")
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("补到余额完成")
|
||||||
|
props.onSuccess?.()
|
||||||
|
} else {
|
||||||
|
toast.error(result.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`补到余额失败,请重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [props])
|
||||||
|
|
||||||
|
const cancel = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await tradeCancel({
|
||||||
|
trade_no: props.trade.inner_no,
|
||||||
|
method: Number(props.trade.method),
|
||||||
|
user_id: Number(props.trade.user_id),
|
||||||
|
})
|
||||||
|
console.log(result, "resultresultresult")
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("取消订单完成")
|
||||||
|
props.onSuccess?.()
|
||||||
|
} else {
|
||||||
|
toast.error(result.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`取消订单失败,请重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [props])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button size="sm" onClick={handleCheck} disabled={loading}>
|
||||||
|
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : "检查订单"}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>订单检查结果</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
{data && (
|
||||||
|
<div className="py-4">
|
||||||
|
<div
|
||||||
|
className={`p-4 rounded-lg ${data.Status === 1 ? "bg-green-100" : "bg-red-100"}`}
|
||||||
|
>
|
||||||
|
<p className="font-medium">创建时间:{data?.TransId}</p>
|
||||||
|
<p className="mt-2">
|
||||||
|
支付状态:
|
||||||
|
{data?.Status === 1
|
||||||
|
? "已支付"
|
||||||
|
: data?.Status === 0
|
||||||
|
? "待支付"
|
||||||
|
: "已取消"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{props && props.trade.status === 0 && (
|
||||||
|
<div className="flex gap-4 items-center justify-center">
|
||||||
|
<Button size="sm" className="w-32" onClick={headerClick}>
|
||||||
|
完成订单
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" className="w-32" onClick={convert}>
|
||||||
|
补到余额
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" className="w-32" onClick={cancel}>
|
||||||
|
取消订单
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="outline">关闭</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateRole(props: { trade: Trade; onSuccess?: () => void }) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const { register, handleSubmit, reset } = useForm<{
|
||||||
|
remark: string
|
||||||
|
}>({
|
||||||
|
defaultValues: { remark: "" },
|
||||||
|
})
|
||||||
|
const handleOpenChange = (isOpen: boolean) => {
|
||||||
|
setOpen(isOpen)
|
||||||
|
if (isOpen) {
|
||||||
|
reset({ remark: props.trade.remark ?? "" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitEditRemark = async (data: { remark: string }) => {
|
||||||
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
const response = await updateTradeRemark({
|
||||||
|
trade_no: props.trade.inner_no || "",
|
||||||
|
remark: data.remark,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
throw new Error(response.message)
|
||||||
|
}
|
||||||
|
toast.success("备注修改成功")
|
||||||
|
setOpen(false)
|
||||||
|
props.onSuccess?.()
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
`修改备注失败:${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button size="sm">修改备注</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
|
||||||
|
<DialogContent>
|
||||||
|
<form onSubmit={handleSubmit(submitEditRemark)} id="edit-remark-form">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>修改备注</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="py-4">
|
||||||
|
<Field className="flex flex-col gap-1">
|
||||||
|
<FieldLabel>备注信息</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...register("remark")}
|
||||||
|
placeholder="请输入备注信息"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost" disabled={loading}>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<Button type="submit" form="edit-remark-form" disabled={loading}>
|
||||||
|
{loading ? "保存中..." : "保存"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ export type Trade = {
|
|||||||
canceled_at: Date
|
canceled_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
user?: User
|
user?: User
|
||||||
|
remark: string
|
||||||
|
amount:string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user