Compare commits
5 Commits
e70cfbd9a8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9448c6c41 | ||
|
|
e0183f9a95 | ||
|
|
3dfe8a2b52 | ||
|
|
ea26e2fa1b | ||
|
|
b82f4cab1c |
@@ -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",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface ResourceListParams {
|
|||||||
created_at_start?: Date
|
created_at_start?: Date
|
||||||
created_at_end?: Date
|
created_at_end?: Date
|
||||||
expired?: boolean
|
expired?: boolean
|
||||||
|
resource_type?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listResourceLong(params: ResourceListParams) {
|
export async function listResourceLong(params: ResourceListParams) {
|
||||||
@@ -71,3 +72,7 @@ export async function ResourceShort(params: {
|
|||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function listResource(params: ResourceListParams) {
|
||||||
|
return callByUser<PageRecord<Resources>>("/api/admin/resource/page", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export async function updateTradeRemark(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PayCloseData = {
|
type PayCloseData = {
|
||||||
status: 0 | 1 | 2
|
Status: 0 | 1 | 2
|
||||||
TransId: string
|
TransId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,3 +49,27 @@ export async function getTradeCheckk(params: {
|
|||||||
}) {
|
}) {
|
||||||
return callByUser<PayCloseData>("/api/admin/trade/check", params)
|
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,
|
||||||
@@ -252,6 +251,12 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
label: "套餐管理",
|
label: "套餐管理",
|
||||||
requiredScope: ScopeResourceRead,
|
requiredScope: ScopeResourceRead,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: "/resources-new",
|
||||||
|
icon: Package,
|
||||||
|
label: "新套餐管理",
|
||||||
|
requiredScope: ScopeResourceRead,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
href: "/batch",
|
href: "/batch",
|
||||||
icon: ClipboardList,
|
icon: ClipboardList,
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
gateway: "网关列表",
|
gateway: "网关列表",
|
||||||
couponList: "已发放优惠券",
|
couponList: "已发放优惠券",
|
||||||
new: "新建文章",
|
new: "新建文章",
|
||||||
|
"resources-new": "新套餐管理",
|
||||||
}
|
}
|
||||||
|
|
||||||
if (labels[path]) return labels[path]
|
if (labels[path]) return labels[path]
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ type FilterSchema = z.infer<typeof filterSchema>
|
|||||||
|
|
||||||
export default function BillingPage() {
|
export default function BillingPage() {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const innerNo = searchParams.get("inner_no")
|
|
||||||
const billNo = searchParams.get("bill_no")
|
|
||||||
const resourceNo = searchParams.get("resource_no")
|
|
||||||
const [skuOptions, setSkuOptions] = useState<SkuOption[]>([])
|
const [skuOptions, setSkuOptions] = useState<SkuOption[]>([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [skuProductCode, setSkuProductCode] = useState<ProductCode>(
|
const [skuProductCode, setSkuProductCode] = useState<ProductCode>(
|
||||||
@@ -90,19 +87,37 @@ export default function BillingPage() {
|
|||||||
)
|
)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const { control, handleSubmit, reset, getValues } = useForm<FilterSchema>({
|
const { control, handleSubmit, reset, getValues, setValue } =
|
||||||
resolver: zodResolver(filterSchema),
|
useForm<FilterSchema>({
|
||||||
defaultValues: {
|
resolver: zodResolver(filterSchema),
|
||||||
bill_no: billNo || "",
|
defaultValues: {
|
||||||
inner_no: innerNo || "",
|
bill_no: searchParams.get("bill_no") || "",
|
||||||
created_at_start: "",
|
inner_no: searchParams.get("inner_no") || "",
|
||||||
created_at_end: "",
|
created_at_start: "",
|
||||||
phone: "",
|
created_at_end: "",
|
||||||
resource_no: resourceNo || "",
|
phone: "",
|
||||||
sku_code: "all",
|
resource_no: searchParams.get("resource_no") || "",
|
||||||
product_code: "",
|
sku_code: "all",
|
||||||
},
|
product_code: "",
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const params = {
|
||||||
|
resource_no: searchParams.get("resource_no"),
|
||||||
|
bill_no: searchParams.get("bill_no"),
|
||||||
|
inner_no: searchParams.get("inner_no"),
|
||||||
|
}
|
||||||
|
if (params.resource_no !== getValues("resource_no")) {
|
||||||
|
setValue("resource_no", params.resource_no || "")
|
||||||
|
}
|
||||||
|
if (params.bill_no !== getValues("bill_no")) {
|
||||||
|
setValue("bill_no", params.bill_no || "")
|
||||||
|
}
|
||||||
|
if (params.inner_no !== getValues("inner_no")) {
|
||||||
|
setValue("inner_no", params.inner_no || "")
|
||||||
|
}
|
||||||
|
}, [searchParams, setValue, getValues])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|||||||
@@ -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,34 +174,52 @@ export default function GatewayPage() {
|
|||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => {
|
||||||
<div className="flex gap-2 ">
|
return (
|
||||||
<Button
|
<div className="flex gap-2 ">
|
||||||
onClick={() =>
|
<Button
|
||||||
handleToggle(row.original.id, row.original.status)
|
onClick={() =>
|
||||||
}
|
handleToggle(row.original.id, row.original.status)
|
||||||
disabled={loading}
|
}
|
||||||
variant={
|
disabled={loading}
|
||||||
row.original.status === 0 ? "default" : "destructive"
|
variant={
|
||||||
}
|
row.original.status === 0 ? "default" : "destructive"
|
||||||
>
|
}
|
||||||
{row.original.status === 0 ? "启用" : "停用"}
|
size="sm"
|
||||||
</Button>
|
>
|
||||||
<Auth scope={ScopeChannelWriteClearExpired}>
|
{row.original.status === 0 ? "启用" : "停用"}
|
||||||
<Button onClick={() => clearExpired(row.original)}>
|
|
||||||
清理过期连接
|
|
||||||
</Button>
|
</Button>
|
||||||
</Auth>
|
<DropdownMenu>
|
||||||
<Auth scope={ScopeProxyWrite}>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button onClick={() => createPort(row.original)}>
|
<Button size="sm" variant="outline">
|
||||||
重建端口池
|
打开菜单
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => createChains(row.original)}>
|
</DropdownMenuTrigger>
|
||||||
重建代理链
|
<DropdownMenuContent align="end" className="w-8">
|
||||||
</Button>
|
<Auth scope={ScopeChannelWriteClearExpired}>
|
||||||
</Auth>
|
<DropdownMenuItem
|
||||||
</div>
|
onClick={() => clearExpired(row.original)}
|
||||||
),
|
>
|
||||||
|
清理过期连接
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeProxyWrite}>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => createPort(row.original)}
|
||||||
|
>
|
||||||
|
重建端口池
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => createChains(row.original)}
|
||||||
|
>
|
||||||
|
重建代理链
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Auth>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
630
src/app/(root)/resources-new/page.tsx
Normal file
630
src/app/(root)/resources-new/page.tsx
Normal file
@@ -0,0 +1,630 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format, isBefore, isSameDay } from "date-fns"
|
||||||
|
import { Box, Loader2, Timer } from "lucide-react"
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useCallback, useMemo, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { listResource, updateResource } from "@/actions/resources"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Page } from "@/components/page"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Resources } from "@/models/resources"
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
type: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
expired: z.string().optional(),
|
||||||
|
resource_type: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
interface FilterParams {
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
active?: boolean
|
||||||
|
mode?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
expired?: boolean
|
||||||
|
resource_type?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取资源类型
|
||||||
|
function getResourceType(resource: Resources): number {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.type
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.type
|
||||||
|
}
|
||||||
|
return resource.type
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取资源详情对象
|
||||||
|
function getResourceDetail(resource: Resources) {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取过期时间
|
||||||
|
function getExpireAt(resource: Resources): Date | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.expire_at
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.expire_at
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function getName(resource: Resources): string | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.sku?.name
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.sku?.name
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取最近使用时间
|
||||||
|
function getLastAt(resource: Resources): Date | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.last_at
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.last_at
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// 资源类型徽章
|
||||||
|
function ResourceTypeBadge({ resource }: { resource: Resources }) {
|
||||||
|
const type = getResourceType(resource)
|
||||||
|
if (type === 1) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<Timer size={20} />
|
||||||
|
<span>包时</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (type === 2) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<Box size={20} />
|
||||||
|
<span>包量</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过期徽章
|
||||||
|
function ExpireBadge({ expireAt }: { expireAt: Date | null | undefined }) {
|
||||||
|
if (!expireAt) return null
|
||||||
|
if (isBefore(expireAt, new Date())) {
|
||||||
|
return <Badge variant="destructive">过期</Badge>
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化日期
|
||||||
|
function formatDateTime(date: Date | null | undefined) {
|
||||||
|
if (!date) return ""
|
||||||
|
return format(date, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算今日使用量
|
||||||
|
function getTodayUsage(lastAt: Date | null | undefined, daily: number) {
|
||||||
|
if (lastAt && isSameDay(lastAt, new Date())) {
|
||||||
|
return daily
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ResourcesPage() {
|
||||||
|
return (
|
||||||
|
<Page>
|
||||||
|
<ResourceList />
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ResourceList() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const resourceNo = searchParams.get("resource_no")
|
||||||
|
const listFn = listResource
|
||||||
|
const [updatingId, setUpdatingId] = useState<number | null>(null)
|
||||||
|
const router = useRouter()
|
||||||
|
const { control, handleSubmit, reset, getValues } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: resourceNo || "",
|
||||||
|
status: "all",
|
||||||
|
type: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
expired: "all",
|
||||||
|
resource_type: "all",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchResources = useCallback(
|
||||||
|
(page: number, size: number) => {
|
||||||
|
const result: FilterParams = {}
|
||||||
|
const filters = getValues()
|
||||||
|
if (filters.user_phone?.trim())
|
||||||
|
result.user_phone = filters.user_phone.trim()
|
||||||
|
if (filters.resource_no?.trim())
|
||||||
|
result.resource_no = filters.resource_no.trim()
|
||||||
|
if (filters.status && filters.status !== "all") {
|
||||||
|
result.active = filters.status === "0"
|
||||||
|
}
|
||||||
|
if (filters.type && filters.type !== "all") {
|
||||||
|
result.mode = Number(filters.type)
|
||||||
|
}
|
||||||
|
if (filters.resource_type && filters.resource_type !== "all") {
|
||||||
|
result.resource_type = Number(filters.resource_type)
|
||||||
|
}
|
||||||
|
if (filters.expired && filters.expired !== "all") {
|
||||||
|
result.expired = filters.expired === "1"
|
||||||
|
}
|
||||||
|
if (filters.created_at_start)
|
||||||
|
result.created_at_start = new Date(filters.created_at_start)
|
||||||
|
if (filters.created_at_end)
|
||||||
|
result.created_at_end = new Date(filters.created_at_end)
|
||||||
|
return listFn({ page, size, ...result })
|
||||||
|
},
|
||||||
|
[listFn, getValues],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Resources>(fetchResources)
|
||||||
|
|
||||||
|
const handleStatusChange = useCallback(
|
||||||
|
async (resource: Resources, newStatusValue: string) => {
|
||||||
|
const newActive = newStatusValue === "0"
|
||||||
|
if (newActive === resource.active) return
|
||||||
|
setUpdatingId(resource.id)
|
||||||
|
try {
|
||||||
|
await updateResource({
|
||||||
|
id: resource.id,
|
||||||
|
active: newActive,
|
||||||
|
})
|
||||||
|
toast.success("更新成功", {
|
||||||
|
description: `资源状态已更新为${newActive ? "启用" : "禁用"}`,
|
||||||
|
})
|
||||||
|
table.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("更新状态失败:", error)
|
||||||
|
toast.error("更新失败", {
|
||||||
|
description: error instanceof Error ? error.message : "请稍后重试",
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setUpdatingId(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[table],
|
||||||
|
)
|
||||||
|
const handleCheckipChange = useCallback(
|
||||||
|
async (resource: Resources) => {
|
||||||
|
const newCheckip = !resource.checkip
|
||||||
|
setUpdatingId(resource.id)
|
||||||
|
try {
|
||||||
|
await updateResource({
|
||||||
|
id: resource.id,
|
||||||
|
checkip: newCheckip,
|
||||||
|
})
|
||||||
|
toast.success("更新成功", {
|
||||||
|
description: `IP检查已${newCheckip ? "启用IP检查" : "停用IP检查"}`,
|
||||||
|
})
|
||||||
|
table.refresh()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("更新IP检查状态失败:", error)
|
||||||
|
toast.error("更新失败", {
|
||||||
|
description: error instanceof Error ? error.message : "请稍后重试",
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setUpdatingId(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[table],
|
||||||
|
)
|
||||||
|
const onFilter = handleSubmit(() => {
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: (row: Resources) => row.user?.phone || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "套餐",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const resourceNo = row.original.resource_no
|
||||||
|
const name = getName(row.original)
|
||||||
|
const expireAt = getExpireAt(row.original)
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div>{name}</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<span className="text-xs text-gray-500">{resourceNo}</span>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-40">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/billing?resource_no=${resourceNo}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
账单详情
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/batch?resource_no=${resourceNo}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
提取记录
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/channel?resource_no=${resourceNo}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
IP管理
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<ExpireBadge expireAt={expireAt} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "产品",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const isLong = row.original.code === "long"
|
||||||
|
return <span>{isLong ? "长效" : "短效"}</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "类型",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return <ResourceTypeBadge resource={row.original} />
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "IP时效",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const detail = getResourceDetail(row.original)
|
||||||
|
const live = detail?.live
|
||||||
|
if (live === undefined) return "-"
|
||||||
|
return <span>{`${live}分钟`}</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "使用情况",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const detail = getResourceDetail(row.original)
|
||||||
|
const type = getResourceType(row.original)
|
||||||
|
|
||||||
|
if (!detail) return <span>-</span>
|
||||||
|
|
||||||
|
if (type === 1) {
|
||||||
|
// 包时
|
||||||
|
const todayUsage = getTodayUsage(detail.last_at, detail.daily || 0)
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span>
|
||||||
|
{todayUsage}/{detail.quota}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
{detail.used < detail.quota ? (
|
||||||
|
<span className="text-green-500">正常</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-red-500">已用完</span>
|
||||||
|
)}
|
||||||
|
<span>|</span>
|
||||||
|
<span>
|
||||||
|
{detail.used}/{detail.quota}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最近使用时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const lastAt = getLastAt(row.original)
|
||||||
|
return lastAt ? formatDateTime(lastAt) : "暂未使用"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "开通时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return formatDateTime(row.original.created_at)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "到期时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return formatDateTime(getExpireAt(row.original))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const resource = row.original
|
||||||
|
const isLoading = updatingId === resource.id
|
||||||
|
const currentActive = resource.active
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Select
|
||||||
|
value={currentActive ? "0" : "1"}
|
||||||
|
onValueChange={val => handleStatusChange(resource, val)}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="min-w-20">
|
||||||
|
<SelectValue placeholder="状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent className="min-w-(--radix-select-trigger-width)">
|
||||||
|
<SelectItem value="0">启用</SelectItem>
|
||||||
|
<SelectItem value="1">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{isLoading && (
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
onClick={() => handleCheckipChange(resource)}
|
||||||
|
variant={resource.checkip ? "destructive" : "default"}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{resource.checkip ? "停用IP检查" : "启用IP检查"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[updatingId, handleStatusChange, handleCheckipChange, router],
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-3 overflow-hidden">
|
||||||
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg flex-none">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="user_phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>会员号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入会员号" clearable />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="resource_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" clearable />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="resource_type"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>产品</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">短效</SelectItem>
|
||||||
|
<SelectItem value="2">长效</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="type"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>类型</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">包时</SelectItem>
|
||||||
|
<SelectItem value="2">包量</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="0">启用</SelectItem>
|
||||||
|
<SelectItem value="1">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>是否过期</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="0">未过期</SelectItem>
|
||||||
|
<SelectItem value="1">已过期</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} clearable />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} clearable />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">搜索</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
router.replace("./resources")
|
||||||
|
reset({
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
status: "all",
|
||||||
|
type: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
expired: "all",
|
||||||
|
})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense fallback={<div className="text-center p-4">加载中...</div>}>
|
||||||
|
<DataTable<Resources>
|
||||||
|
{...table}
|
||||||
|
columns={columns}
|
||||||
|
classNames={{
|
||||||
|
root: "flex-auto overflow-hidden",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</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) => {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import { z } from "zod"
|
|||||||
import {
|
import {
|
||||||
getPageTrade,
|
getPageTrade,
|
||||||
getTradeCheckk,
|
getTradeCheckk,
|
||||||
|
tradeCancel,
|
||||||
|
tradeComplete,
|
||||||
|
tradeConvert,
|
||||||
updateTradeRemark,
|
updateTradeRemark,
|
||||||
} from "@/actions/trade"
|
} from "@/actions/trade"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
@@ -119,7 +122,6 @@ export default function TradePage() {
|
|||||||
setFilters(result)
|
setFilters(result)
|
||||||
table.pagination.onPageChange(1)
|
table.pagination.onPageChange(1)
|
||||||
})
|
})
|
||||||
console.log(...table.data.map(i => i.remark), "tabletabletabletable")
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
@@ -309,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",
|
||||||
@@ -390,7 +407,12 @@ export default function TradePage() {
|
|||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<CheckOrder trade={row.original} />
|
{row.original.status === 0 && (
|
||||||
|
<CheckOrder
|
||||||
|
trade={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<UpdateRole trade={row.original} onSuccess={table.refresh} />
|
<UpdateRole trade={row.original} onSuccess={table.refresh} />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
@@ -402,10 +424,10 @@ export default function TradePage() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
type PayCloseData = {
|
type PayCloseData = {
|
||||||
status: 0 | 1 | 2
|
Status: 0 | 1 | 2
|
||||||
TransId?: string
|
TransId?: string
|
||||||
}
|
}
|
||||||
function CheckOrder(props: { trade: Trade }) {
|
function CheckOrder(props: { trade: Trade; onSuccess: () => void }) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [data, setData] = useState<PayCloseData | null>(null)
|
const [data, setData] = useState<PayCloseData | null>(null)
|
||||||
@@ -418,7 +440,6 @@ function CheckOrder(props: { trade: Trade }) {
|
|||||||
method: Number(props.trade.method),
|
method: Number(props.trade.method),
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(res, "res")
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
setData(res.data)
|
setData(res.data)
|
||||||
} else {
|
} else {
|
||||||
@@ -431,7 +452,76 @@ function CheckOrder(props: { trade: Trade }) {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}, [props.trade.inner_no, props.trade.method])
|
}, [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),
|
||||||
|
})
|
||||||
|
|
||||||
|
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),
|
||||||
|
})
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -448,20 +538,35 @@ function CheckOrder(props: { trade: Trade }) {
|
|||||||
{data && (
|
{data && (
|
||||||
<div className="py-4">
|
<div className="py-4">
|
||||||
<div
|
<div
|
||||||
className={`p-4 rounded-lg ${data.status === 1 ? "bg-green-50" : "bg-red-50"}`}
|
className={`p-4 rounded-lg ${data.Status === 1 ? "bg-green-100" : "bg-red-100"}`}
|
||||||
>
|
>
|
||||||
<p className="font-medium">创建时间:{data?.TransId}</p>
|
<p className="font-medium">创建时间:{data?.TransId}</p>
|
||||||
<p className="mt-2">
|
<p className="mt-2">
|
||||||
支付状态:
|
支付状态:
|
||||||
{data?.status === 1
|
{data?.Status === 1
|
||||||
? "已支付"
|
? "已支付"
|
||||||
: data?.status === 0
|
: data?.Status === 0
|
||||||
? "待支付"
|
? "未支付"
|
||||||
: "已取消"}
|
: "已取消"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{data && data?.Status === 1 && (
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{data && data?.Status === 0 && (
|
||||||
|
<Button size="sm" className="w-32" onClick={cancel}>
|
||||||
|
取消订单
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<DialogClose asChild>
|
<DialogClose asChild>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type ResourceBase = {
|
|||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
user: User
|
user: User
|
||||||
checkip: boolean
|
checkip: boolean
|
||||||
|
code: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceShort = {
|
type ResourceShort = {
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ export type Trade = {
|
|||||||
updated_at: Date
|
updated_at: Date
|
||||||
user?: User
|
user?: User
|
||||||
remark: string
|
remark: string
|
||||||
|
amount:string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user