Compare commits
8 Commits
v1.1.0
...
ed95f0520d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed95f0520d | ||
|
|
790180a847 | ||
|
|
cc7e26561d | ||
|
|
8fcf54ae10 | ||
|
|
ff645aaaca | ||
| f6ae0a9463 | |||
| 30af977543 | |||
| 0789462a8d |
@@ -3,7 +3,7 @@
|
|||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -H 0.0.0.0 --turbopack",
|
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
||||||
"build": "next build --turbopack",
|
"build": "next build --turbopack",
|
||||||
"lint": "biome check --write"
|
"lint": "biome check --write"
|
||||||
},
|
},
|
||||||
|
|||||||
32
src/actions/balance.ts
Normal file
32
src/actions/balance.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import type { PageRecord } from "@/lib/api"
|
||||||
|
import type { Balance } from "@/models/balance"
|
||||||
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
|
export async function getPageBalance(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_phone?: string
|
||||||
|
bill_id?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Balance>>(
|
||||||
|
"/api/admin/balance-activity/page",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getBalance(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
user_phone?: string
|
||||||
|
bill_id?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Balance>>(
|
||||||
|
"/api/admin/balance-activity/page/of-user",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -16,3 +16,19 @@ export async function getPageBatch(params: {
|
|||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Batch>>("/api/admin/batch/page", params)
|
return callByUser<PageRecord<Batch>>("/api/admin/batch/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getBatch(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
batch_no?: string
|
||||||
|
prov?: string
|
||||||
|
city?: string
|
||||||
|
isp?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Batch>>("/api/admin/batch/page/of-user", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,3 +26,19 @@ export async function getSkuList(params: { product_code?: ProductCode }) {
|
|||||||
}
|
}
|
||||||
return callByUser<ProductSku[]>("/api/admin/product/sku/all", requestParams)
|
return callByUser<ProductSku[]>("/api/admin/product/sku/all", requestParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getBill(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
bill_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
trade_inner_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
sku_code?: string
|
||||||
|
product_code?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Billing>>("/api/admin/bill/page/of-user", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,3 +16,21 @@ export async function getPageChannel(params: {
|
|||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Channel>>("/api/admin/channel/page", params)
|
return callByUser<PageRecord<Channel>>("/api/admin/channel/page", params)
|
||||||
}
|
}
|
||||||
|
export async function getChannel(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
batch_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
proxy_port?: number
|
||||||
|
proxy_host?: string
|
||||||
|
node_ip?: string
|
||||||
|
expired_at_start?: Date
|
||||||
|
expired_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Channel>>(
|
||||||
|
"/api/admin/channel/page/of-user",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { PageRecord } from "@/lib/api"
|
import type { PageRecord } from "@/lib/api"
|
||||||
import type { Cust } from "@/models/cust"
|
import type { User } from "@/models/user"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getPageCusts(params: { page: number; size: number }) {
|
export async function getPageCusts(params: { page: number; size: number }) {
|
||||||
return callByUser<PageRecord<Cust>>("/api/admin/user/page", params)
|
return callByUser<PageRecord<User>>("/api/admin/user/page", params)
|
||||||
}
|
}
|
||||||
export async function updateCust(data: {
|
export async function updateCust(data: {
|
||||||
id: number
|
id: number
|
||||||
@@ -16,7 +16,7 @@ export async function updateCust(data: {
|
|||||||
contact_qq?: string
|
contact_qq?: string
|
||||||
contact_wechat?: string
|
contact_wechat?: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Cust>>("/api/admin/user/update", data)
|
return callByUser<PageRecord<User>>("/api/admin/user/update", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createCust(data: {
|
export async function createCust(data: {
|
||||||
@@ -32,9 +32,22 @@ export async function createCust(data: {
|
|||||||
contact_qq?: string
|
contact_qq?: string
|
||||||
contact_wechat?: string
|
contact_wechat?: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Cust>>("/api/admin/user/create", data)
|
return callByUser<PageRecord<User>>("/api/admin/user/create", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBalance(params: { user_id: number; balance: string }) {
|
export async function getDeposit(params: { user_id: number; amount: string }) {
|
||||||
return callByUser<PageRecord<Cust>>("/api/admin/user/update/balance", params)
|
return callByUser<PageRecord<User>>(
|
||||||
|
"/api/admin/user/update/balance-inc",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getDeduction(params: {
|
||||||
|
user_id: number
|
||||||
|
amount: string
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<User>>(
|
||||||
|
"/api/admin/user/update/balance-dec",
|
||||||
|
params,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export async function createProductSku(data: {
|
|||||||
name: string
|
name: string
|
||||||
price: string
|
price: string
|
||||||
discount_id?: number
|
discount_id?: number
|
||||||
|
price_min?: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<ProductSku>("/api/admin/product/sku/create", {
|
return callByUser<ProductSku>("/api/admin/product/sku/create", {
|
||||||
product_id: data.product_id,
|
product_id: data.product_id,
|
||||||
@@ -33,6 +34,7 @@ export async function createProductSku(data: {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
price: data.price,
|
price: data.price,
|
||||||
discount_id: data.discount_id,
|
discount_id: data.discount_id,
|
||||||
|
price_min: data.price_min,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ export async function updateProductSku(data: {
|
|||||||
name?: string
|
name?: string
|
||||||
price?: string
|
price?: string
|
||||||
discount_id?: number | null
|
discount_id?: number | null
|
||||||
|
price_min?: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<ProductSku>("/api/admin/product/sku/update", {
|
return callByUser<ProductSku>("/api/admin/product/sku/update", {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
@@ -49,6 +52,7 @@ export async function updateProductSku(data: {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
price: data.price,
|
price: data.price,
|
||||||
discount_id: data.discount_id,
|
discount_id: data.discount_id,
|
||||||
|
price_min: data.price_min,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,3 +69,6 @@ export async function batchUpdateProductSkuDiscount(data: {
|
|||||||
discount_id: data.discount_id,
|
discount_id: data.discount_id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export async function activeProductSku(data: { id: number; status: number }) {
|
||||||
|
return callByUser<ProductSku>("/api/admin/product/sku/update/status", data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,3 +31,39 @@ export async function listResourceShort(params: ResourceListParams) {
|
|||||||
export async function updateResource(data: { id: number; active?: boolean }) {
|
export async function updateResource(data: { id: number; active?: boolean }) {
|
||||||
return callByUser<Resources>("/api/admin/resource/update", data)
|
return callByUser<Resources>("/api/admin/resource/update", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function ResourceLong(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
active?: boolean
|
||||||
|
mode?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
expired?: boolean
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Resources>>(
|
||||||
|
"/api/admin/resource/long/page/of-user",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function ResourceShort(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
active?: boolean
|
||||||
|
mode?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
expired?: boolean
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Resources>>(
|
||||||
|
"/api/admin/resource/short/page/of-user",
|
||||||
|
params,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,3 +15,25 @@ export async function getPageTrade(params: {
|
|||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<Trade>>("/api/admin/trade/page", params)
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getTrade(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
user_phone?: string
|
||||||
|
inner_no?: string
|
||||||
|
method?: number
|
||||||
|
platform?: number
|
||||||
|
status?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/page/of-user", params)
|
||||||
|
}
|
||||||
|
export async function getTradeComplete(params: {
|
||||||
|
user_id: number
|
||||||
|
trade_no: string
|
||||||
|
method: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/complete", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ export async function getPageUsers(params: { page: number; size: number }) {
|
|||||||
return callByUser<PageRecord<User>>("/api/admin/user/page", params)
|
return callByUser<PageRecord<User>>("/api/admin/user/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPageUserPage(params: { page: number; size: number }) {
|
||||||
|
return callByUser<PageRecord<User>>("/api/admin/user/page/not-bind", params)
|
||||||
|
}
|
||||||
|
|
||||||
export async function bindAdmin(params: {
|
export async function bindAdmin(params: {
|
||||||
id: number
|
id: number
|
||||||
account?: string
|
account?: string
|
||||||
@@ -14,11 +18,11 @@ export async function bindAdmin(params: {
|
|||||||
enabled?: boolean
|
enabled?: boolean
|
||||||
assigned?: boolean
|
assigned?: boolean
|
||||||
}) {
|
}) {
|
||||||
return callByUser("/api/admin/user/bind", {
|
return callByUser("/api/admin/user/update/bind", {
|
||||||
user_id: params.id,
|
user_id: params.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPageUser(params: object) {
|
export async function getPageUser(params: { phone?: string; name?: string }) {
|
||||||
return callByUser<User>("/api/admin/user/get", params)
|
return callByUser<User>("/api/admin/user/get", params)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { Lock } from "lucide-react"
|
||||||
import { Suspense, useState } from "react"
|
import { Suspense, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { deleteAdmin, getPageAdmin, updateAdmin } from "@/actions/admin"
|
import { deleteAdmin, getPageAdmin, updateAdmin } from "@/actions/admin"
|
||||||
@@ -21,6 +22,11 @@ import {
|
|||||||
HoverCardContent,
|
HoverCardContent,
|
||||||
HoverCardTrigger,
|
HoverCardTrigger,
|
||||||
} from "@/components/ui/hover-card"
|
} from "@/components/ui/hover-card"
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip"
|
||||||
import { type Admin, AdminStatus } from "@/models/admin"
|
import { type Admin, AdminStatus } from "@/models/admin"
|
||||||
import type { Role } from "@/models/role"
|
import type { Role } from "@/models/role"
|
||||||
import { AssignRoles } from "./assign-roles"
|
import { AssignRoles } from "./assign-roles"
|
||||||
@@ -29,6 +35,7 @@ import { UpdateAdmin } from "./update"
|
|||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const table = useDataTable((page, size) => getPageAdmin({ page, size }))
|
const table = useDataTable((page, size) => getPageAdmin({ page, size }))
|
||||||
|
console.log(table, "table")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
@@ -81,20 +88,43 @@ export default function AdminPage() {
|
|||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => {
|
||||||
<div className="flex gap-2">
|
const admin = row.original
|
||||||
<UpdateAdmin admin={row.original} onSuccess={table.refresh} />
|
if (admin.lock === true) {
|
||||||
<AssignRoles admin={row.original} onSuccess={table.refresh} />
|
return (
|
||||||
<ToggleStatusButton
|
<Tooltip>
|
||||||
admin={row.original}
|
<TooltipTrigger asChild>
|
||||||
onSuccess={table.refresh}
|
<div className="flex justify-center items-center">
|
||||||
/>
|
<Lock className="h-4 w-4 text-muted-foreground" />
|
||||||
<DeleteButton
|
</div>
|
||||||
admin={row.original}
|
</TooltipTrigger>
|
||||||
onSuccess={table.refresh}
|
<TooltipContent>
|
||||||
/>
|
<p>该账号为系统账号,不可修改</p>
|
||||||
</div>
|
</TooltipContent>
|
||||||
),
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<UpdateAdmin
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<AssignRoles
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<ToggleStatusButton
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<DeleteButton
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {
|
import {
|
||||||
BadgeQuestionMarkIcon,
|
BadgeQuestionMarkIcon,
|
||||||
BellIcon,
|
|
||||||
ChevronDownIcon,
|
ChevronDownIcon,
|
||||||
ChevronRightIcon,
|
ChevronRightIcon,
|
||||||
InboxIcon,
|
|
||||||
LogOutIcon,
|
LogOutIcon,
|
||||||
SearchIcon,
|
|
||||||
SettingsIcon,
|
SettingsIcon,
|
||||||
UserIcon,
|
UserIcon,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
@@ -16,36 +13,12 @@ import { usePathname, useRouter } from "next/navigation"
|
|||||||
import { useEffect, useRef, useState } from "react"
|
import { useEffect, useRef, useState } from "react"
|
||||||
import { logout } from "@/actions/auth"
|
import { logout } from "@/actions/auth"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
|
||||||
import type { Admin } from "@/models/admin"
|
import type { Admin } from "@/models/admin"
|
||||||
|
|
||||||
export default function Appbar(props: { admin: Admin }) {
|
export default function Appbar(props: { admin: Admin }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [showDropdown, setShowDropdown] = useState(false)
|
const [showDropdown, setShowDropdown] = useState(false)
|
||||||
const [showNotifications, setShowNotifications] = useState(false)
|
const [showNotifications, setShowNotifications] = useState(false)
|
||||||
const [notifications] = useState([
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
title: "系统通知",
|
|
||||||
content: "您有新的待审核内容",
|
|
||||||
time: "10分钟前",
|
|
||||||
read: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
title: "安全提醒",
|
|
||||||
content: "您的账号于昨天登录了新设备",
|
|
||||||
time: "1小时前",
|
|
||||||
read: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
title: "系统更新",
|
|
||||||
content: "系统将在今晚进行例行维护",
|
|
||||||
time: "2小时前",
|
|
||||||
read: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
const dropdownRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -72,14 +45,15 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
return () => document.removeEventListener("mousedown", handleClickOutside)
|
return () => document.removeEventListener("mousedown", handleClickOutside)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// 根据路径生成面包屑
|
|
||||||
const generateBreadcrumbs = () => {
|
const generateBreadcrumbs = () => {
|
||||||
const paths = pathname.split("/").filter(Boolean)
|
const paths = pathname.split("/").filter(Boolean)
|
||||||
|
const hiddenSegments = ["client"]
|
||||||
|
const filteredPaths = paths.filter(path => !hiddenSegments.includes(path))
|
||||||
const breadcrumbs = [
|
const breadcrumbs = [
|
||||||
{ path: "/", label: "首页" },
|
{ path: "/", label: "首页" },
|
||||||
...paths.map((path, index) => {
|
...filteredPaths.map((path, index) => {
|
||||||
const url = `/${paths.slice(0, index + 1).join("/")}`
|
const originalIndex = paths.findIndex(p => p === path)
|
||||||
|
const url = `/${paths.slice(0, originalIndex + 1).join("/")}`
|
||||||
const label = getBreadcrumbLabel(path)
|
const label = getBreadcrumbLabel(path)
|
||||||
return { path: url, label }
|
return { path: url, label }
|
||||||
}),
|
}),
|
||||||
@@ -94,7 +68,7 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
content: "内容管理",
|
content: "内容管理",
|
||||||
articles: "文章管理",
|
articles: "文章管理",
|
||||||
media: "媒体库",
|
media: "媒体库",
|
||||||
user: "用户管理",
|
user: "客户认领",
|
||||||
roles: "角色权限",
|
roles: "角色权限",
|
||||||
settings: "系统设置",
|
settings: "系统设置",
|
||||||
logs: "系统日志",
|
logs: "系统日志",
|
||||||
@@ -113,13 +87,13 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
permissions: "权限列表",
|
permissions: "权限列表",
|
||||||
discount: "折扣管理",
|
discount: "折扣管理",
|
||||||
statistics: "数据统计",
|
statistics: "数据统计",
|
||||||
|
balance: "余额明细",
|
||||||
}
|
}
|
||||||
|
|
||||||
return labels[path] || path
|
return labels[path] || path
|
||||||
}
|
}
|
||||||
|
|
||||||
const breadcrumbs = generateBreadcrumbs()
|
const breadcrumbs = generateBreadcrumbs()
|
||||||
const unreadCount = notifications.filter(n => !n.read).length
|
|
||||||
const doLogout = async () => {
|
const doLogout = async () => {
|
||||||
const resp = await logout()
|
const resp = await logout()
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
@@ -153,88 +127,6 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
|
|
||||||
{/* 右侧用户信息和工具栏 */}
|
{/* 右侧用户信息和工具栏 */}
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center space-x-4">
|
||||||
{/* 搜索框 */}
|
|
||||||
<div className="hidden md:block relative">
|
|
||||||
<div className="relative">
|
|
||||||
<SearchIcon className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
|
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
placeholder="搜索..."
|
|
||||||
className="pl-10 pr-4 py-2 bg-gray-100 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent w-56"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 通知图标 */}
|
|
||||||
<div className="relative" ref={notificationRef}>
|
|
||||||
<Button
|
|
||||||
onClick={() => setShowNotifications(!showNotifications)}
|
|
||||||
className="relative p-2 rounded-full text-gray-600 bg-gray-100 hover:bg-gray-100 hover:text-gray-800 transition-colors"
|
|
||||||
aria-label="通知"
|
|
||||||
>
|
|
||||||
<BellIcon />
|
|
||||||
{unreadCount > 0 && (
|
|
||||||
<span className="absolute top-1 right-1 h-4 w-4 text-xs flex items-center justify-center rounded-full bg-red-500 text-white">
|
|
||||||
{unreadCount}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{/* 通知下拉面板 */}
|
|
||||||
{showNotifications && (
|
|
||||||
<div className="absolute right-0 mt-2 w-80 bg-white rounded-md shadow-lg py-1 z-20 border border-gray-200">
|
|
||||||
<div className="px-4 py-2 border-b border-gray-100 flex justify-between items-center">
|
|
||||||
<h3 className="font-medium text-gray-800">通知</h3>
|
|
||||||
<Button className="text-xs text-blue-600 hover:text-blue-800">
|
|
||||||
全部标为已读
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="max-h-72 overflow-y-auto">
|
|
||||||
{notifications.length > 0 ? (
|
|
||||||
notifications.map(notification => (
|
|
||||||
<div
|
|
||||||
key={notification.id}
|
|
||||||
className={`px-4 py-3 border-b border-gray-100 hover:bg-gray-50 ${
|
|
||||||
notification.read ? "bg-white" : "bg-blue-50"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div className="flex justify-between items-start">
|
|
||||||
<h4 className="text-sm font-medium text-gray-800">
|
|
||||||
{notification.title}
|
|
||||||
</h4>
|
|
||||||
<span className="text-xs text-gray-500">
|
|
||||||
{notification.time}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-gray-600 mt-1">
|
|
||||||
{notification.content}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<div className="py-8 px-4 text-center">
|
|
||||||
<InboxIcon size={18} />
|
|
||||||
<p className="mt-2 text-sm text-gray-500">暂无通知</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="border-t border-gray-100 p-2 text-center">
|
|
||||||
<Link
|
|
||||||
href="/notifications"
|
|
||||||
className="text-xs text-blue-600 hover:text-blue-800"
|
|
||||||
>
|
|
||||||
查看全部通知
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 分隔线 */}
|
|
||||||
<div className="hidden md:block h-8 w-px bg-gray-200"></div>
|
|
||||||
|
|
||||||
{/* 用户下拉菜单 */}
|
{/* 用户下拉菜单 */}
|
||||||
<div className="relative" ref={dropdownRef}>
|
<div className="relative" ref={dropdownRef}>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
231
src/app/(root)/balance/page.tsx
Normal file
231
src/app/(root)/balance/page.tsx
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { Suspense, useCallback, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import z from "zod"
|
||||||
|
import { getPageBalance } from "@/actions/balance"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
|
||||||
|
import type { Balance } from "@/models/balance"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
user_phone?: string
|
||||||
|
bill_id?: string
|
||||||
|
admin_id?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
phone: z.string().optional(),
|
||||||
|
bill_id: z.string().optional(),
|
||||||
|
admin_id: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: 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>
|
||||||
|
|
||||||
|
export default function BalancePage() {
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
phone: "",
|
||||||
|
bill_id: "",
|
||||||
|
admin_id: "",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchUsers = useCallback(
|
||||||
|
(page: number, size: number) => getPageBalance({ page, size, ...filters }),
|
||||||
|
[filters],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Balance>(fetchUsers)
|
||||||
|
|
||||||
|
console.log(table, "table")
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.phone) result.user_phone = data.phone
|
||||||
|
if (data.bill_id) result.bill_id = data.bill_id
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>会员号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="bill_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账单号" />
|
||||||
|
<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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Balance>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: row => row.user?.phone || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "账单号",
|
||||||
|
accessorFn: row => row.bill?.bill_no || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "管理员",
|
||||||
|
accessorKey: "admin_id",
|
||||||
|
accessorFn: row => row.admin?.name || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "变动金额",
|
||||||
|
accessorKey: "amount",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const amount = row.original.amount
|
||||||
|
const isPositive = Number(amount) > 0
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span
|
||||||
|
className={`font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? "+" : ""}
|
||||||
|
{Number(amount).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "余额变化",
|
||||||
|
accessorKey: "balance_prev",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
¥{Number(row.original.balance_prev).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
<span className="text-muted-foreground">→</span>
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
¥{Number(row.original.balance_curr).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "备注",
|
||||||
|
accessorKey: "remark",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
import type { Batch } from "@/models/batch"
|
import type { Batch } from "@/models/batch"
|
||||||
|
|
||||||
type APIFilterParams = {
|
type APIFilterParams = {
|
||||||
phone?: string
|
user_phone?: string
|
||||||
batch_no?: string
|
batch_no?: string
|
||||||
resource_no?: string
|
resource_no?: string
|
||||||
prov?: string
|
prov?: string
|
||||||
@@ -84,7 +84,7 @@ export default function BatchPage() {
|
|||||||
|
|
||||||
const onFilter = handleSubmit(data => {
|
const onFilter = handleSubmit(data => {
|
||||||
const result: APIFilterParams = {}
|
const result: APIFilterParams = {}
|
||||||
if (data.user_phone?.trim()) result.phone = data.user_phone.trim()
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
||||||
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
if (data.prov?.trim()) result.prov = data.prov.trim()
|
if (data.prov?.trim()) result.prov = data.prov.trim()
|
||||||
@@ -250,10 +250,9 @@ export default function BatchPage() {
|
|||||||
<DataTable<Batch>
|
<DataTable<Batch>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{
|
{
|
||||||
header: "会员号",
|
header: "会员号",
|
||||||
accessorFn: row => row.user?.phone || "-",
|
accessorFn: row => row.user?.phone || "",
|
||||||
},
|
},
|
||||||
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
{ header: "批次号", accessorKey: "batch_no" },
|
{ header: "批次号", accessorKey: "batch_no" },
|
||||||
|
|||||||
@@ -181,6 +181,20 @@ export default function BillingPage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
name="bill_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
name="inner_no"
|
name="inner_no"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -262,20 +276,6 @@ export default function BillingPage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Controller
|
|
||||||
name="bill_no"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Field
|
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
className="w-40 flex-none"
|
|
||||||
>
|
|
||||||
<FieldLabel>账单号</FieldLabel>
|
|
||||||
<Input {...field} placeholder="请输入账单号" />
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
|
||||||
</Field>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
<Controller
|
||||||
name="created_at_start"
|
name="created_at_start"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -328,8 +328,7 @@ export default function BillingPage() {
|
|||||||
<DataTable<Billing>
|
<DataTable<Billing>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
{ header: "会员号", accessorFn: row => row.user?.phone || "" },
|
||||||
{ header: "会员号", accessorFn: row => row.user?.phone || "-" },
|
|
||||||
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
{
|
{
|
||||||
header: "账单详情",
|
header: "账单详情",
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ export default function ChannelPage() {
|
|||||||
<DataTable<Channel>
|
<DataTable<Channel>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{
|
{
|
||||||
header: "会员号",
|
header: "会员号",
|
||||||
accessorFn: row => row.user?.phone || "-",
|
accessorFn: row => row.user?.phone || "-",
|
||||||
|
|||||||
224
src/app/(root)/client/balance/page.tsx
Normal file
224
src/app/(root)/client/balance/page.tsx
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import z from "zod"
|
||||||
|
import { getBalance } from "@/actions/balance"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import type { Balance } from "@/models/balance"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
user_phone?: string
|
||||||
|
bill_id?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
phone: z.string().optional(),
|
||||||
|
bill_id: z.string().optional(),
|
||||||
|
admin_id: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: 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>
|
||||||
|
|
||||||
|
export default function BalancePage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const router = useRouter()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const userPhone = searchParams.get("phone")
|
||||||
|
console.log(userPhone, "userPhone")
|
||||||
|
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
phone: "",
|
||||||
|
bill_id: "",
|
||||||
|
admin_id: "",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const table = useDataTable<Balance>((page, size) =>
|
||||||
|
getBalance({ page, size, user_id: Number(userId), ...filters }),
|
||||||
|
)
|
||||||
|
console.log(table, "仅用户的table")
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.phone) result.user_phone = data.phone
|
||||||
|
if (data.bill_id) result.bill_id = data.bill_id
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
router.back()
|
||||||
|
}}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
返回上一级
|
||||||
|
</Button>
|
||||||
|
<span className="ml-2 text-gray-600">用户会员号: {userPhone}</span>
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="bill_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账单号" />
|
||||||
|
<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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Balance>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: "账单号",
|
||||||
|
accessorFn: row => row.bill?.bill_no || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "管理员",
|
||||||
|
accessorKey: "admin_id",
|
||||||
|
accessorFn: row => row.admin?.name || "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "变动金额",
|
||||||
|
accessorKey: "amount",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const amount = row.original.amount
|
||||||
|
const isPositive = Number(amount) > 0
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span
|
||||||
|
className={`font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? "+" : ""}
|
||||||
|
{Number(amount).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "余额变化",
|
||||||
|
accessorKey: "balance_prev",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
¥{Number(row.original.balance_prev).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
<span className="text-muted-foreground">→</span>
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
¥{Number(row.original.balance_curr).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "备注",
|
||||||
|
accessorKey: "remark",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
258
src/app/(root)/client/batch/page.tsx
Normal file
258
src/app/(root)/client/batch/page.tsx
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getBatch } from "@/actions/batch"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
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 { Batch } from "@/models/batch"
|
||||||
|
|
||||||
|
type APIFilterParams = {
|
||||||
|
phone?: string
|
||||||
|
batch_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
prov?: string
|
||||||
|
city?: string
|
||||||
|
isp?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
batch_no: z.string().optional(),
|
||||||
|
prov: z.string().optional(),
|
||||||
|
city: z.string().optional(),
|
||||||
|
isp: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: 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 FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
export default function BatchPage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const [filters, setFilters] = useState<APIFilterParams>({})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
resource_no: "",
|
||||||
|
batch_no: "",
|
||||||
|
prov: "",
|
||||||
|
city: "",
|
||||||
|
isp: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const table = useDataTable<Batch>((page, size) =>
|
||||||
|
getBatch({ page, size, user_id: Number(userId), ...filters }),
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: APIFilterParams = {}
|
||||||
|
if (data.user_phone?.trim()) result.phone = data.user_phone.trim()
|
||||||
|
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.prov?.trim()) result.prov = data.prov.trim()
|
||||||
|
if (data.city?.trim()) result.city = data.city.trim()
|
||||||
|
if (data.isp && data.isp !== "all") result.isp = data.isp
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{/* 筛选表单 */}
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="batch_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>批次号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入批次号" />
|
||||||
|
<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="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="prov"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>省份</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入省份" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="city"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>城市</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入城市" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="isp"
|
||||||
|
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>
|
||||||
|
<SelectItem value="3">移动</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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
|
<DataTable<Batch>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: row => row.user?.phone || "",
|
||||||
|
},
|
||||||
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
|
{ header: "批次号", accessorKey: "batch_no" },
|
||||||
|
{ header: "省份", accessorKey: "prov" },
|
||||||
|
{ header: "城市", accessorKey: "city" },
|
||||||
|
{ header: "提取IP", accessorKey: "ip" },
|
||||||
|
{ header: "运营商", accessorKey: "isp" },
|
||||||
|
{ header: "提取数量", accessorKey: "count" },
|
||||||
|
{
|
||||||
|
header: "提取时间",
|
||||||
|
accessorKey: "time",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.time), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
447
src/app/(root)/client/billing/page.tsx
Normal file
447
src/app/(root)/client/billing/page.tsx
Normal file
@@ -0,0 +1,447 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { CreditCard, Wallet } from "lucide-react"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useEffect, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getBill, getSkuList } from "@/actions/bill"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
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 { ProductCode } from "@/lib/base"
|
||||||
|
import type { Billing } from "@/models/billing"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
bill_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
trade_inner_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
sku_code?: string
|
||||||
|
product_code?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuOption = {
|
||||||
|
resource_code: string
|
||||||
|
resource_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
phone: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
bill_no: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
inner_no: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
product_code: z.string().optional(),
|
||||||
|
sku_code: 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 FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
export default function BillingPage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
const [skuOptions, setSkuOptions] = useState<SkuOption[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [skuProductCode, setSkuProductCode] = useState<ProductCode>(
|
||||||
|
ProductCode.All,
|
||||||
|
)
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
bill_no: "",
|
||||||
|
inner_no: "",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
sku_code: "all",
|
||||||
|
product_code: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true)
|
||||||
|
getSkuList({
|
||||||
|
product_code: skuProductCode,
|
||||||
|
})
|
||||||
|
.then(resp => {
|
||||||
|
if (!resp.success) {
|
||||||
|
throw new Error(resp.message)
|
||||||
|
}
|
||||||
|
setSkuOptions(
|
||||||
|
resp.data.map(sku => ({
|
||||||
|
resource_code: sku.code,
|
||||||
|
resource_name: sku.name,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.error("获取套餐类型失败:", e)
|
||||||
|
toast.error(
|
||||||
|
`获取套餐类型失败:${e instanceof Error ? e.message : String(e)}`,
|
||||||
|
)
|
||||||
|
setSkuOptions([])
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
}, [skuProductCode])
|
||||||
|
|
||||||
|
const table = useDataTable<Billing>((page, size) =>
|
||||||
|
getBill({ page, size, user_id: Number(userId), ...filters }),
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.phone?.trim()) result.user_phone = data.phone.trim()
|
||||||
|
if (data.inner_no?.trim()) result.trade_inner_no = data.inner_no.trim()
|
||||||
|
if (data.bill_no?.trim()) result.bill_no = data.bill_no.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.product_code && data.product_code !== ProductCode.All) {
|
||||||
|
result.product_code = data.product_code
|
||||||
|
}
|
||||||
|
if (data.sku_code && data.sku_code !== "all") {
|
||||||
|
result.sku_code = data.sku_code
|
||||||
|
}
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="resource_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="bill_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="inner_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>订单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入订单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="product_code"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>产品类型</FieldLabel>
|
||||||
|
<Select
|
||||||
|
value={skuProductCode}
|
||||||
|
onValueChange={value => {
|
||||||
|
setSkuProductCode(value as ProductCode)
|
||||||
|
field.onChange(value)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue
|
||||||
|
placeholder={"请选择"}
|
||||||
|
defaultValue={
|
||||||
|
skuProductCode === ProductCode.All ? "全部" : ""
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value={ProductCode.All}>全部</SelectItem>
|
||||||
|
<SelectItem value={ProductCode.Short}>短效</SelectItem>
|
||||||
|
<SelectItem value={ProductCode.Long}>长效</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="sku_code"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐类型</FieldLabel>
|
||||||
|
<Select
|
||||||
|
value={loading ? undefined : field.value || "all"}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder={loading ? "加载中..." : "全部"} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
{skuOptions.map(option => (
|
||||||
|
<SelectItem
|
||||||
|
key={option.resource_code}
|
||||||
|
value={option.resource_code}
|
||||||
|
>
|
||||||
|
{option.resource_name || option.resource_code}
|
||||||
|
</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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setSkuProductCode(ProductCode.All)
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Billing>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
|
{
|
||||||
|
header: "账单详情",
|
||||||
|
accessorKey: "info",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const bill = row.original
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="shrink-0">
|
||||||
|
{bill.type === 1 && (
|
||||||
|
<div className="flex gap-2 items-center bg-orange-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>消费</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.type === 2 && (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>退款</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.type === 3 && (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>充值</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">{bill.info}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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
|
||||||
|
className={
|
||||||
|
amount > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{amount.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "实付金额",
|
||||||
|
accessorKey: "actual",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const actual =
|
||||||
|
typeof row.original.actual === "string"
|
||||||
|
? parseFloat(row.original.actual)
|
||||||
|
: row.original.actual || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
actual > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{actual.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "账单号", accessorKey: "bill_no" },
|
||||||
|
{
|
||||||
|
header: "订单号",
|
||||||
|
accessorKey: "trade.inner_no",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const bill = row.original
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="shrink-0 w-20">
|
||||||
|
{bill.trade?.acquirer === 1 && (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>支付宝</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.trade?.acquirer === 2 && (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>微信</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.trade?.acquirer === 3 && (
|
||||||
|
<div className="flex gap-2 items-center bg-orange-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>银联</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!bill.trade?.acquirer && (
|
||||||
|
<div className="flex gap-2 items-center bg-red-50 w-full px-2 py-1 rounded-md">
|
||||||
|
<Wallet size={16} />
|
||||||
|
<span>余额</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">{bill.trade?.inner_no}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
315
src/app/(root)/client/channel/page.tsx
Normal file
315
src/app/(root)/client/channel/page.tsx
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getChannel } from "@/actions/channel"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import type { Channel } from "@/models/channel"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
batch_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
proxy_host?: string
|
||||||
|
proxy_port?: number
|
||||||
|
node_ip?: string
|
||||||
|
expired_at_start?: Date
|
||||||
|
expired_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
batch_no: z.string().optional(),
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
proxy_host: z.string().optional(),
|
||||||
|
proxy_port: z.string().optional(),
|
||||||
|
node_ip: z.string().optional(),
|
||||||
|
expired_at_start: z.string().optional(),
|
||||||
|
expired_at_end: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.expired_at_start && data.expired_at_end) {
|
||||||
|
const start = new Date(data.expired_at_start)
|
||||||
|
const end = new Date(data.expired_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["expired_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
const ispMap: Record<number, string> = {
|
||||||
|
1: "电信",
|
||||||
|
2: "联通",
|
||||||
|
3: "移动",
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ChannelPage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
batch_no: "",
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
proxy_port: "",
|
||||||
|
proxy_host: "",
|
||||||
|
node_ip: "",
|
||||||
|
expired_at_start: "",
|
||||||
|
expired_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const table = useDataTable<Channel>((page, size) =>
|
||||||
|
getChannel({ page, size, user_id: Number(userId), ...filters }),
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
||||||
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.proxy_host?.trim()) result.proxy_host = data.proxy_host.trim()
|
||||||
|
if (data.proxy_port?.trim())
|
||||||
|
result.proxy_port = Number(data.proxy_port.trim())
|
||||||
|
if (data.node_ip?.trim()) result.node_ip = data.node_ip.trim()
|
||||||
|
if (data.expired_at_start)
|
||||||
|
result.expired_at_start = new Date(data.expired_at_start)
|
||||||
|
if (data.expired_at_end)
|
||||||
|
result.expired_at_end = new Date(data.expired_at_end)
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="batch_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>批次号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入批次号" />
|
||||||
|
<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="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="proxy_host"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>代理IP</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入代理IP" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="proxy_port"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>代理端口</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入代理端口" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="node_ip"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>节点</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入节点" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Channel>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: row => row.user?.phone || "",
|
||||||
|
},
|
||||||
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
|
{ header: "批次号", accessorKey: "batch_no" },
|
||||||
|
{
|
||||||
|
header: "节点",
|
||||||
|
accessorFn: row => row.ip || row.edge_ref || row.edge_id,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
header: "自动配置",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const prov = row.original.filter_prov
|
||||||
|
const city = row.original.filter_city
|
||||||
|
const isp = row.original.filter_isp
|
||||||
|
const parts = []
|
||||||
|
if (prov && prov !== "all") parts.push(prov)
|
||||||
|
if (city && city !== "all") parts.push(city)
|
||||||
|
if (isp && isp !== "all") {
|
||||||
|
parts.push(ispMap[Number(isp)] || isp)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="text-sm">
|
||||||
|
{parts.length > 0 ? parts.join(" / ") : "不限"}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "网关地址",
|
||||||
|
accessorKey: "host",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{row.original.host}:{row.original.port}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "认证方式",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const channel = row.original
|
||||||
|
const hasWhitelist =
|
||||||
|
channel.whitelists && channel.whitelists.trim() !== ""
|
||||||
|
const hasAuth = channel.username && channel.password
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1 min-w-0">
|
||||||
|
{hasWhitelist ? (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span>白名单</span>
|
||||||
|
<div className="flex flex-wrap gap-1 max-w-50">
|
||||||
|
{channel.whitelists.split(",").map(ip => (
|
||||||
|
<Badge key={ip.trim()} variant="secondary">
|
||||||
|
{ip.trim()}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : hasAuth ? (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span>账号密码</span>
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{channel.username}:{channel.password}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span className="text-sm text-gray-400">无认证</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "过期时间",
|
||||||
|
accessorKey: "expired_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.expired_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
389
src/app/(root)/client/cust/page.tsx
Normal file
389
src/app/(root)/client/cust/page.tsx
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { Suspense, useCallback, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getPageUser } from "@/actions/user"
|
||||||
|
// import { DeductionDialog } from "@/app/(root)/cust/deduction"
|
||||||
|
// import { DepositDialog } from "@/app/(root)/cust/deposit"
|
||||||
|
import { UpdateDialog } from "@/app/(root)/cust/update"
|
||||||
|
import { Auth } from "@/components/auth"
|
||||||
|
import { DataTable } from "@/components/data-table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
ScopeBalanceActivityReadOfUser,
|
||||||
|
ScopeBatchReadOfUser,
|
||||||
|
ScopeBillReadOfUser,
|
||||||
|
ScopeChannelReadOfUser,
|
||||||
|
ScopeResourceRead,
|
||||||
|
ScopeTradeReadOfUser,
|
||||||
|
ScopeUserWrite,
|
||||||
|
ScopeUserWriteBalance,
|
||||||
|
} from "@/lib/scopes"
|
||||||
|
import type { User } from "@/models/user"
|
||||||
|
import { AddUserDialog } from "../../cust/create"
|
||||||
|
|
||||||
|
interface UserQueryParams {
|
||||||
|
account?: string
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z.object({
|
||||||
|
phone: z.string().optional(),
|
||||||
|
name: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
export default function UserQueryPage() {
|
||||||
|
const [userList, setUserList] = useState<User[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
// const [depositDialog, setDepositDialog] = useState(false)
|
||||||
|
// const [deposit, setDeposit] = useState<User | null>(null)
|
||||||
|
// const [deductionDialog, setDeductionDialog] = useState(false)
|
||||||
|
// const [deduction, setDeduction] = useState<User | null>(null)
|
||||||
|
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
||||||
|
const [currentEditUser, setCurrentEditUser] = useState<User | null>(null)
|
||||||
|
const [currentFilters, setCurrentFilters] = useState<UserQueryParams>({})
|
||||||
|
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
phone: "",
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchUsers = useCallback(async (filters: UserQueryParams = {}) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await getPageUser(filters)
|
||||||
|
if (res.success) {
|
||||||
|
const data = Array.isArray(res.data) ? res.data : [res.data]
|
||||||
|
setUserList(data)
|
||||||
|
} else {
|
||||||
|
toast.error(res.message || "获取用户失败")
|
||||||
|
setUserList([])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`获取用户失败: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const onFilter = handleSubmit((data: FormValues) => {
|
||||||
|
const params: UserQueryParams = {}
|
||||||
|
if (data.phone?.trim()) params.account = data.phone.trim()
|
||||||
|
if (data.name?.trim()) params.name = data.name.trim()
|
||||||
|
if (Object.keys(params).length === 0) {
|
||||||
|
toast.info("请至少输入一个筛选条件")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setCurrentFilters(params)
|
||||||
|
fetchUsers(params)
|
||||||
|
})
|
||||||
|
|
||||||
|
const refreshTable = useCallback(() => {
|
||||||
|
if (Object.keys(currentFilters).length > 0) {
|
||||||
|
fetchUsers(currentFilters)
|
||||||
|
}
|
||||||
|
}, [fetchUsers, currentFilters])
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
reset()
|
||||||
|
setCurrentFilters({})
|
||||||
|
setUserList([])
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>手机号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入手机号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="name"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>姓名</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入姓名" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Auth scope={ScopeUserWrite}>
|
||||||
|
<Button type="button" onClick={() => setIsAddDialogOpen(true)}>
|
||||||
|
添加用户
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Button type="button" variant="outline" onClick={handleReset}>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<User>
|
||||||
|
data={userList || []}
|
||||||
|
status={loading ? "load" : "done"}
|
||||||
|
columns={[
|
||||||
|
{ header: "手机", accessorKey: "phone" },
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "客户来源",
|
||||||
|
accessorKey: "source",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const sourceMap: Record<number, string> = {
|
||||||
|
0: "官网注册",
|
||||||
|
1: "管理员添加",
|
||||||
|
2: "代理商注册",
|
||||||
|
3: "代理商添加",
|
||||||
|
}
|
||||||
|
return sourceMap[row.original.source] ?? "未知"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "余额",
|
||||||
|
accessorKey: "balance",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const balance = Number(row.original.balance) || 0
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
balance > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{balance.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "账号", accessorKey: "username" },
|
||||||
|
{
|
||||||
|
header: "账号状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "客户经理",
|
||||||
|
cell: ({ row }) => row.original.admin?.name || "",
|
||||||
|
},
|
||||||
|
{ header: "姓名", accessorKey: "name" },
|
||||||
|
{
|
||||||
|
header: "实名状态",
|
||||||
|
accessorKey: "id_type",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Badge
|
||||||
|
variant={row.original.id_type === 1 ? "default" : "secondary"}
|
||||||
|
className={
|
||||||
|
row.original.id_type === 1
|
||||||
|
? "bg-green-100 text-green-800"
|
||||||
|
: "bg-gray-100 text-gray-800"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{row.original.id_type === 1 ? "已认证" : "未认证"}
|
||||||
|
</Badge>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最后登录时间",
|
||||||
|
accessorKey: "last_login",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
row.original.last_login
|
||||||
|
? format(
|
||||||
|
new Date(row.original.last_login),
|
||||||
|
"yyyy-MM-dd HH:mm",
|
||||||
|
)
|
||||||
|
: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最后登录IP",
|
||||||
|
accessorKey: "last_login_ip",
|
||||||
|
cell: ({ row }) => row.original.last_login_ip || "",
|
||||||
|
},
|
||||||
|
{ header: "联系方式", accessorKey: "contact_wechat" },
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-2 w-75">
|
||||||
|
{/* <Auth scope={ScopeUserWriteBalanceInc}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setDeposit(row.original)
|
||||||
|
setDepositDialog(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
充值
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeUserWriteBalanceDec}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="destructive"
|
||||||
|
onClick={() => {
|
||||||
|
setDeduction(row.original)
|
||||||
|
setDeductionDialog(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
扣款
|
||||||
|
</Button>
|
||||||
|
</Auth> */}
|
||||||
|
<Auth scope={ScopeUserWriteBalance}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentEditUser(row.original)
|
||||||
|
setIsEditDialogOpen(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeTradeReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/client/trade?userId=${row.original.id}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
交易明细
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBillReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/billing?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
账单详情
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeResourceRead}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/resources?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
套餐管理
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBatchReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/client/batch?userId=${row.original.id}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
提取记录
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeChannelReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/channel?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
IP管理
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBalanceActivityReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/balance?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
余额操作
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
<AddUserDialog
|
||||||
|
open={isAddDialogOpen}
|
||||||
|
onOpenChange={setIsAddDialogOpen}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
<UpdateDialog
|
||||||
|
open={isEditDialogOpen}
|
||||||
|
onOpenChange={setIsEditDialogOpen}
|
||||||
|
currentUser={currentEditUser}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* <DepositDialog
|
||||||
|
open={depositDialog}
|
||||||
|
onOpenChange={setDepositDialog}
|
||||||
|
currentUser={deposit}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/> */}
|
||||||
|
|
||||||
|
{/* <DeductionDialog
|
||||||
|
open={deductionDialog}
|
||||||
|
onOpenChange={setDeductionDialog}
|
||||||
|
currentUser={deduction}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/> */}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
567
src/app/(root)/client/resources/page.tsx
Normal file
567
src/app/(root)/client/resources/page.tsx
Normal file
@@ -0,0 +1,567 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format, isBefore, isSameDay } from "date-fns"
|
||||||
|
import { Box, Loader2, Timer } from "lucide-react"
|
||||||
|
import { 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 {
|
||||||
|
ResourceLong,
|
||||||
|
ResourceShort,
|
||||||
|
updateResource,
|
||||||
|
} from "@/actions/resources"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
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 { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取资源类型
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算今日使用量
|
||||||
|
function getTodayUsage(lastAt: Date | null | undefined, daily: number) {
|
||||||
|
if (lastAt && isSameDay(lastAt, new Date())) {
|
||||||
|
return daily
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ResourcesPage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Tabs defaultValue="short">
|
||||||
|
<TabsList className="bg-card p-1.5 rounded-lg">
|
||||||
|
<TabsTrigger
|
||||||
|
value="short"
|
||||||
|
className="w-30 h-9 data-[state=active]:bg-primary-muted text-base rounded-md"
|
||||||
|
>
|
||||||
|
短效套餐
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger
|
||||||
|
value="long"
|
||||||
|
className="w-30 h-9 data-[state=active]:bg-primary-muted text-base rounded-md"
|
||||||
|
>
|
||||||
|
长效套餐
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="short" className="flex flex-col gap-4">
|
||||||
|
<ResourceList resourceType="short" />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="long" className="flex flex-col gap-4">
|
||||||
|
<ResourceList resourceType="long" />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResourceListProps {
|
||||||
|
resourceType: "long" | "short"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ResourceList({ resourceType }: ResourceListProps) {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const [filters, setFilters] = useState<FilterParams>({})
|
||||||
|
const isLong = resourceType === "long"
|
||||||
|
const listFn = isLong ? ResourceLong : ResourceShort
|
||||||
|
const [updatingId, setUpdatingId] = useState<number | null>(null)
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
status: "all",
|
||||||
|
type: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
expired: "all",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchResources = useCallback(
|
||||||
|
(page: number, size: number) => {
|
||||||
|
return listFn({ page, size, user_id: Number(userId), ...filters })
|
||||||
|
},
|
||||||
|
[listFn, filters, userId],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Resources>(fetchResources)
|
||||||
|
const refreshTable = useCallback(() => {
|
||||||
|
setFilters(prev => ({ ...prev }))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
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 ? "启用" : "禁用"}`,
|
||||||
|
})
|
||||||
|
refreshTable()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("更新状态失败:", error)
|
||||||
|
toast.error("更新失败", {
|
||||||
|
description: error instanceof Error ? error.message : "请稍后重试",
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setUpdatingId(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[refreshTable],
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterParams = {}
|
||||||
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.status && data.status !== "all") {
|
||||||
|
result.active = data.status === "0"
|
||||||
|
}
|
||||||
|
if (data.type && data.type !== "all") {
|
||||||
|
result.mode = Number(data.type)
|
||||||
|
}
|
||||||
|
if (data.expired && data.expired !== "all") {
|
||||||
|
result.expired = data.expired === "1"
|
||||||
|
}
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
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">
|
||||||
|
<span className="text-xs text-gray-500">{resourceNo}</span>
|
||||||
|
<ExpireBadge expireAt={expireAt} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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>{isLong ? `${live}小时` : `${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 {
|
||||||
|
// 包量
|
||||||
|
if (isLong) {
|
||||||
|
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>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<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)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...(!isLong
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
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" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[isLong, updatingId, handleStatusChange],
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
|
<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="请输入会员号" />
|
||||||
|
<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="请输入套餐号" />
|
||||||
|
<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="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="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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense fallback={<div className="text-center p-4">加载中...</div>}>
|
||||||
|
<DataTable<Resources> {...table} columns={columns} />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
350
src/app/(root)/client/trade/page.tsx
Normal file
350
src/app/(root)/client/trade/page.tsx
Normal file
@@ -0,0 +1,350 @@
|
|||||||
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { CheckCircle, Clock, XCircle } from "lucide-react"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useCallback, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getTrade } from "@/actions/trade"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
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 { Trade } from "@/models/trade"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
inner_no?: string
|
||||||
|
method?: number
|
||||||
|
platform?: number
|
||||||
|
status?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
inner_no: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
method: z.string().optional(),
|
||||||
|
platform: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: 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 FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
export default function TradePage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
inner_no: "",
|
||||||
|
method: "all",
|
||||||
|
platform: "all",
|
||||||
|
status: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchTrades = useCallback(
|
||||||
|
async (page: number, size: number) => {
|
||||||
|
return getTrade({ page, size, user_id: Number(userId), ...filters })
|
||||||
|
},
|
||||||
|
[filters, userId],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Trade>(fetchTrades)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.inner_no?.trim()) result.inner_no = data.inner_no.trim()
|
||||||
|
if (data.method && data.method !== "all")
|
||||||
|
result.method = Number(data.method)
|
||||||
|
if (data.platform && data.platform !== "all")
|
||||||
|
result.platform = Number(data.platform)
|
||||||
|
if (data.status && data.status !== "all")
|
||||||
|
result.status = Number(data.status)
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{/* 筛选表单 */}
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="inner_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>订单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入订单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="method"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<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>
|
||||||
|
<SelectItem value="3">商福通</SelectItem>
|
||||||
|
<SelectItem value="4">商福通渠道支付宝</SelectItem>
|
||||||
|
<SelectItem value="5">商福通渠道微信</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="platform"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<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-24">
|
||||||
|
<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>
|
||||||
|
<SelectItem value="2">取消支付</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} />
|
||||||
|
<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} />
|
||||||
|
<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={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Trade>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: "订单号",
|
||||||
|
accessorKey: "inner_no",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "渠道订单号",
|
||||||
|
accessorKey: "outer_no",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付渠道",
|
||||||
|
accessorKey: "method",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const methodMap: Record<number, string> = {
|
||||||
|
1: "支付宝",
|
||||||
|
2: "微信",
|
||||||
|
3: "商福通",
|
||||||
|
4: "商福通渠道支付宝",
|
||||||
|
5: "商福通渠道微信",
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{methodMap[row.original.method as number] || "未知"}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付金额",
|
||||||
|
accessorKey: "payment",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const payment =
|
||||||
|
typeof row.original.payment === "string"
|
||||||
|
? parseFloat(row.original.payment)
|
||||||
|
: row.original.payment || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
payment > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{payment.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付平台",
|
||||||
|
accessorKey: "platform",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const platform = row.original.platform
|
||||||
|
if (!platform) return <span>-</span>
|
||||||
|
return platform === 1
|
||||||
|
? "电脑网站"
|
||||||
|
: platform === 2
|
||||||
|
? "手机网站"
|
||||||
|
: "-"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const status = row.original.status
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-yellow-600">
|
||||||
|
<Clock className="h-4 w-4" />
|
||||||
|
<span>待支付</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
case 1:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-green-600">
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
<span>支付成功</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
case 2:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-gray-500">
|
||||||
|
<XCircle className="h-4 w-4" />
|
||||||
|
<span>取消支付</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
return <span className="text-gray-400">-</span>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "购买套餐", accessorKey: "subject" },
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -35,7 +35,6 @@ export default function CouponPage() {
|
|||||||
<DataTable<Coupon>
|
<DataTable<Coupon>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{ header: "所属用户", accessorKey: "user_id" },
|
{ header: "所属用户", accessorKey: "user_id" },
|
||||||
{ header: "代码", accessorKey: "code" },
|
{ header: "代码", accessorKey: "code" },
|
||||||
{ header: "备注", accessorKey: "remark" },
|
{ header: "备注", accessorKey: "remark" },
|
||||||
|
|||||||
@@ -270,17 +270,6 @@ export function AddUserDialog({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<Controller
|
|
||||||
name="name"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Field data-invalid={fieldState.invalid}>
|
|
||||||
<FieldLabel>真实姓名</FieldLabel>
|
|
||||||
<Input {...field} placeholder="请输入真实姓名" />
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
|
||||||
</Field>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
<Controller
|
||||||
name="email"
|
name="email"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -292,9 +281,6 @@ export function AddUserDialog({
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
|
||||||
<Controller
|
<Controller
|
||||||
name="status"
|
name="status"
|
||||||
control={control}
|
control={control}
|
||||||
|
|||||||
144
src/app/(root)/cust/deduction.tsx
Normal file
144
src/app/(root)/cust/deduction.tsx
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getDeduction } from "@/actions/cust"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
|
const Schema = z.object({
|
||||||
|
deduction: z
|
||||||
|
.string()
|
||||||
|
.min(1, "请输入扣款金额")
|
||||||
|
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||||
|
.refine(val => Number(val) >= 0, "金额不能为负数"),
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof Schema>
|
||||||
|
|
||||||
|
interface UpdateDeductionDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
currentUser: User | null
|
||||||
|
onSuccess: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DeductionDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
currentUser,
|
||||||
|
onSuccess,
|
||||||
|
}: UpdateDeductionDialogProps) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
setValue,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(Schema),
|
||||||
|
defaultValues: {
|
||||||
|
deduction: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = async (data: FormValues) => {
|
||||||
|
if (!currentUser) return
|
||||||
|
setIsLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await getDeduction({
|
||||||
|
user_id: currentUser.id,
|
||||||
|
amount: data.deduction,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("扣款成功")
|
||||||
|
onOpenChange(false)
|
||||||
|
reset()
|
||||||
|
onSuccess()
|
||||||
|
} else {
|
||||||
|
toast.error(result.message || "扣款失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`网络错误,请稍后重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
onOpenChange(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>扣款</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
扣减用户 {currentUser?.name || currentUser?.username} 的余额
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<Field data-invalid={!!errors.deduction}>
|
||||||
|
<FieldLabel>扣款(元)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
placeholder="请输入扣款金额"
|
||||||
|
{...register("deduction")}
|
||||||
|
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value
|
||||||
|
value = value.replace(/[^\d.]/g, "")
|
||||||
|
const dotCount = (value.match(/\./g) || []).length
|
||||||
|
if (dotCount > 1) {
|
||||||
|
value = value.slice(0, value.lastIndexOf("."))
|
||||||
|
}
|
||||||
|
if (value.includes(".")) {
|
||||||
|
const [int, dec] = value.split(".")
|
||||||
|
value = `${int}.${dec.slice(0, 2)}`
|
||||||
|
}
|
||||||
|
setValue("deduction", value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{errors.deduction?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading ? "保存中" : "保存"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { useEffect, useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { getBalance } from "@/actions/cust"
|
import { getDeposit } from "@/actions/cust"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -17,31 +17,31 @@ 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 type { Cust } from "@/models/cust"
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
const balanceSchema = z.object({
|
const Schema = z.object({
|
||||||
balance: z
|
deposit: z
|
||||||
.string()
|
.string()
|
||||||
.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, "余额不能为负数"),
|
||||||
})
|
})
|
||||||
|
|
||||||
type BalanceFormValues = z.infer<typeof balanceSchema>
|
type FormValues = z.infer<typeof Schema>
|
||||||
|
|
||||||
interface UpdateBalanceDialogProps {
|
interface UpdateDepositDialogProps {
|
||||||
open: boolean
|
open: boolean
|
||||||
onOpenChange: (open: boolean) => void
|
onOpenChange: (open: boolean) => void
|
||||||
currentUser: Cust | null
|
currentUser: User | null
|
||||||
onSuccess: () => void
|
onSuccess: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BalanceDialog({
|
export function DepositDialog({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
currentUser,
|
currentUser,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}: UpdateBalanceDialogProps) {
|
}: UpdateDepositDialogProps) {
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -50,37 +50,29 @@ export function BalanceDialog({
|
|||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<BalanceFormValues>({
|
} = useForm<FormValues>({
|
||||||
resolver: zodResolver(balanceSchema),
|
resolver: zodResolver(Schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
balance: "",
|
deposit: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
const onSubmit = async (data: FormValues) => {
|
||||||
if (open && currentUser) {
|
|
||||||
const currentBalance = currentUser.balance?.toString() || "0"
|
|
||||||
const formattedBalance = Number(currentBalance).toFixed(2)
|
|
||||||
setValue("balance", formattedBalance)
|
|
||||||
}
|
|
||||||
}, [open, currentUser, setValue])
|
|
||||||
|
|
||||||
const onSubmit = async (data: BalanceFormValues) => {
|
|
||||||
if (!currentUser) return
|
if (!currentUser) return
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
try {
|
try {
|
||||||
const result = await getBalance({
|
const result = await getDeposit({
|
||||||
user_id: currentUser.id,
|
user_id: currentUser.id,
|
||||||
balance: data.balance,
|
amount: data.deposit,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
toast.success("修改余额成功")
|
toast.success("充值成功")
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
reset()
|
reset()
|
||||||
onSuccess()
|
onSuccess()
|
||||||
} else {
|
} else {
|
||||||
toast.error(result.message || "修改余额失败")
|
toast.error(result.message || "充值失败")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : error
|
const message = error instanceof Error ? error.message : error
|
||||||
@@ -101,45 +93,35 @@ export function BalanceDialog({
|
|||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>修改余额</DialogTitle>
|
<DialogTitle>充值</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
修改用户 {currentUser?.name || currentUser?.username} 的余额
|
充值用户 {currentUser?.name || currentUser?.username} 的余额
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="grid gap-4 py-4">
|
<div className="grid gap-4 py-4">
|
||||||
<Field data-invalid={!!errors.balance}>
|
<Field data-invalid={!!errors.deposit}>
|
||||||
<FieldLabel>余额(元)</FieldLabel>
|
<FieldLabel>充值(元)</FieldLabel>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="text" // 改为 text,避免 number 输入冲突
|
||||||
step="0.01"
|
placeholder="请输入充值金额"
|
||||||
min="0"
|
{...register("deposit")}
|
||||||
placeholder="请输入余额"
|
|
||||||
{...register("balance", {
|
|
||||||
setValueAs: value => {
|
|
||||||
if (!value) return ""
|
|
||||||
const num = Number(value)
|
|
||||||
if (Number.isNaN(num)) return value
|
|
||||||
return num.toFixed(2)
|
|
||||||
},
|
|
||||||
})}
|
|
||||||
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
let value = e.target.value
|
let value = e.target.value
|
||||||
if (value.startsWith("-")) {
|
value = value.replace(/[^\d.]/g, "")
|
||||||
value = value.replace("-", "")
|
const dotCount = (value.match(/\./g) || []).length
|
||||||
|
if (dotCount > 1) {
|
||||||
|
value = value.slice(0, value.lastIndexOf("."))
|
||||||
}
|
}
|
||||||
if (value.includes(".")) {
|
if (value.includes(".")) {
|
||||||
const parts = value.split(".")
|
const [int, dec] = value.split(".")
|
||||||
if (parts[1] && parts[1].length > 2) {
|
value = `${int}.${dec.slice(0, 2)}`
|
||||||
value = `${parts[0]}.${parts[1].slice(0, 2)}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setValue("deposit", value)
|
||||||
setValue("balance", value)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<FieldError>{errors.balance?.message}</FieldError>
|
<FieldError>{errors.deposit?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
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 { z } from "zod"
|
import { z } from "zod"
|
||||||
import { getPageCusts } from "@/actions/cust"
|
import { getPageCusts } from "@/actions/cust"
|
||||||
|
import { Auth } from "@/components/auth"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
@@ -23,9 +25,22 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import type { Cust } from "@/models/cust"
|
import {
|
||||||
import { BalanceDialog } from "./balanceDialog"
|
ScopeBalanceActivityReadOfUser,
|
||||||
|
ScopeBatchReadOfUser,
|
||||||
|
ScopeBillReadOfUser,
|
||||||
|
ScopeChannelReadOfUser,
|
||||||
|
ScopeResourceRead,
|
||||||
|
ScopeTradeReadOfUser,
|
||||||
|
ScopeUserWrite,
|
||||||
|
ScopeUserWriteBalance,
|
||||||
|
ScopeUserWriteBalanceDec,
|
||||||
|
ScopeUserWriteBalanceInc,
|
||||||
|
} from "@/lib/scopes"
|
||||||
|
import type { User } from "@/models/user"
|
||||||
import { AddUserDialog } from "./create"
|
import { AddUserDialog } from "./create"
|
||||||
|
import { DeductionDialog } from "./deduction"
|
||||||
|
import { DepositDialog } from "./deposit"
|
||||||
import { UpdateDialog } from "./update"
|
import { UpdateDialog } from "./update"
|
||||||
|
|
||||||
type FilterValues = {
|
type FilterValues = {
|
||||||
@@ -63,13 +78,16 @@ const filterSchema = z
|
|||||||
|
|
||||||
type FormValues = z.infer<typeof filterSchema>
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function UserPage() {
|
export default function CustPage() {
|
||||||
const [filters, setFilters] = useState<FilterValues>({})
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
|
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
|
||||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
||||||
const [currentEditUser, setCurrentEditUser] = useState<Cust | null>(null)
|
const [currentEditUser, setCurrentEditUser] = useState<User | null>(null)
|
||||||
const [balanceDialog, setBalanceDialog] = useState(false)
|
const [depositDialog, setDepositDialog] = useState(false)
|
||||||
const [balance, setBalance] = useState<Cust | null>(null)
|
const [deposit, setDeposit] = useState<User | null>(null)
|
||||||
|
const router = useRouter()
|
||||||
|
const [deductionDialog, setDeductionDialog] = useState(false)
|
||||||
|
const [deduction, setDeduction] = useState<User | null>(null)
|
||||||
const { control, handleSubmit, reset } = useForm<FormValues>({
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
resolver: zodResolver(filterSchema),
|
resolver: zodResolver(filterSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -87,7 +105,7 @@ export default function UserPage() {
|
|||||||
[filters],
|
[filters],
|
||||||
)
|
)
|
||||||
|
|
||||||
const table = useDataTable<Cust>(fetchUsers)
|
const table = useDataTable<User>(fetchUsers)
|
||||||
|
|
||||||
const onFilter = handleSubmit(data => {
|
const onFilter = handleSubmit(data => {
|
||||||
const result: FilterValues = {}
|
const result: FilterValues = {}
|
||||||
@@ -212,7 +230,11 @@ export default function UserPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
<Button type="submit">筛选</Button>
|
<Auth scope={ScopeUserWrite}>
|
||||||
|
<Button type="button" onClick={() => setIsAddDialogOpen(true)}>
|
||||||
|
添加用户
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -224,21 +246,22 @@ export default function UserPage() {
|
|||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="button" onClick={() => setIsAddDialogOpen(true)}>
|
<Button type="submit">筛选</Button>
|
||||||
添加用户
|
|
||||||
</Button>
|
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<DataTable<Cust>
|
<DataTable<User>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{ header: "账号", accessorKey: "username" },
|
|
||||||
{ header: "手机", accessorKey: "phone" },
|
{ header: "手机", accessorKey: "phone" },
|
||||||
{ header: "邮箱", accessorKey: "email" },
|
{
|
||||||
{ header: "姓名", accessorKey: "name" },
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
// { header: "邮箱", accessorKey: "email" },
|
||||||
{
|
{
|
||||||
header: "客户来源",
|
header: "客户来源",
|
||||||
accessorKey: "source",
|
accessorKey: "source",
|
||||||
@@ -268,7 +291,22 @@ export default function UserPage() {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ header: "折扣", accessorKey: "discount.name" },
|
{ header: "账号", accessorKey: "username" },
|
||||||
|
{
|
||||||
|
header: "账号状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
||||||
|
},
|
||||||
|
{ header: "客户经理", accessorKey: "admin.name" },
|
||||||
|
{ header: "姓名", accessorKey: "name" },
|
||||||
|
{
|
||||||
|
header: "身份证号",
|
||||||
|
accessorKey: "id_no",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const idNo = row.original.id_no
|
||||||
|
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : ""
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: "实名状态",
|
header: "实名状态",
|
||||||
accessorKey: "id_type",
|
accessorKey: "id_type",
|
||||||
@@ -286,18 +324,22 @@ export default function UserPage() {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "身份证号",
|
header: "最后登录时间",
|
||||||
accessorKey: "id_no",
|
accessorKey: "last_login",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) =>
|
||||||
const idNo = row.original.id_no
|
row.original.last_login
|
||||||
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : "-"
|
? format(
|
||||||
},
|
new Date(row.original.last_login),
|
||||||
|
"yyyy-MM-dd HH:mm",
|
||||||
|
)
|
||||||
|
: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "账号状态",
|
header: "最后登录IP",
|
||||||
accessorKey: "status",
|
accessorKey: "last_login_ip",
|
||||||
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
cell: ({ row }) => row.original.last_login_ip || "",
|
||||||
},
|
},
|
||||||
|
{ header: "折扣", accessorKey: "discount.name" },
|
||||||
{
|
{
|
||||||
header: "联系方式",
|
header: "联系方式",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
@@ -314,55 +356,114 @@ export default function UserPage() {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ header: "客户经理", accessorKey: "admin.name" },
|
|
||||||
{
|
|
||||||
header: "最后登录时间",
|
|
||||||
accessorKey: "last_login",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
row.original.last_login
|
|
||||||
? format(
|
|
||||||
new Date(row.original.last_login),
|
|
||||||
"yyyy-MM-dd HH:mm",
|
|
||||||
)
|
|
||||||
: "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "最后登录IP",
|
|
||||||
accessorKey: "last_login_ip",
|
|
||||||
cell: ({ row }) => row.original.last_login_ip || "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "创建时间",
|
|
||||||
accessorKey: "created_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-2">
|
<div className="flex flex-wrap gap-2 w-75">
|
||||||
<Button
|
<Auth scope={ScopeUserWriteBalanceInc}>
|
||||||
size="sm"
|
<Button
|
||||||
variant="outline"
|
size="sm"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setBalance(row.original)
|
setDeposit(row.original)
|
||||||
setBalanceDialog(true)
|
setDepositDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
修改余额
|
充值
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
</Auth>
|
||||||
size="sm"
|
<Auth scope={ScopeUserWriteBalanceDec}>
|
||||||
onClick={() => {
|
<Button
|
||||||
setCurrentEditUser(row.original)
|
size="sm"
|
||||||
setIsEditDialogOpen(true)
|
onClick={() => {
|
||||||
}}
|
setDeduction(row.original)
|
||||||
>
|
setDeductionDialog(true)
|
||||||
修改
|
}}
|
||||||
</Button>
|
>
|
||||||
|
扣款
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeUserWriteBalance}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentEditUser(row.original)
|
||||||
|
setIsEditDialogOpen(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeTradeReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/client/trade?userId=${row.original.id}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
交易明细
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBillReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/billing?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
账单详情
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeResourceRead}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/resources?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
套餐管理
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBatchReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/client/batch?userId=${row.original.id}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
提取记录
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeChannelReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/channel?userId=${row.original.id}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
IP管理
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
<Auth scope={ScopeBalanceActivityReadOfUser}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
router.push(
|
||||||
|
`/client/balance?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
余额操作
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -384,10 +485,16 @@ export default function UserPage() {
|
|||||||
onSuccess={refreshTable}
|
onSuccess={refreshTable}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<BalanceDialog
|
<DepositDialog
|
||||||
open={balanceDialog}
|
open={depositDialog}
|
||||||
onOpenChange={setBalanceDialog}
|
onOpenChange={setDepositDialog}
|
||||||
currentUser={balance}
|
currentUser={deposit}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
<DeductionDialog
|
||||||
|
open={deductionDialog}
|
||||||
|
onOpenChange={setDeductionDialog}
|
||||||
|
currentUser={deduction}
|
||||||
onSuccess={refreshTable}
|
onSuccess={refreshTable}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import type { Admin } from "@/models/admin"
|
import type { Admin } from "@/models/admin"
|
||||||
import type { Cust } from "@/models/cust"
|
import type { User } from "@/models/user"
|
||||||
import type { ProductDiscount } from "@/models/product_discount"
|
import type { ProductDiscount } from "@/models/product_discount"
|
||||||
|
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
@@ -69,7 +69,7 @@ export type EditUserFormValues = z.infer<typeof editUserSchema>
|
|||||||
interface EditUserDialogProps {
|
interface EditUserDialogProps {
|
||||||
open: boolean
|
open: boolean
|
||||||
onOpenChange: (open: boolean) => void
|
onOpenChange: (open: boolean) => void
|
||||||
currentUser: Cust | null
|
currentUser: User | null
|
||||||
onSuccess: () => void
|
onSuccess: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ async function Layout(props: { children: ReactNode }) {
|
|||||||
const profile = await getProfile()
|
const profile = await getProfile()
|
||||||
if (!profile.success) throw new Error("页面渲染失败:无法获取账号信息")
|
if (!profile.success) throw new Error("页面渲染失败:无法获取账号信息")
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-gray-100">
|
<div className="flex h-screen overflow-hidden bg-gray-100">
|
||||||
<SetScopes admin={profile.data} />
|
<SetScopes admin={profile.data} />
|
||||||
|
|
||||||
{/* 侧边栏 */}
|
{/* 侧边栏 */}
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ import {
|
|||||||
BarChart3,
|
BarChart3,
|
||||||
ChevronsLeft,
|
ChevronsLeft,
|
||||||
ChevronsRight,
|
ChevronsRight,
|
||||||
|
CircleDollarSign,
|
||||||
ClipboardList,
|
ClipboardList,
|
||||||
Code,
|
|
||||||
ComputerIcon,
|
ComputerIcon,
|
||||||
ContactRound,
|
ContactRound,
|
||||||
DollarSign,
|
DollarSign,
|
||||||
|
FolderCode,
|
||||||
Home,
|
Home,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
type LucideIcon,
|
type LucideIcon,
|
||||||
Package,
|
Package,
|
||||||
|
ScanSearch,
|
||||||
Shield,
|
Shield,
|
||||||
ShoppingBag,
|
ShoppingBag,
|
||||||
SquarePercent,
|
SquarePercent,
|
||||||
@@ -36,6 +38,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
ScopeAdminRead,
|
ScopeAdminRead,
|
||||||
ScopeAdminRoleRead,
|
ScopeAdminRoleRead,
|
||||||
|
ScopeBalanceActivity,
|
||||||
ScopeBatchRead,
|
ScopeBatchRead,
|
||||||
ScopeBillRead,
|
ScopeBillRead,
|
||||||
ScopeChannelRead,
|
ScopeChannelRead,
|
||||||
@@ -46,6 +49,7 @@ import {
|
|||||||
ScopeResourceRead,
|
ScopeResourceRead,
|
||||||
ScopeTradeRead,
|
ScopeTradeRead,
|
||||||
ScopeUserRead,
|
ScopeUserRead,
|
||||||
|
ScopeUserReadNotBind,
|
||||||
ScopeUserReadOne,
|
ScopeUserReadOne,
|
||||||
} from "@/lib/scopes"
|
} from "@/lib/scopes"
|
||||||
|
|
||||||
@@ -98,8 +102,6 @@ interface NavItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function NavItem({ href, icon: Icon, label, requiredScope }: NavItemProps) {
|
function NavItem({ href, icon: Icon, label, requiredScope }: NavItemProps) {
|
||||||
// console.log(requiredScope, "requiredScope")
|
|
||||||
|
|
||||||
const { collapsed, isActive } = useNavigation()
|
const { collapsed, isActive } = useNavigation()
|
||||||
const active = isActive(href)
|
const active = isActive(href)
|
||||||
|
|
||||||
@@ -169,6 +171,12 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
href: "/user",
|
href: "/user",
|
||||||
icon: Users,
|
icon: Users,
|
||||||
label: "客户认领",
|
label: "客户认领",
|
||||||
|
requiredScope: ScopeUserReadNotBind,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/client/cust",
|
||||||
|
icon: ScanSearch,
|
||||||
|
label: "客户查询",
|
||||||
requiredScope: ScopeUserReadOne,
|
requiredScope: ScopeUserReadOne,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -183,6 +191,12 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
label: "交易明细",
|
label: "交易明细",
|
||||||
requiredScope: ScopeTradeRead,
|
requiredScope: ScopeTradeRead,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: "/balance",
|
||||||
|
icon: CircleDollarSign,
|
||||||
|
label: "余额明细",
|
||||||
|
requiredScope: ScopeBalanceActivity,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
href: "/billing",
|
href: "/billing",
|
||||||
icon: DollarSign,
|
icon: DollarSign,
|
||||||
@@ -226,7 +240,7 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "/channel",
|
href: "/channel",
|
||||||
icon: Code,
|
icon: FolderCode,
|
||||||
label: "IP管理",
|
label: "IP管理",
|
||||||
requiredScope: ScopeChannelRead,
|
requiredScope: ScopeChannelRead,
|
||||||
},
|
},
|
||||||
@@ -261,9 +275,11 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
export default function Navigation() {
|
export default function Navigation() {
|
||||||
const [collapsed, setCollapsed] = useState(false)
|
const [collapsed, setCollapsed] = useState(false)
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
const isActive = (path: string) => {
|
const isActive = (path: string) => {
|
||||||
return path === "/" ? pathname === path : pathname.startsWith(path)
|
if (path === "/") {
|
||||||
|
return pathname === path
|
||||||
|
}
|
||||||
|
return pathname === path || pathname.startsWith(path + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextValue: NavigationContextType = {
|
const contextValue: NavigationContextType = {
|
||||||
@@ -277,12 +293,12 @@ export default function Navigation() {
|
|||||||
<NavigationContext.Provider value={contextValue}>
|
<NavigationContext.Provider value={contextValue}>
|
||||||
<aside
|
<aside
|
||||||
className={twJoin(
|
className={twJoin(
|
||||||
"bg-background border-r border-border transition-all duration-300 ease-in-out flex flex-col",
|
"bg-background border-r border-border transition-all duration-300 ease-in-out flex flex-col h-full",
|
||||||
collapsed ? "w-16" : "w-64",
|
collapsed ? "w-16" : "w-64",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Logo */}
|
{/*Logo 区域 */}
|
||||||
<div className="h-16 flex items-center justify-center border-b border-border">
|
<div className="h-16 flex items-center justify-center border-b border-border p-4 shrink-0">
|
||||||
{!collapsed ? (
|
{!collapsed ? (
|
||||||
<span className="text-xl font-bold tracking-wide text-foreground">
|
<span className="text-xl font-bold tracking-wide text-foreground">
|
||||||
管理系统
|
管理系统
|
||||||
@@ -294,7 +310,7 @@ export default function Navigation() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{/* Navigation Menu */}
|
{/* Navigation Menu */}
|
||||||
<ScrollArea className="flex-1 py-3">
|
<ScrollArea className="flex-1 py-3 overflow-hidden">
|
||||||
<nav className="space-y-3">
|
<nav className="space-y-3">
|
||||||
{menuSections.map((section, idx) => (
|
{menuSections.map((section, idx) => (
|
||||||
<div key={section.title}>
|
<div key={section.title}>
|
||||||
@@ -309,8 +325,7 @@ export default function Navigation() {
|
|||||||
</nav>
|
</nav>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|
||||||
{/* Toggle Button */}
|
<div className="p-4 border-t border-border mt-auto shrink-0">
|
||||||
<div className="p-4 border-t border-border mt-auto">
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => setCollapsed(!collapsed)}
|
onClick={() => setCollapsed(!collapsed)}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import {
|
|||||||
type Row,
|
type Row,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table"
|
} from "@tanstack/react-table"
|
||||||
|
import { Copy } from "lucide-react"
|
||||||
import { Suspense, useCallback, useEffect, useState } from "react"
|
import { Suspense, useCallback, useEffect, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { getAllPermissions } from "@/actions/permission"
|
import { getAllPermissions } from "@/actions/permission"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -25,6 +27,34 @@ type Node = {
|
|||||||
children: Node[]
|
children: Node[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toConstName(name: string): string {
|
||||||
|
return (
|
||||||
|
"Scope" +
|
||||||
|
name
|
||||||
|
.split(/[:_]/)
|
||||||
|
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
||||||
|
.join("")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateScopeCode(roots: Node[]): string {
|
||||||
|
function generateNode(node: Node, isRoot: boolean): string[] {
|
||||||
|
const lines: string[] = []
|
||||||
|
if (isRoot) {
|
||||||
|
lines.push(`// ${node.description}`)
|
||||||
|
}
|
||||||
|
const constName = toConstName(node.name)
|
||||||
|
const comment = isRoot ? "" : ` // ${node.description}`
|
||||||
|
lines.push(`export const ${constName} = "${node.name}"${comment}`)
|
||||||
|
for (const child of node.children) {
|
||||||
|
lines.push(...generateNode(child, false))
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
return roots.map(root => generateNode(root, true).join("\n")).join("\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
export default function PermissionsPage() {
|
export default function PermissionsPage() {
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -95,9 +125,27 @@ function PermissionTable() {
|
|||||||
refresh()
|
refresh()
|
||||||
}, [refresh])
|
}, [refresh])
|
||||||
|
|
||||||
|
const handleCopy = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const code = generateScopeCode(data)
|
||||||
|
await navigator.clipboard.writeText(code)
|
||||||
|
toast.success("已复制权限代码到剪贴板")
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(e instanceof Error ? e.message : "复制失败")
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-background rounded-lg">
|
<div className="flex flex-col gap-3">
|
||||||
<Table>
|
{process.env.NODE_ENV === "development" && (
|
||||||
|
<div>
|
||||||
|
<Button variant="outline" size="sm" onClick={handleCopy}>
|
||||||
|
<Copy className="mr-2 h-4 w-4" />
|
||||||
|
复制权限代码
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Table className="bg-background rounded-lg">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow className="h-10">
|
<TableRow className="h-10">
|
||||||
<TableHead>编码</TableHead>
|
<TableHead>编码</TableHead>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { toast } from "sonner"
|
|||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { createProductSku } from "@/actions/product"
|
import { createProductSku } from "@/actions/product"
|
||||||
import { getAllProductDiscount } from "@/actions/product_discount"
|
import { getAllProductDiscount } from "@/actions/product_discount"
|
||||||
|
import { ProductCodeField } from "@/components/products"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -20,6 +21,7 @@ import {
|
|||||||
FieldError,
|
FieldError,
|
||||||
FieldGroup,
|
FieldGroup,
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
|
FieldSeparator,
|
||||||
} from "@/components/ui/field"
|
} from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import {
|
import {
|
||||||
@@ -30,6 +32,7 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import type { ProductDiscount } from "@/models/product_discount"
|
import type { ProductDiscount } from "@/models/product_discount"
|
||||||
|
import type { SelectedProduct } from "./type"
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
code: z.string().min(1, "请输入套餐编码"),
|
code: z.string().min(1, "请输入套餐编码"),
|
||||||
@@ -42,10 +45,18 @@ const schema = z.object({
|
|||||||
"请输入有效的正数单价",
|
"请输入有效的正数单价",
|
||||||
),
|
),
|
||||||
discount_id: z.string().optional(),
|
discount_id: z.string().optional(),
|
||||||
|
price_min: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.or(z.literal(""))
|
||||||
|
.refine(
|
||||||
|
v => !v || (!Number.isNaN(Number(v)) && Number(v) > 0),
|
||||||
|
"请输入有效的正数价格",
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
export function CreateProductSku(props: {
|
export function CreateProductSku(props: {
|
||||||
productId: number
|
product?: SelectedProduct
|
||||||
onSuccess?: () => void
|
onSuccess?: () => void
|
||||||
}) {
|
}) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@@ -58,6 +69,7 @@ export function CreateProductSku(props: {
|
|||||||
name: "",
|
name: "",
|
||||||
price: "",
|
price: "",
|
||||||
discount_id: "",
|
discount_id: "",
|
||||||
|
price_min: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -74,9 +86,11 @@ export function CreateProductSku(props: {
|
|||||||
}, [open])
|
}, [open])
|
||||||
|
|
||||||
const onSubmit = async (data: z.infer<typeof schema>) => {
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
|
if (!props.product) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await createProductSku({
|
const resp = await createProductSku({
|
||||||
product_id: props.productId,
|
product_id: props.product.id,
|
||||||
code: data.code,
|
code: data.code,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
price: data.price,
|
price: data.price,
|
||||||
@@ -84,7 +98,9 @@ export function CreateProductSku(props: {
|
|||||||
data.discount_id && data.discount_id !== ""
|
data.discount_id && data.discount_id !== ""
|
||||||
? Number(data.discount_id)
|
? Number(data.discount_id)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
price_min: data.price_min,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
form.reset()
|
form.reset()
|
||||||
toast.success("套餐创建成功")
|
toast.success("套餐创建成功")
|
||||||
@@ -109,7 +125,7 @@ export function CreateProductSku(props: {
|
|||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button disabled={!props.productId}>新建套餐</Button>
|
<Button disabled={!props.product}>新建套餐</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
@@ -119,25 +135,6 @@ export function CreateProductSku(props: {
|
|||||||
|
|
||||||
<form id="sku-create" onSubmit={form.handleSubmit(onSubmit)}>
|
<form id="sku-create" onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
<Controller
|
|
||||||
control={form.control}
|
|
||||||
name="code"
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Field>
|
|
||||||
<FieldLabel htmlFor="sku-create-code">套餐编码</FieldLabel>
|
|
||||||
<Input
|
|
||||||
id="sku-create-code"
|
|
||||||
placeholder="请输入套餐编码"
|
|
||||||
{...field}
|
|
||||||
aria-invalid={fieldState.invalid}
|
|
||||||
/>
|
|
||||||
{fieldState.invalid && (
|
|
||||||
<FieldError errors={[fieldState.error]} />
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -176,6 +173,25 @@ export function CreateProductSku(props: {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={form.control}
|
||||||
|
name="price_min"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel htmlFor="sku-create-price">最低价格</FieldLabel>
|
||||||
|
<Input
|
||||||
|
id="sku-create-price"
|
||||||
|
placeholder="请输入单价"
|
||||||
|
{...field}
|
||||||
|
aria-invalid={fieldState.invalid}
|
||||||
|
/>
|
||||||
|
{fieldState.invalid && (
|
||||||
|
<FieldError errors={[fieldState.error]} />
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="discount_id"
|
name="discount_id"
|
||||||
@@ -203,6 +219,16 @@ export function CreateProductSku(props: {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FieldSeparator />
|
||||||
|
|
||||||
|
{props.product && (
|
||||||
|
<ProductCodeField
|
||||||
|
control={form.control}
|
||||||
|
name="code"
|
||||||
|
code={props.product.code}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,31 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
import { Suspense, useCallback, useEffect, useMemo, useState } from "react"
|
import { Suspense, useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import {
|
import {
|
||||||
deleteProductSku,
|
activeProductSku,
|
||||||
getAllProduct,
|
getAllProduct,
|
||||||
getPageProductSku,
|
getPageProductSku,
|
||||||
} from "@/actions/product"
|
} from "@/actions/product"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import {
|
import { SkuCodeBadge } from "@/components/products/format"
|
||||||
AlertDialog,
|
|
||||||
AlertDialogAction,
|
|
||||||
AlertDialogCancel,
|
|
||||||
AlertDialogContent,
|
|
||||||
AlertDialogDescription,
|
|
||||||
AlertDialogFooter,
|
|
||||||
AlertDialogHeader,
|
|
||||||
AlertDialogTitle,
|
|
||||||
AlertDialogTrigger,
|
|
||||||
} from "@/components/ui/alert-dialog"
|
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import type { ProductCode } from "@/lib/base"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import type { Product } from "@/models/product"
|
import type { Product } from "@/models/product"
|
||||||
import type { ProductSku } from "@/models/product_sku"
|
import type { ProductSku } from "@/models/product_sku"
|
||||||
import { BatchUpdateDiscount } from "./batch-discount"
|
import { BatchUpdateDiscount } from "./batch-discount"
|
||||||
import { CreateProductSku } from "./create"
|
import { CreateProductSku } from "./create"
|
||||||
|
import type { SelectedProduct } from "./type"
|
||||||
import { UpdateProductSku } from "./update"
|
import { UpdateProductSku } from "./update"
|
||||||
|
|
||||||
export default function ProductPage() {
|
export default function ProductPage() {
|
||||||
const [selected, setSelected] = useState<number | undefined>(undefined)
|
const [selected, setSelected] = useState<SelectedProduct | undefined>(
|
||||||
|
undefined,
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="size-full flex gap-6 items-stretch">
|
<div className="size-full flex gap-6 items-stretch">
|
||||||
@@ -41,8 +36,8 @@ export default function ProductPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Products(props: {
|
function Products(props: {
|
||||||
selected?: number
|
selected?: SelectedProduct
|
||||||
onSelect?: (id: number) => void
|
onSelect?: (id: SelectedProduct) => void
|
||||||
}) {
|
}) {
|
||||||
const [list, setList] = useState<Product[]>([])
|
const [list, setList] = useState<Product[]>([])
|
||||||
|
|
||||||
@@ -54,7 +49,7 @@ function Products(props: {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const selected = useMemo(() => {
|
const selected = useMemo(() => {
|
||||||
return list.find(item => item.id === props.selected)
|
return list.find(item => item.id === props.selected?.id)
|
||||||
}, [list, props.selected])
|
}, [list, props.selected])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -75,7 +70,7 @@ function Products(props: {
|
|||||||
"size-full box-border p-2 rounded-md flex justify-between items-center select-none",
|
"size-full box-border p-2 rounded-md flex justify-between items-center select-none",
|
||||||
selected?.id === item.id && "bg-primary/20",
|
selected?.id === item.id && "bg-primary/20",
|
||||||
)}
|
)}
|
||||||
onClick={() => props.onSelect?.(item.id)}
|
onClick={() => props.onSelect?.({ id: item.id, code: item.code })}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p>{item.name}</p>
|
<p>{item.name}</p>
|
||||||
@@ -90,24 +85,27 @@ function Products(props: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProductSkus(props: { selected?: number }) {
|
function ProductSkus(props: {
|
||||||
|
selected?: {
|
||||||
|
id: number
|
||||||
|
code: ProductCode
|
||||||
|
}
|
||||||
|
}) {
|
||||||
const action = useCallback(
|
const action = useCallback(
|
||||||
(page: number, size: number) =>
|
(page: number, size: number) =>
|
||||||
getPageProductSku({ page, size, product_id: props.selected }),
|
getPageProductSku({ page, size, product_id: props.selected?.id }),
|
||||||
[props.selected],
|
[props.selected],
|
||||||
)
|
)
|
||||||
|
|
||||||
const table = useDataTable(action)
|
const table = useDataTable(action)
|
||||||
|
console.log(table, "table")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-auto overflow-hidden flex flex-col items-stretch gap-3">
|
<div className="flex-auto overflow-hidden flex flex-col items-stretch gap-3">
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
<CreateProductSku
|
<CreateProductSku product={props.selected} onSuccess={table.refresh} />
|
||||||
productId={props.selected ?? 0}
|
|
||||||
onSuccess={table.refresh}
|
|
||||||
/>
|
|
||||||
<BatchUpdateDiscount
|
<BatchUpdateDiscount
|
||||||
productId={props.selected ?? 0}
|
productId={props.selected?.id ?? 0}
|
||||||
onSuccess={table.refresh}
|
onSuccess={table.refresh}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -118,7 +116,18 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
}}
|
}}
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "套餐编码", accessorKey: "code" },
|
{
|
||||||
|
header: "套餐编码",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
row.original.product ? (
|
||||||
|
<SkuCodeBadge
|
||||||
|
productCode={row.original.product.code}
|
||||||
|
skuCode={row.original.code}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
row.original.code
|
||||||
|
),
|
||||||
|
},
|
||||||
{ header: "套餐名称", accessorKey: "name" },
|
{ header: "套餐名称", accessorKey: "name" },
|
||||||
{ header: "单价", accessorFn: row => Number(row.price).toFixed(2) },
|
{ header: "单价", accessorFn: row => Number(row.price).toFixed(2) },
|
||||||
{ header: "折扣", accessorFn: row => row.discount?.name ?? "—" },
|
{ header: "折扣", accessorFn: row => row.discount?.name ?? "—" },
|
||||||
@@ -131,6 +140,7 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
return Number(value.toFixed(2))
|
return Number(value.toFixed(2))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ header: "最低价格", accessorKey: "price_min" },
|
||||||
{
|
{
|
||||||
header: "创建时间",
|
header: "创建时间",
|
||||||
accessorFn: row => format(row.created_at, "yyyy-MM-dd HH:mm"),
|
accessorFn: row => format(row.created_at, "yyyy-MM-dd HH:mm"),
|
||||||
@@ -149,7 +159,7 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
sku={row.original}
|
sku={row.original}
|
||||||
onSuccess={table.refresh}
|
onSuccess={table.refresh}
|
||||||
/>
|
/>
|
||||||
<DeleteButton sku={row.original} onSuccess={table.refresh} />
|
<ActiveButton sku={row.original} onSuccess={table.refresh} />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -160,18 +170,22 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DeleteButton(props: { sku: ProductSku; onSuccess?: () => void }) {
|
function ActiveButton(props: { sku: ProductSku; onSuccess?: () => void }) {
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
const handleConfirm = async () => {
|
const handleConfirm = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const resp = await deleteProductSku(props.sku.id)
|
const newStatus = props.sku.status === 1 ? 0 : 1
|
||||||
|
const resp = await activeProductSku({
|
||||||
|
id: props.sku.id,
|
||||||
|
status: newStatus,
|
||||||
|
})
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
toast.success("删除成功")
|
toast.success(newStatus === 1 ? "已启用" : "已禁用")
|
||||||
props.onSuccess?.()
|
props.onSuccess?.()
|
||||||
} else {
|
} else {
|
||||||
toast.error(resp.message ?? "删除失败")
|
toast.error(resp.message ?? "操作失败")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : error
|
const message = error instanceof Error ? error.message : error
|
||||||
@@ -182,26 +196,17 @@ function DeleteButton(props: { sku: ProductSku; onSuccess?: () => void }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlertDialog>
|
<Button
|
||||||
<AlertDialogTrigger asChild>
|
size="sm"
|
||||||
<Button size="sm" variant="destructive" disabled={loading}>
|
variant={props.sku?.status === 1 ? "outline" : "default"}
|
||||||
删除
|
onClick={handleConfirm}
|
||||||
</Button>
|
disabled={loading}
|
||||||
</AlertDialogTrigger>
|
>
|
||||||
<AlertDialogContent size="sm">
|
{loading ? (
|
||||||
<AlertDialogHeader>
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
<AlertDialogTitle>确认删除</AlertDialogTitle>
|
) : (
|
||||||
<AlertDialogDescription>
|
<>{props.sku?.status === 1 ? "禁用" : "启用"}</>
|
||||||
确定要删除套餐「{props.sku.name}」吗?此操作不可撤销。
|
)}
|
||||||
</AlertDialogDescription>
|
</Button>
|
||||||
</AlertDialogHeader>
|
|
||||||
<AlertDialogFooter>
|
|
||||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
|
||||||
<AlertDialogAction variant="destructive" onClick={handleConfirm}>
|
|
||||||
删除
|
|
||||||
</AlertDialogAction>
|
|
||||||
</AlertDialogFooter>
|
|
||||||
</AlertDialogContent>
|
|
||||||
</AlertDialog>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/app/(root)/product/type.ts
Normal file
6
src/app/(root)/product/type.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import type { ProductCode } from "@/lib/base"
|
||||||
|
|
||||||
|
export type SelectedProduct = {
|
||||||
|
id: number
|
||||||
|
code: ProductCode
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { toast } from "sonner"
|
|||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { updateProductSku } from "@/actions/product"
|
import { updateProductSku } from "@/actions/product"
|
||||||
import { getAllProductDiscount } from "@/actions/product_discount"
|
import { getAllProductDiscount } from "@/actions/product_discount"
|
||||||
|
import { ProductCodeField } from "@/components/products"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -20,6 +21,7 @@ import {
|
|||||||
FieldError,
|
FieldError,
|
||||||
FieldGroup,
|
FieldGroup,
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
|
FieldSeparator,
|
||||||
} from "@/components/ui/field"
|
} from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import {
|
import {
|
||||||
@@ -43,6 +45,13 @@ const schema = z.object({
|
|||||||
"请输入有效的正数单价",
|
"请输入有效的正数单价",
|
||||||
),
|
),
|
||||||
discount_id: z.string().optional(),
|
discount_id: z.string().optional(),
|
||||||
|
price_min: z
|
||||||
|
.string()
|
||||||
|
.min(1, "请输入最低价格")
|
||||||
|
.refine(
|
||||||
|
v => !Number.isNaN(Number(v)) && Number(v) > 0,
|
||||||
|
"请输入有效的正数价格",
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
export function UpdateProductSku(props: {
|
export function UpdateProductSku(props: {
|
||||||
@@ -59,6 +68,7 @@ export function UpdateProductSku(props: {
|
|||||||
name: props.sku.name,
|
name: props.sku.name,
|
||||||
price: props.sku.price,
|
price: props.sku.price,
|
||||||
discount_id: props.sku.discount ? String(props.sku.discount.id) : "",
|
discount_id: props.sku.discount ? String(props.sku.discount.id) : "",
|
||||||
|
price_min: props.sku.price_min ?? "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -73,6 +83,8 @@ export function UpdateProductSku(props: {
|
|||||||
}, [open])
|
}, [open])
|
||||||
|
|
||||||
const onSubmit = async (data: z.infer<typeof schema>) => {
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
|
console.log(data, "data")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await updateProductSku({
|
const resp = await updateProductSku({
|
||||||
id: props.sku.id,
|
id: props.sku.id,
|
||||||
@@ -83,7 +95,22 @@ export function UpdateProductSku(props: {
|
|||||||
data.discount_id && data.discount_id !== ""
|
data.discount_id && data.discount_id !== ""
|
||||||
? Number(data.discount_id)
|
? Number(data.discount_id)
|
||||||
: null,
|
: null,
|
||||||
|
price_min: data.price_min,
|
||||||
})
|
})
|
||||||
|
console.log({
|
||||||
|
id: props.sku.id,
|
||||||
|
code: data.code,
|
||||||
|
name: data.name,
|
||||||
|
price: data.price,
|
||||||
|
discount_id:
|
||||||
|
data.discount_id && data.discount_id !== ""
|
||||||
|
? Number(data.discount_id)
|
||||||
|
: null,
|
||||||
|
price_min: data.price_min,
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(resp, "resp")
|
||||||
|
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
toast.success("套餐修改成功")
|
toast.success("套餐修改成功")
|
||||||
props.onSuccess?.()
|
props.onSuccess?.()
|
||||||
@@ -104,6 +131,7 @@ export function UpdateProductSku(props: {
|
|||||||
name: props.sku.name,
|
name: props.sku.name,
|
||||||
price: props.sku.price,
|
price: props.sku.price,
|
||||||
discount_id: props.sku.discount ? String(props.sku.discount.id) : "",
|
discount_id: props.sku.discount ? String(props.sku.discount.id) : "",
|
||||||
|
price_min: props.sku.price_min ?? "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
setOpen(value)
|
setOpen(value)
|
||||||
@@ -124,25 +152,6 @@ export function UpdateProductSku(props: {
|
|||||||
|
|
||||||
<form id="sku-update" onSubmit={form.handleSubmit(onSubmit)}>
|
<form id="sku-update" onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
<Controller
|
|
||||||
control={form.control}
|
|
||||||
name="code"
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Field>
|
|
||||||
<FieldLabel htmlFor="sku-update-code">套餐编码</FieldLabel>
|
|
||||||
<Input
|
|
||||||
id="sku-update-code"
|
|
||||||
placeholder="请输入套餐编码"
|
|
||||||
{...field}
|
|
||||||
aria-invalid={fieldState.invalid}
|
|
||||||
/>
|
|
||||||
{fieldState.invalid && (
|
|
||||||
<FieldError errors={[fieldState.error]} />
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -180,7 +189,24 @@ export function UpdateProductSku(props: {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
control={form.control}
|
||||||
|
name="price_min"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel htmlFor="sku-create-price">最低价格</FieldLabel>
|
||||||
|
<Input
|
||||||
|
id="sku-create-price"
|
||||||
|
placeholder="请输入最低价格"
|
||||||
|
{...field}
|
||||||
|
aria-invalid={fieldState.invalid}
|
||||||
|
/>
|
||||||
|
{fieldState.invalid && (
|
||||||
|
<FieldError errors={[fieldState.error]} />
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="discount_id"
|
name="discount_id"
|
||||||
@@ -208,6 +234,16 @@ export function UpdateProductSku(props: {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FieldSeparator />
|
||||||
|
|
||||||
|
{props.sku.product && (
|
||||||
|
<ProductCodeField
|
||||||
|
control={form.control}
|
||||||
|
name="code"
|
||||||
|
code={props.sku.product.code}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -281,10 +281,9 @@ function ResourceList({ resourceType }: ResourceListProps) {
|
|||||||
|
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{
|
{
|
||||||
header: "会员号",
|
header: "会员号",
|
||||||
accessorFn: (row: Resources) => row.user?.phone || "-",
|
accessorFn: (row: Resources) => row.user?.phone || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "套餐",
|
header: "套餐",
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
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, XCircle } from "lucide-react"
|
||||||
import { Suspense, 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, getTradeComplete } from "@/actions/trade"
|
||||||
|
import { Auth } from "@/components/auth"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
@@ -22,6 +24,7 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
|
import { ScopeTradeWriteComplete } from "@/lib/scopes"
|
||||||
import type { Trade } from "@/models/trade"
|
import type { Trade } from "@/models/trade"
|
||||||
|
|
||||||
type FilterValues = {
|
type FilterValues = {
|
||||||
@@ -82,9 +85,14 @@ export default function TradePage() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const table = useDataTable<Trade>((page, size) =>
|
const fetchTrades = useCallback(
|
||||||
getPageTrade({ page, size, ...filters }),
|
(page: number, size: number) => {
|
||||||
|
return getPageTrade({ page, size, ...filters })
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Trade>(fetchTrades)
|
||||||
const onFilter = handleSubmit(data => {
|
const onFilter = handleSubmit(data => {
|
||||||
const result: FilterValues = {}
|
const result: FilterValues = {}
|
||||||
|
|
||||||
@@ -105,6 +113,27 @@ export default function TradePage() {
|
|||||||
table.pagination.onPageChange(1)
|
table.pagination.onPageChange(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [completingId, setCompletingId] = useState<string | null>(null)
|
||||||
|
|
||||||
|
const handleComplete = async (trade: Trade) => {
|
||||||
|
if (completingId) return
|
||||||
|
setCompletingId(trade.inner_no)
|
||||||
|
try {
|
||||||
|
const result = await getTradeComplete({
|
||||||
|
user_id: Number(trade.user_id),
|
||||||
|
trade_no: trade.inner_no,
|
||||||
|
method: trade.method,
|
||||||
|
})
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("订单已完成")
|
||||||
|
} else {
|
||||||
|
toast.error(result.message || "操作失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("完成订单失败:", error)
|
||||||
|
toast.error("网络错误,请稍后重试")
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{/* 筛选表单 */}
|
{/* 筛选表单 */}
|
||||||
@@ -258,10 +287,9 @@ export default function TradePage() {
|
|||||||
<DataTable<Trade>
|
<DataTable<Trade>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{
|
{
|
||||||
header: "会员号",
|
header: "会员号",
|
||||||
accessorFn: row => row.user?.phone || "-",
|
accessorFn: row => row.user?.phone || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "订单号",
|
header: "订单号",
|
||||||
@@ -369,6 +397,30 @@ export default function TradePage() {
|
|||||||
cell: ({ row }) =>
|
cell: ({ row }) =>
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const isPending = row.original.status === 0
|
||||||
|
const isLoading = completingId === row.original.inner_no
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Auth scope={ScopeTradeWriteComplete}>
|
||||||
|
{isPending && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleComplete(row.original)}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? "处理中..." : "完成订单"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Auth>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
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 { bindAdmin, getPageUser } from "@/actions/user"
|
import { bindAdmin, getPageUserPage } from "@/actions/user"
|
||||||
import { DataTable } from "@/components/data-table"
|
import { Auth } from "@/components/auth"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
@@ -16,82 +16,47 @@ import {
|
|||||||
FieldLabel,
|
FieldLabel,
|
||||||
} from "@/components/ui/field"
|
} from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { useFetch } from "@/hooks/data"
|
||||||
|
import { ScopeUserWriteBind } from "@/lib/scopes"
|
||||||
import type { User } from "@/models/user"
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
interface UserQueryParams {
|
interface FilterValues {
|
||||||
account?: string
|
phone?: string
|
||||||
name?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterSchema = z.object({
|
const filterSchema = z.object({
|
||||||
account: z.string().optional(),
|
phone: z.string().optional(),
|
||||||
name: z.string().optional(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
type FormValues = z.infer<typeof filterSchema>
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function UserPage() {
|
export default function UserPage() {
|
||||||
const [userList, setUserList] = useState<User[]>([])
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
const { control, handleSubmit, reset } = useForm<FormValues>({
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
resolver: zodResolver(filterSchema),
|
resolver: zodResolver(filterSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
account: "",
|
phone: "",
|
||||||
name: "",
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const fetchUsers = useCallback(async (filters: UserQueryParams = {}) => {
|
const fetchUsers = useCallback(
|
||||||
setLoading(true)
|
(page: number, size: number) => getPageUserPage({ page, size, ...filters }),
|
||||||
try {
|
[filters],
|
||||||
const res = await getPageUser(filters)
|
|
||||||
if (res.success) {
|
|
||||||
const req = [{ ...res.data }]
|
|
||||||
setUserList(req)
|
|
||||||
} else {
|
|
||||||
toast.error(res.message || "获取用户失败")
|
|
||||||
setUserList([])
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : error
|
|
||||||
toast.error(`获取管理员失败: ${message}`)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const bind = useCallback(
|
|
||||||
async (id: number) => {
|
|
||||||
try {
|
|
||||||
const res = await bindAdmin({ id })
|
|
||||||
if (res.success) {
|
|
||||||
toast.success("用户已认领")
|
|
||||||
fetchUsers()
|
|
||||||
} else {
|
|
||||||
toast.error(res.message || "认领失败")
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : error
|
|
||||||
toast.error(`认领请求失败: ${message}`)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[fetchUsers],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const onFilter = handleSubmit((data: FormValues) => {
|
const table = useDataTable<User>(fetchUsers)
|
||||||
const params: UserQueryParams = {}
|
const bind = useFetch(table, (id: number) => bindAdmin({ id }), {
|
||||||
|
done: "用户已认领",
|
||||||
|
fail: "用户认领失败",
|
||||||
|
})
|
||||||
|
|
||||||
if (data.account?.trim()) params.account = data.account.trim()
|
const onFilter = handleSubmit(data => {
|
||||||
if (data.name?.trim()) params.name = data.name.trim()
|
const result: FilterValues = {}
|
||||||
const hasValidFilter = Object.keys(params).length > 0
|
if (data.phone) result.phone = data.phone
|
||||||
if (hasValidFilter) {
|
setFilters(result)
|
||||||
fetchUsers(params)
|
table.pagination.onPageChange(1)
|
||||||
} else {
|
|
||||||
setUserList([])
|
|
||||||
setLoading(false)
|
|
||||||
toast.info("请输入筛选条件后再查询")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -99,30 +64,15 @@ export default function UserPage() {
|
|||||||
<form onSubmit={onFilter} className="bg-white p-4">
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="account"
|
name="phone"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Field
|
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
className="w-80 flex-none"
|
|
||||||
>
|
|
||||||
<FieldLabel>账号/手机号/邮箱</FieldLabel>
|
|
||||||
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
|
||||||
</Field>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
|
||||||
name="name"
|
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field
|
||||||
data-invalid={fieldState.invalid}
|
data-invalid={fieldState.invalid}
|
||||||
className="w-40 flex-none"
|
className="w-40 flex-none"
|
||||||
>
|
>
|
||||||
<FieldLabel>姓名</FieldLabel>
|
<FieldLabel>手机号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入姓名" />
|
<Input {...field} placeholder="请输入手机号" />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
@@ -136,7 +86,7 @@ export default function UserPage() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
reset()
|
reset()
|
||||||
setUserList([])
|
setFilters({})
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -147,10 +97,9 @@ export default function UserPage() {
|
|||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<DataTable<User>
|
<DataTable<User>
|
||||||
data={userList || []}
|
{...table}
|
||||||
status={loading ? "load" : "done"}
|
status={loading ? "load" : "done"}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "ID", accessorKey: "id" },
|
|
||||||
{ header: "账号", accessorKey: "username" },
|
{ header: "账号", accessorKey: "username" },
|
||||||
{ header: "手机", accessorKey: "phone" },
|
{ header: "手机", accessorKey: "phone" },
|
||||||
{ header: "邮箱", accessorKey: "email" },
|
{ header: "邮箱", accessorKey: "email" },
|
||||||
@@ -187,14 +136,6 @@ export default function UserPage() {
|
|||||||
</Badge>
|
</Badge>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
header: "身份证号",
|
|
||||||
accessorKey: "id_no",
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const idNo = row.original.id_no
|
|
||||||
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : "-"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
header: "客户来源",
|
header: "客户来源",
|
||||||
accessorKey: "source",
|
accessorKey: "source",
|
||||||
@@ -214,10 +155,6 @@ export default function UserPage() {
|
|||||||
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
||||||
},
|
},
|
||||||
{ header: "联系方式", accessorKey: "contact_wechat" },
|
{ header: "联系方式", accessorKey: "contact_wechat" },
|
||||||
{
|
|
||||||
header: "客户经理",
|
|
||||||
cell: ({ row }) => row.original.admin?.name || "-",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
header: "最后登录时间",
|
header: "最后登录时间",
|
||||||
accessorKey: "last_login",
|
accessorKey: "last_login",
|
||||||
@@ -227,12 +164,12 @@ export default function UserPage() {
|
|||||||
new Date(row.original.last_login),
|
new Date(row.original.last_login),
|
||||||
"yyyy-MM-dd HH:mm",
|
"yyyy-MM-dd HH:mm",
|
||||||
)
|
)
|
||||||
: "-",
|
: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "最后登录IP",
|
header: "最后登录IP",
|
||||||
accessorKey: "last_login_ip",
|
accessorKey: "last_login_ip",
|
||||||
cell: ({ row }) => row.original.last_login_ip || "-",
|
cell: ({ row }) => row.original.last_login_ip || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "创建时间",
|
header: "创建时间",
|
||||||
@@ -245,13 +182,15 @@ export default function UserPage() {
|
|||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ctx => (
|
cell: ctx => (
|
||||||
<Button
|
<Auth scope={ScopeUserWriteBind}>
|
||||||
size="sm"
|
<Button
|
||||||
onClick={() => bind(ctx.row.original.id)}
|
size="sm"
|
||||||
disabled={!!ctx.row.original.admin_id}
|
onClick={() => bind(ctx.row.original.id)}
|
||||||
>
|
disabled={!!ctx.row.original.admin_id}
|
||||||
{ctx.row.original.admin_id ? "已认领" : "认领"}
|
>
|
||||||
</Button>
|
{ctx.row.original.admin_id ? "已认领" : "认领"}
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export type DataTableProps<T> = {
|
|||||||
headRow?: string
|
headRow?: string
|
||||||
dataRow?: string
|
dataRow?: string
|
||||||
}
|
}
|
||||||
|
serial?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DataTable<T extends Record<string, unknown>>(
|
export function DataTable<T extends Record<string, unknown>>(
|
||||||
@@ -36,7 +37,14 @@ export function DataTable<T extends Record<string, unknown>>(
|
|||||||
) {
|
) {
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: props.data,
|
data: props.data,
|
||||||
columns: props.columns,
|
columns: [
|
||||||
|
{
|
||||||
|
id: "serial",
|
||||||
|
header: "#",
|
||||||
|
cell: ({ row }) => row.index + 1,
|
||||||
|
},
|
||||||
|
...props.columns,
|
||||||
|
],
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
manualPagination: true,
|
manualPagination: true,
|
||||||
rowCount: props.pagination?.total,
|
rowCount: props.pagination?.total,
|
||||||
|
|||||||
62
src/components/products/format.tsx
Normal file
62
src/components/products/format.tsx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import type { ReactNode } from "react"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { ProductCode } from "@/lib/base"
|
||||||
|
|
||||||
|
interface SkuCodeBadgeProps {
|
||||||
|
productCode: ProductCode
|
||||||
|
skuCode: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SkuCodeBadge({
|
||||||
|
productCode,
|
||||||
|
skuCode,
|
||||||
|
}: SkuCodeBadgeProps): ReactNode {
|
||||||
|
switch (productCode) {
|
||||||
|
case ProductCode.Short:
|
||||||
|
case ProductCode.Long:
|
||||||
|
return <ParsedSkuCodeBadge skuCode={skuCode} />
|
||||||
|
default:
|
||||||
|
return <Badge variant="outline">{skuCode}</Badge>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ParsedSkuCodeBadge({ skuCode }: { skuCode: string }): ReactNode {
|
||||||
|
const params = new URLSearchParams(skuCode)
|
||||||
|
const modeStr = params.get("mode")
|
||||||
|
|
||||||
|
let mode: string | undefined
|
||||||
|
let modeClass: string | undefined
|
||||||
|
switch (modeStr) {
|
||||||
|
case "time":
|
||||||
|
mode = "包时"
|
||||||
|
modeClass = "bg-green-50"
|
||||||
|
break
|
||||||
|
case "quota":
|
||||||
|
mode = "包量"
|
||||||
|
modeClass = "bg-blue-50"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
const live = params.get("live")
|
||||||
|
const expire = params.get("expire")
|
||||||
|
|
||||||
|
if (!mode || !live || !expire) {
|
||||||
|
return (
|
||||||
|
<Badge variant="secondary" className="bg-red-50">
|
||||||
|
{skuCode}(解析失败)
|
||||||
|
</Badge>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
<Badge variant="secondary" className={modeClass}>
|
||||||
|
类型:{mode}
|
||||||
|
</Badge>
|
||||||
|
<Badge variant="secondary">有效时间:{live} 分钟</Badge>
|
||||||
|
{expire !== "0" && (
|
||||||
|
<Badge variant="secondary">过期时间:{expire} 天</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
200
src/components/products/index.tsx
Normal file
200
src/components/products/index.tsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import type { ChangeEvent } from "react"
|
||||||
|
import {
|
||||||
|
type Control,
|
||||||
|
type Path,
|
||||||
|
type UseControllerReturn,
|
||||||
|
useController,
|
||||||
|
} from "react-hook-form"
|
||||||
|
import { ProductCode } from "@/lib/base"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
FieldLegend,
|
||||||
|
} from "../ui/field"
|
||||||
|
import { Input } from "../ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "../ui/select"
|
||||||
|
|
||||||
|
export function ProductCodeField<
|
||||||
|
T extends {
|
||||||
|
code: string
|
||||||
|
},
|
||||||
|
>(props: { control: Control<T>; name: Path<T>; code: ProductCode }) {
|
||||||
|
const rt = useController(props)
|
||||||
|
|
||||||
|
switch (props.code) {
|
||||||
|
case ProductCode.Short:
|
||||||
|
return <ProductShortCode {...rt} />
|
||||||
|
case ProductCode.Long:
|
||||||
|
return <ProductLongCode {...rt} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProductShortCode<T extends { code: string }>(
|
||||||
|
props: UseControllerReturn<T>,
|
||||||
|
) {
|
||||||
|
const { field, fieldState } = props
|
||||||
|
|
||||||
|
const params = new URLSearchParams(field.value)
|
||||||
|
const setParams = (data: {
|
||||||
|
mode?: string
|
||||||
|
live?: string
|
||||||
|
expire?: string
|
||||||
|
}) => {
|
||||||
|
if (data.mode) params.set("mode", data.mode)
|
||||||
|
if (data.live) params.set("live", data.live)
|
||||||
|
if (data.expire) params.set("expire", data.expire)
|
||||||
|
field.onChange(params.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
const onModeChange = (value: string) => {
|
||||||
|
setParams({ mode: value })
|
||||||
|
}
|
||||||
|
const onLiveChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value || "0"
|
||||||
|
if (value.length > 1 && value[0] === "0") {
|
||||||
|
value = value.substring(1, value.length)
|
||||||
|
}
|
||||||
|
if (!/^([0-9]+)$/.test(value)) return
|
||||||
|
setParams({ live: value })
|
||||||
|
}
|
||||||
|
const onExpireChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value || "0"
|
||||||
|
if (value.length > 1 && value[0] === "0") {
|
||||||
|
value = value.substring(1, value.length)
|
||||||
|
}
|
||||||
|
if (!/^([0-9]+)$/.test(value)) return
|
||||||
|
setParams({ expire: value })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FieldLegend>
|
||||||
|
<FieldLegend>短效套餐详情</FieldLegend>
|
||||||
|
<FieldGroup>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>套餐类型</FieldLabel>
|
||||||
|
<Select
|
||||||
|
defaultValue={params.get("mode") ?? "quota"}
|
||||||
|
onValueChange={onModeChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择套餐类型" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="time">包时</SelectItem>
|
||||||
|
<SelectItem value="quota">包量</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>有效期(分钟)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={params.get("live") ?? "0"}
|
||||||
|
onChange={onLiveChange}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
{params.get("mode") === "time" && (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>过期时间(天)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={params.get("expire") ?? "0"}
|
||||||
|
onChange={onExpireChange}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
{fieldState.error && <FieldError errors={[fieldState.error]} />}
|
||||||
|
</FieldGroup>
|
||||||
|
</FieldLegend>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProductLongCode<T extends { code: string }>(
|
||||||
|
props: UseControllerReturn<T>,
|
||||||
|
) {
|
||||||
|
const { field, fieldState } = props
|
||||||
|
|
||||||
|
const params = new URLSearchParams(field.value)
|
||||||
|
const setParams = (data: {
|
||||||
|
mode?: string
|
||||||
|
live?: string
|
||||||
|
expire?: string
|
||||||
|
}) => {
|
||||||
|
if (data.mode) params.set("mode", data.mode)
|
||||||
|
if (data.live) params.set("live", data.live)
|
||||||
|
if (data.expire) params.set("expire", data.expire)
|
||||||
|
field.onChange(params.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
const onModeChange = (value: string) => {
|
||||||
|
setParams({ mode: value })
|
||||||
|
}
|
||||||
|
const onLiveChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value || "0"
|
||||||
|
if (value.length > 1 && value[0] === "0") {
|
||||||
|
value = value.substring(1, value.length)
|
||||||
|
}
|
||||||
|
if (!/^([0-9]+)$/.test(value)) return
|
||||||
|
setParams({ live: value })
|
||||||
|
}
|
||||||
|
const onExpireChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value || "0"
|
||||||
|
if (value.length > 1 && value[0] === "0") {
|
||||||
|
value = value.substring(1, value.length)
|
||||||
|
}
|
||||||
|
if (!/^([0-9]+)$/.test(value)) return
|
||||||
|
setParams({ expire: value })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FieldLegend>
|
||||||
|
<FieldLegend>长效套餐详情</FieldLegend>
|
||||||
|
<FieldGroup>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>套餐类型</FieldLabel>
|
||||||
|
<Select
|
||||||
|
defaultValue={params.get("mode") ?? "quota"}
|
||||||
|
onValueChange={onModeChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择套餐类型" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="time">包时</SelectItem>
|
||||||
|
<SelectItem value="quota">包量</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>有效期(分钟)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={params.get("live") ?? "0"}
|
||||||
|
onChange={onLiveChange}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
{params.get("mode") === "time" && (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>过期时间(天)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={params.get("expire") ?? "0"}
|
||||||
|
onChange={onExpireChange}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
{fieldState.error && <FieldError errors={[fieldState.error]} />}
|
||||||
|
</FieldGroup>
|
||||||
|
</FieldLegend>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ export const ScopeProductWrite = "product:write" // 写入产品
|
|||||||
export const ScopeProductSku = "product_sku"
|
export const ScopeProductSku = "product_sku"
|
||||||
export const ScopeProductSkuRead = "product_sku:read" // 读取产品套餐列表
|
export const ScopeProductSkuRead = "product_sku:read" // 读取产品套餐列表
|
||||||
export const ScopeProductSkuWrite = "product_sku:write" // 写入产品套餐
|
export const ScopeProductSkuWrite = "product_sku:write" // 写入产品套餐
|
||||||
|
export const ScopeProductSkuWriteStatus = "product_sku:write:status" // 更改产品套餐状态
|
||||||
|
|
||||||
// 折扣
|
// 折扣
|
||||||
export const ScopeDiscount = "discount"
|
export const ScopeDiscount = "discount"
|
||||||
@@ -32,14 +33,23 @@ export const ScopeDiscountWrite = "discount:write" // 写入折扣
|
|||||||
export const ScopeResource = "resource"
|
export const ScopeResource = "resource"
|
||||||
export const ScopeResourceRead = "resource:read" // 读取用户套餐列表
|
export const ScopeResourceRead = "resource:read" // 读取用户套餐列表
|
||||||
export const ScopeResourceWrite = "resource:write" // 写入用户套餐
|
export const ScopeResourceWrite = "resource:write" // 写入用户套餐
|
||||||
|
export const ScopeResourceShort = "resource:short" // 短效动态套餐
|
||||||
|
export const ScopeResourceShortRead = "resource:short:read" // 读取用户短效动态套餐列表
|
||||||
|
export const ScopeResourceShortReadOfUser = "resource:short:read:of_user" // 读取指定用户的短效动态套餐列表
|
||||||
|
export const ScopeResourceLong = "resource:long" // 长效动态套餐
|
||||||
|
export const ScopeResourceLongRead = "resource:long:read" // 读取用户长效动态套餐列表
|
||||||
|
export const ScopeResourceLongReadOfUser = "resource:long:read:of_user" // 读取指定用户的长效动态套餐列表
|
||||||
|
|
||||||
// 用户
|
// 用户
|
||||||
export const ScopeUser = "user"
|
export const ScopeUser = "user"
|
||||||
export const ScopeUserRead = "user:read" // 读取用户列表
|
export const ScopeUserRead = "user:read" // 读取用户列表
|
||||||
|
export const ScopeUserReadOne = "user:read:one" // 读取单个用户
|
||||||
|
export const ScopeUserReadNotBind = "user:read:not_bind" // 读取未绑定管理员的用户列表
|
||||||
export const ScopeUserWrite = "user:write" // 写入用户
|
export const ScopeUserWrite = "user:write" // 写入用户
|
||||||
export const ScopeUserWriteBalance = "user:write:balance" // 写入用户余额
|
export const ScopeUserWriteBalance = "user:write:balance" // 写入用户余额
|
||||||
export const ScopeUserReadOne = "user:read:one" // 读取单个用户
|
export const ScopeUserWriteBalanceInc = "user:write:balance:inc" // 增加用户余额
|
||||||
export const ScopeUserWriteBind = "user:write:bind" // 认领用户
|
export const ScopeUserWriteBalanceDec = "user:write:balance:dec" // 减少用户余额
|
||||||
|
export const ScopeUserWriteBind = "user:write:bind" // 用户认领
|
||||||
|
|
||||||
// 优惠券
|
// 优惠券
|
||||||
export const ScopeCoupon = "coupon"
|
export const ScopeCoupon = "coupon"
|
||||||
@@ -49,19 +59,29 @@ export const ScopeCouponWrite = "coupon:write" // 写入优惠券
|
|||||||
// 批次
|
// 批次
|
||||||
export const ScopeBatch = "batch"
|
export const ScopeBatch = "batch"
|
||||||
export const ScopeBatchRead = "batch:read" // 读取批次列表
|
export const ScopeBatchRead = "batch:read" // 读取批次列表
|
||||||
|
export const ScopeBatchReadOfUser = "batch:read:of_user" // 读取指定用户的批次列表
|
||||||
export const ScopeBatchWrite = "batch:write" // 写入批次
|
export const ScopeBatchWrite = "batch:write" // 写入批次
|
||||||
|
|
||||||
// IP
|
// IP
|
||||||
export const ScopeChannel = "channel"
|
export const ScopeChannel = "channel"
|
||||||
export const ScopeChannelRead = "channel:read" // 读取 IP 列表
|
export const ScopeChannelRead = "channel:read" // 读取 IP 列表
|
||||||
|
export const ScopeChannelReadOfUser = "channel:read:of_user" // 读取指定用户的 IP 列表
|
||||||
export const ScopeChannelWrite = "channel:write" // 写入 IP
|
export const ScopeChannelWrite = "channel:write" // 写入 IP
|
||||||
|
|
||||||
// 交易
|
// 交易
|
||||||
export const ScopeTrade = "trade"
|
export const ScopeTrade = "trade"
|
||||||
export const ScopeTradeRead = "trade:read" // 读取交易列表
|
export const ScopeTradeRead = "trade:read" // 读取交易列表
|
||||||
|
export const ScopeTradeReadOfUser = "trade:read:of_user" // 读取指定用户的交易列表
|
||||||
export const ScopeTradeWrite = "trade:write" // 写入交易
|
export const ScopeTradeWrite = "trade:write" // 写入交易
|
||||||
|
export const ScopeTradeWriteComplete = "trade:write:complete" // 完成交易
|
||||||
|
|
||||||
// 账单
|
// 账单
|
||||||
export const ScopeBill = "bill"
|
export const ScopeBill = "bill"
|
||||||
export const ScopeBillRead = "bill:read" // 读取账单列表
|
export const ScopeBillRead = "bill:read" // 读取账单列表
|
||||||
|
export const ScopeBillReadOfUser = "bill:read:of_user" // 读取指定用户的账单列表
|
||||||
export const ScopeBillWrite = "bill:write" // 写入账单
|
export const ScopeBillWrite = "bill:write" // 写入账单
|
||||||
|
|
||||||
|
// 余额变动
|
||||||
|
export const ScopeBalanceActivity = "balance_activity"
|
||||||
|
export const ScopeBalanceActivityRead = "balance_activity:read" // 读取余额变动列表
|
||||||
|
export const ScopeBalanceActivityReadOfUser = "balance_activity:read:of_user" // 读取指定用户的余额变动列表
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export type Admin = {
|
|||||||
phone?: string
|
phone?: string
|
||||||
email?: string
|
email?: string
|
||||||
status: AdminStatus
|
status: AdminStatus
|
||||||
|
lock: boolean
|
||||||
lastLogin?: Date
|
lastLogin?: Date
|
||||||
lastLoginIp?: string
|
lastLoginIp?: string
|
||||||
lastLoginUa?: string
|
lastLoginUa?: string
|
||||||
|
|||||||
18
src/models/balance.ts
Normal file
18
src/models/balance.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import type { Admin } from "./admin"
|
||||||
|
import type { Billing } from "./billing"
|
||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
|
export type Balance = {
|
||||||
|
id: number
|
||||||
|
user_id: string
|
||||||
|
bill_id: string
|
||||||
|
admin_id: string
|
||||||
|
amount: number
|
||||||
|
balance_prev: number
|
||||||
|
balance_curr: number
|
||||||
|
remark: string
|
||||||
|
created_at: Date
|
||||||
|
user?: User
|
||||||
|
admin?: Admin
|
||||||
|
bill?: Billing
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import type { ProductDiscount } from "./product_discount"
|
|
||||||
|
|
||||||
export type Cust = {
|
|
||||||
id: number
|
|
||||||
admin_id?: number
|
|
||||||
phone: string
|
|
||||||
admin?: Admin
|
|
||||||
password: string
|
|
||||||
source: number
|
|
||||||
discount_id: string
|
|
||||||
has_password: boolean
|
|
||||||
username: string
|
|
||||||
email: string
|
|
||||||
name: string
|
|
||||||
avatar: string
|
|
||||||
status: number
|
|
||||||
balance: number
|
|
||||||
id_type: number
|
|
||||||
id_no: string
|
|
||||||
id_token: string
|
|
||||||
contact_qq: string
|
|
||||||
contact_wechat: string
|
|
||||||
last_login: Date
|
|
||||||
last_login_host: string
|
|
||||||
last_login_agent: string
|
|
||||||
last_login_ip: string
|
|
||||||
created_at: Date
|
|
||||||
updated_at: Date
|
|
||||||
discount: ProductDiscount
|
|
||||||
}
|
|
||||||
export type Admin = {
|
|
||||||
name: string
|
|
||||||
password: string
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import type { ProductCode } from "@/lib/base"
|
||||||
import type { Model } from "./base/model"
|
import type { Model } from "./base/model"
|
||||||
import type { ProductSku } from "./product_sku"
|
import type { ProductSku } from "./product_sku"
|
||||||
|
|
||||||
export type Product = Model & {
|
export type Product = Model & {
|
||||||
code: string
|
code: ProductCode
|
||||||
name: string
|
name: string
|
||||||
description?: string
|
description?: string
|
||||||
sort: number
|
sort: number
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ export type ProductSku = Model & {
|
|||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
price: string
|
price: string
|
||||||
|
status: number
|
||||||
product?: Product
|
product?: Product
|
||||||
|
price_min?: string
|
||||||
discount?: ProductDiscount
|
discount?: ProductDiscount
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export type Trade = {
|
|||||||
type: number
|
type: number
|
||||||
subject: string
|
subject: string
|
||||||
status: number
|
status: number
|
||||||
|
user_id: string
|
||||||
created_at: Date
|
created_at: Date
|
||||||
canceled_at: Date
|
canceled_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { Admin } from "./admin"
|
import type { Admin } from "./admin"
|
||||||
|
import type { ProductDiscount } from "./product_discount"
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
id: number
|
id: number
|
||||||
admin_id?: number
|
admin_id?: number
|
||||||
admin?: Admin
|
|
||||||
phone: string
|
phone: string
|
||||||
source: number
|
source: number
|
||||||
has_password: boolean
|
has_password: boolean
|
||||||
@@ -24,4 +24,8 @@ export type User = {
|
|||||||
last_login_ip: string
|
last_login_ip: string
|
||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
password: string
|
||||||
|
discount_id: string
|
||||||
|
discount: ProductDiscount
|
||||||
|
admin?: Admin
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user