Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc29a025b0 | ||
|
|
85f9e68e32 | ||
|
|
7cd1a7cbe7 | ||
|
|
66ee6bb9fd |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lanhu-admin",
|
"name": "lanhu-admin",
|
||||||
"version": "1.7.0",
|
"version": "1.8.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
||||||
|
|||||||
@@ -7,22 +7,28 @@ export async function getPagCoupon(params: { page: number; size: number }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createCoupon(data: {
|
export async function createCoupon(data: {
|
||||||
code: string
|
name: string
|
||||||
amount: number
|
amount: number
|
||||||
remark?: string
|
count: number
|
||||||
min_amount?: number
|
status: number
|
||||||
|
min_amount: number
|
||||||
expire_at?: Date
|
expire_at?: Date
|
||||||
|
expire_in?: number
|
||||||
|
expire_type: number
|
||||||
}) {
|
}) {
|
||||||
return callByUser<Coupon>("/api/admin/coupon/create", data)
|
return callByUser<Coupon>("/api/admin/coupon/create", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateCoupon(data: {
|
export async function updateCoupon(data: {
|
||||||
code: string
|
id: number
|
||||||
|
name: string
|
||||||
amount: number
|
amount: number
|
||||||
remark?: string
|
min_amount: number
|
||||||
min_amount?: number
|
count: number
|
||||||
|
status: number
|
||||||
|
expire_type: number
|
||||||
expire_at?: Date
|
expire_at?: Date
|
||||||
status?: number
|
expire_in?: number
|
||||||
}) {
|
}) {
|
||||||
return callByUser<Coupon>("/api/admin/coupon/update", data)
|
return callByUser<Coupon>("/api/admin/coupon/update", data)
|
||||||
}
|
}
|
||||||
@@ -32,3 +38,21 @@ export async function deleteCoupon(id: number) {
|
|||||||
id,
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getReleaseCoupon(data: {
|
||||||
|
coupon_id: number
|
||||||
|
user_id: number
|
||||||
|
}) {
|
||||||
|
return callByUser<Coupon>("/api/admin/coupon/update/assign", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUserCoupon(data: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_id: number
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Coupon>>(
|
||||||
|
"/api/admin/coupon-user/page/of-user",
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
10
src/actions/env.ts
Normal file
10
src/actions/env.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
const NODE_ENV = process.env.NODE_ENV
|
||||||
|
|
||||||
|
export async function getNodeEnv() {
|
||||||
|
if (!NODE_ENV) {
|
||||||
|
toast.error(`接口请求错误:NODE_ENV为空`)
|
||||||
|
}
|
||||||
|
return NODE_ENV
|
||||||
|
}
|
||||||
@@ -22,3 +22,7 @@ export async function createGateway(data: {
|
|||||||
export async function updateGateway(data: { id: number; status: number }) {
|
export async function updateGateway(data: { id: number; status: number }) {
|
||||||
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
|
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clear(data: { proxy_id: number }) {
|
||||||
|
return callByUser<PageRecord>("/api/admin/channel/sync/clear-expired", data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { createContext, type ReactNode, useContext, useState } from "react"
|
import { createContext, type ReactNode, Suspense, useContext, useState } from "react"
|
||||||
import { twJoin } from "tailwind-merge"
|
import { twJoin } from "tailwind-merge"
|
||||||
import { Auth } from "@/components/auth"
|
import { Auth } from "@/components/auth"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
@@ -54,6 +54,7 @@ import {
|
|||||||
ScopeUserReadNotBind,
|
ScopeUserReadNotBind,
|
||||||
ScopeUserReadOne,
|
ScopeUserReadOne,
|
||||||
} from "@/lib/scopes"
|
} from "@/lib/scopes"
|
||||||
|
import Logo from "./logo"
|
||||||
|
|
||||||
// Navigation Context
|
// Navigation Context
|
||||||
interface NavigationContextType {
|
interface NavigationContextType {
|
||||||
@@ -255,7 +256,7 @@ const menuSections: { title: string; items: NavItemProps[] }[] = [
|
|||||||
href: "/gateway",
|
href: "/gateway",
|
||||||
icon: DoorClosedIcon,
|
icon: DoorClosedIcon,
|
||||||
label: "网关列表",
|
label: "网关列表",
|
||||||
requiredScope:ScopeProxyRead
|
requiredScope: ScopeProxyRead,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "/admin",
|
href: "/admin",
|
||||||
@@ -301,22 +302,13 @@ 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 h-full",
|
"bg-white border-r border-slate-200 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 p-4 shrink-0">
|
<Suspense><Logo collapsed={collapsed} /></Suspense>
|
||||||
{!collapsed ? (
|
|
||||||
<span className="text-xl font-bold tracking-wide text-foreground">
|
|
||||||
管理系统
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="text-xl font-bold mx-auto text-foreground">
|
|
||||||
<ComputerIcon />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{/* Navigation Menu */}
|
{/* Navigation Menu */}
|
||||||
<ScrollArea className="flex-1 py-3 overflow-hidden">
|
<ScrollArea className="flex-1 py-3 overflow-hidden">
|
||||||
<nav className="space-y-3">
|
<nav className="space-y-3">
|
||||||
29
src/app/(root)/_navigation/logo.tsx
Normal file
29
src/app/(root)/_navigation/logo.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
import { ComputerIcon } from "lucide-react"
|
||||||
|
import { getNodeEnv } from "@/actions/env"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
export default async function Logo(props: { collapsed: boolean }) {
|
||||||
|
const env = await getNodeEnv()
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
`h-16 flex items-center justify-between border-b px-4 shrink-0`,
|
||||||
|
env === "production" && "bg-amber-100",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{!props.collapsed ? (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||||
|
<ComputerIcon className="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<span className="text-xl font-bold tracking-wide">管理系统</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-full flex justify-center">
|
||||||
|
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ export default function BalancePage() {
|
|||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="phone"
|
name="phone"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -142,9 +142,7 @@ export default function BalancePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -157,7 +155,7 @@ export default function BalancePage() {
|
|||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -169,7 +167,7 @@ export default function BalancePage() {
|
|||||||
accessorFn: row => row.user?.phone || "",
|
accessorFn: row => row.user?.phone || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "账单号",
|
header: "账单编号",
|
||||||
accessorFn: row => row.bill?.bill_no || "",
|
accessorFn: row => row.bill?.bill_no || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export default function BalancePage() {
|
|||||||
<span className="ml-2 text-gray-600">用户会员号: {userPhone}</span>
|
<span className="ml-2 text-gray-600">用户会员号: {userPhone}</span>
|
||||||
</div>
|
</div>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="bill_no"
|
name="bill_no"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -141,9 +141,7 @@ export default function BalancePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -156,7 +154,7 @@ export default function BalancePage() {
|
|||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
|
|||||||
109
src/app/(root)/client/coupon/coupon.tsx
Normal file
109
src/app/(root)/client/coupon/coupon.tsx
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
"use client"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { getPagCoupon } from "@/actions/coupon"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
|
||||||
|
export function IssueCouponForUser(props: {
|
||||||
|
userId: number
|
||||||
|
userPhone: string
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const table = useDataTable<Coupon>((page, size) =>
|
||||||
|
getPagCoupon({ page, size }),
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleIssue = async (coupon: Coupon) => {
|
||||||
|
// try {
|
||||||
|
// const result = await issueCouponToUser({
|
||||||
|
// user_id: props.userId,
|
||||||
|
// coupon_id: coupon.id,
|
||||||
|
// coupon_name: coupon.name,
|
||||||
|
// })
|
||||||
|
// if (result.success) {
|
||||||
|
// toast.success(`成功发放「${coupon.name}」给用户 ${props.userPhone}`)
|
||||||
|
// props.onSuccess?.()
|
||||||
|
// setOpen(false)
|
||||||
|
// } else {
|
||||||
|
// toast.error(result.message || "发放失败")
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// const message = error instanceof Error ? error.message : "发放失败"
|
||||||
|
// toast.error(`发放优惠券失败: ${message}`)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onOpenChange={newOpen => {
|
||||||
|
setOpen(newOpen)
|
||||||
|
if (newOpen) {
|
||||||
|
table.refresh()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button>发放优惠券</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent
|
||||||
|
className="max-h-[85vh] overflow-y-auto"
|
||||||
|
style={{ width: "auto", minWidth: "800px", maxWidth: "90vw" }}
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>发放优惠券给 {props.userPhone}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DataTable<Coupon>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "优惠券名称", accessorKey: "name" },
|
||||||
|
{ header: "优惠券金额", accessorKey: "amount" },
|
||||||
|
{ header: "最低消费金额", accessorKey: "min_amount" },
|
||||||
|
{
|
||||||
|
header: "状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const status = row.original.status
|
||||||
|
if (status === 0) {
|
||||||
|
return <span className="text-yellow-600">禁用</span>
|
||||||
|
}
|
||||||
|
if (status === 1) {
|
||||||
|
return <span className="text-green-600">正常</span>
|
||||||
|
}
|
||||||
|
return <span>-</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Button size="sm" onClick={() => handleIssue(row.original)}>
|
||||||
|
发放
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost">取消</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
275
src/app/(root)/client/coupon/page.tsx
Normal file
275
src/app/(root)/client/coupon/page.tsx
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
"use client"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
|
import { Suspense, useState } from "react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { getUserCoupon } from "@/actions/coupon"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Page } from "@/components/page"
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
AlertDialogTrigger,
|
||||||
|
} from "@/components/ui/alert-dialog"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
|
||||||
|
export default function CouponPage() {
|
||||||
|
const router = useRouter()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const userId = searchParams.get("userId")
|
||||||
|
const userPhone = searchParams.get("phone")
|
||||||
|
|
||||||
|
const table = useDataTable<Coupon>((page, size) => {
|
||||||
|
return getUserCoupon({
|
||||||
|
user_id: Number(userId),
|
||||||
|
page,
|
||||||
|
size,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
console.log(table, "table")
|
||||||
|
|
||||||
|
const expireLabel = (coupon: Coupon) => {
|
||||||
|
switch (coupon.expire_type) {
|
||||||
|
case 0:
|
||||||
|
return "永久有效"
|
||||||
|
case 1:
|
||||||
|
return coupon.expire_at
|
||||||
|
? format(new Date(coupon.expire_at), "yyyy-MM-dd")
|
||||||
|
: ""
|
||||||
|
case 2:
|
||||||
|
return coupon.expire_in ? `发放后${coupon.expire_in}天` : ""
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Page>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Button onClick={() => router.back()} className="gap-2">
|
||||||
|
返回上一级
|
||||||
|
</Button>
|
||||||
|
<span className="text-gray-600">用户手机号: {userPhone}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Coupon>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "优惠券名称", accessorKey: "name" },
|
||||||
|
{ header: "券码", accessorKey: "code" },
|
||||||
|
{ header: "金额", accessorKey: "amount" },
|
||||||
|
{ header: "最低消费", accessorKey: "min_amount" },
|
||||||
|
{
|
||||||
|
header: "状态",
|
||||||
|
accessorKey: "coupon_status",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "过期信息",
|
||||||
|
id: "expire",
|
||||||
|
cell: ({ row }) => expireLabel(row.original),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "发放时间",
|
||||||
|
accessorKey: "issued_at",
|
||||||
|
// cell: ({ row }) =>
|
||||||
|
// format(new Date(row.original.issued_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "备注",
|
||||||
|
accessorKey: "remark",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-gray-500">
|
||||||
|
{row.original.remark || "-"}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<UpdateStatusDialog
|
||||||
|
coupon={row.original}
|
||||||
|
userId={Number(userId)}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<RevokeDialog
|
||||||
|
coupon={row.original}
|
||||||
|
userId={Number(userId)}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateStatusDialog({
|
||||||
|
coupon,
|
||||||
|
userId,
|
||||||
|
onSuccess,
|
||||||
|
}: {
|
||||||
|
coupon: Coupon
|
||||||
|
userId: number
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [selectedStatus, setSelectedStatus] =
|
||||||
|
useState(
|
||||||
|
// String(coupon.coupon_status),
|
||||||
|
)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
// setLoading(true)
|
||||||
|
// try {
|
||||||
|
// const status = Number(selectedStatus)
|
||||||
|
// const result = await updateUserCouponStatus({
|
||||||
|
// user_id: userId,
|
||||||
|
// coupon_id: coupon.id,
|
||||||
|
// coupon_status: status,
|
||||||
|
// })
|
||||||
|
// if (result.success) {
|
||||||
|
// toast.success("状态更新成功")
|
||||||
|
// onSuccess?.()
|
||||||
|
// setOpen(false)
|
||||||
|
// } else {
|
||||||
|
// toast.error(result.message || "更新失败")
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// const message = error instanceof Error ? error.message : "更新失败"
|
||||||
|
// toast.error(`状态更新失败: ${message}`)
|
||||||
|
// } finally {
|
||||||
|
// setLoading(false)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button size="sm" variant="secondary">
|
||||||
|
修改状态
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>修改优惠券状态</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="py-4">
|
||||||
|
<p className="text-sm text-gray-600 mb-3">
|
||||||
|
优惠券: {coupon.name} ({coupon.code})
|
||||||
|
</p>
|
||||||
|
<Select value={selectedStatus}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="1">未使用</SelectItem>
|
||||||
|
<SelectItem value="2">已使用</SelectItem>
|
||||||
|
<SelectItem value="3">已过期</SelectItem>
|
||||||
|
<SelectItem value="0">已撤销</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost">取消</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<Button onClick={handleConfirm} disabled={loading}>
|
||||||
|
确认
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function RevokeDialog({
|
||||||
|
coupon,
|
||||||
|
userId,
|
||||||
|
onSuccess,
|
||||||
|
}: {
|
||||||
|
coupon: Coupon
|
||||||
|
userId: number
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
// setLoading(true)
|
||||||
|
// try {
|
||||||
|
// const result = await revokeUserCoupon({
|
||||||
|
// user_id: userId,
|
||||||
|
// coupon_id: coupon.id,
|
||||||
|
// })
|
||||||
|
// if (result.success) {
|
||||||
|
// toast.success("撤销成功")
|
||||||
|
// onSuccess?.()
|
||||||
|
// } else {
|
||||||
|
// toast.error(result.message || "撤销失败")
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// const message = error instanceof Error ? error.message : "撤销失败"
|
||||||
|
// toast.error(`撤销失败: ${message}`)
|
||||||
|
// } finally {
|
||||||
|
// setLoading(false)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button size="sm" variant="destructive" disabled={loading}>
|
||||||
|
撤销
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent size="sm">
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>确认撤销</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
确定要撤销「{coupon.name}」({coupon.code})
|
||||||
|
吗?此操作将标记优惠券为已撤销状态。
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction variant="destructive" onClick={handleConfirm}>
|
||||||
|
撤销
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -19,12 +19,7 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import {
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
Field,
|
|
||||||
FieldError,
|
|
||||||
FieldGroup,
|
|
||||||
FieldLabel,
|
|
||||||
} from "@/components/ui/field"
|
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import {
|
import {
|
||||||
ScopeBalanceActivityReadOfUser,
|
ScopeBalanceActivityReadOfUser,
|
||||||
@@ -111,15 +106,12 @@ export default function UserQueryPage() {
|
|||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="phone"
|
name="phone"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
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>
|
||||||
@@ -131,19 +123,13 @@ export default function UserQueryPage() {
|
|||||||
name="name"
|
name="name"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
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>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Auth scope={ScopeUserWrite}>
|
<Auth scope={ScopeUserWrite}>
|
||||||
<AddUserDialog onSuccess={refreshTable} />
|
<AddUserDialog onSuccess={refreshTable} />
|
||||||
</Auth>
|
</Auth>
|
||||||
@@ -151,7 +137,7 @@ export default function UserQueryPage() {
|
|||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -263,7 +249,7 @@ export default function UserQueryPage() {
|
|||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/client/trade?userId=${row.original.id}`,
|
`/client/trade?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -274,7 +260,7 @@ export default function UserQueryPage() {
|
|||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/client/billing?userId=${row.original.id}`,
|
`/client/billing?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -285,7 +271,7 @@ export default function UserQueryPage() {
|
|||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/client/resources?userId=${row.original.id}`,
|
`/client/resources?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -296,7 +282,7 @@ export default function UserQueryPage() {
|
|||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/client/batch?userId=${row.original.id}`,
|
`/client/batch?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -307,7 +293,7 @@ export default function UserQueryPage() {
|
|||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/client/channel?userId=${row.original.id}`,
|
`/client/channel?userId=${row.original.id}&phone=${row.original.phone}`,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export default function TradePage() {
|
|||||||
<span className="ml-2 text-gray-600">用户会员号: {userPhone}</span>
|
<span className="ml-2 text-gray-600">用户会员号: {userPhone}</span>
|
||||||
</div>
|
</div>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="inner_no"
|
name="inner_no"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -137,7 +137,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="method"
|
name="method"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -161,7 +160,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="platform"
|
name="platform"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -182,7 +180,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="status"
|
name="status"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -204,7 +201,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="created_at_start"
|
name="created_at_start"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -219,7 +215,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="created_at_end"
|
name="created_at_end"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -234,9 +229,6 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -249,7 +241,7 @@ export default function TradePage() {
|
|||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -330,7 +322,7 @@ export default function TradePage() {
|
|||||||
? "电脑网站"
|
? "电脑网站"
|
||||||
: platform === 2
|
: platform === 2
|
||||||
? "手机网站"
|
? "手机网站"
|
||||||
: "-"
|
: ""
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,13 +17,49 @@ import {
|
|||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
import { FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"
|
import { FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
code: z.string().min(1, "请输入优惠券名称"),
|
name: z.string().min(1, "请输入优惠券名称"),
|
||||||
amount: z.string().min(1, "请输入优惠券金额"),
|
amount: z.string()
|
||||||
remark: z.string().optional(),
|
.min(1, "请输入优惠券金额")
|
||||||
min_amount: z.string().optional(),
|
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
|
||||||
|
.refine(val => Number(val) > 0, "优惠券金额必须大于0"),
|
||||||
|
count: z.string()
|
||||||
|
.min(1, "请输入优惠券数量")
|
||||||
|
.regex(/^\d+$/, "请输入正整数")
|
||||||
|
.refine(val => Number(val) >= 1, "优惠券数量至少为1"),
|
||||||
|
min_amount: z.string()
|
||||||
|
.min(1, "请输入最低消费金额")
|
||||||
|
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
|
||||||
|
.refine(val => Number(val) >= 0, "最低消费金额不能为负数"),
|
||||||
expire_at: z.string().optional(),
|
expire_at: z.string().optional(),
|
||||||
|
expire_type: z.string().min(1, "请选择过期类型"),
|
||||||
|
expire_in: z.string().optional(),
|
||||||
|
status:z.string().optional()
|
||||||
|
}).superRefine((data, ctx) => {
|
||||||
|
const expireType = Number(data.expire_type);
|
||||||
|
if (!data.expire_type) return;
|
||||||
|
if (expireType === 1 && !data.expire_at) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "请选择过期时间",
|
||||||
|
path: ["expire_at"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (expireType === 2 && !data.expire_in) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "请输入过期时长天数",
|
||||||
|
path: ["expire_in"]
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export function CreateDiscount(props: { onSuccess?: () => void }) {
|
export function CreateDiscount(props: { onSuccess?: () => void }) {
|
||||||
@@ -32,25 +68,33 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
code: "",
|
name: "",
|
||||||
remark: "",
|
count: "",
|
||||||
amount: "0",
|
amount: "",
|
||||||
min_amount: "0",
|
min_amount: "",
|
||||||
expire_at: "",
|
expire_at: "",
|
||||||
|
expire_in: "",
|
||||||
|
expire_type: "",
|
||||||
|
status: "0",
|
||||||
},
|
},
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
})
|
})
|
||||||
|
|
||||||
const { control, handleSubmit, reset } = form
|
const { control, handleSubmit, reset, watch } = form
|
||||||
|
const watchExpireType = watch("expire_type")
|
||||||
|
|
||||||
const onSubmit = async (data: z.infer<typeof schema>) => {
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
try {
|
try {
|
||||||
|
const expireType = Number(data.expire_type)
|
||||||
const payload = {
|
const payload = {
|
||||||
code: data.code,
|
name: data.name,
|
||||||
amount: Number(data.amount),
|
amount: Number(data.amount),
|
||||||
remark: data?.remark,
|
count: Number(data?.count),
|
||||||
|
status:Number(data.status),
|
||||||
min_amount: Number(data?.min_amount),
|
min_amount: Number(data?.min_amount),
|
||||||
expire_at: data?.expire_at ? new Date(data.expire_at) : undefined,
|
expire_at: data?.expire_at ? new Date(data.expire_at) : undefined,
|
||||||
|
expire_in: expireType === 2 ? Number(data.expire_in) : undefined,
|
||||||
|
expire_type: expireType,
|
||||||
}
|
}
|
||||||
const resp = await createCoupon(payload)
|
const resp = await createCoupon(payload)
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
@@ -93,10 +137,10 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="code"
|
name="name"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">名称:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券名称:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -107,10 +151,10 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="remark"
|
name="count"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">备注:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券数量:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -124,20 +168,9 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
name="amount"
|
name="amount"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">金额:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券金额:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input {...field} />
|
||||||
type="number"
|
|
||||||
min={0}
|
|
||||||
step={5}
|
|
||||||
{...field}
|
|
||||||
onChange={e => {
|
|
||||||
const value = e.target.value
|
|
||||||
if (value === "" || parseFloat(value) >= 0) {
|
|
||||||
field.onChange(value)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -148,43 +181,97 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
name="min_amount"
|
name="min_amount"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">最低消费:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">最低消费金额:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input {...field} />
|
||||||
type="number"
|
|
||||||
min={0}
|
|
||||||
step={5}
|
|
||||||
{...field}
|
|
||||||
onChange={e => {
|
|
||||||
const value = e.target.value
|
|
||||||
if (value === "" || parseFloat(value) >= 0) {
|
|
||||||
field.onChange(value)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="expire_at"
|
name="status"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-30 pt-2">过期时间:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券状态:</FieldLabel>
|
||||||
<Input
|
|
||||||
type="date"
|
|
||||||
min={new Date().toISOString().split("T")[0]}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="0">禁用</SelectItem>
|
||||||
|
<SelectItem value="1">正常</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_type"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期类型:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择过期类型" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="0">不过期</SelectItem>
|
||||||
|
<SelectItem value="1">固定日期</SelectItem>
|
||||||
|
<SelectItem value="2">相对日期</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{watchExpireType === "1" && (
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_at"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期时间:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
min={new Date().toISOString().split("T")[0]}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{watchExpireType === "2" && (
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_in"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期时长(天):</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
placeholder="请输入过期天数"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { format } from "date-fns"
|
|||||||
import { Suspense, useState } from "react"
|
import { Suspense, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { deleteCoupon, getPagCoupon } from "@/actions/coupon"
|
import { deleteCoupon, getPagCoupon } from "@/actions/coupon"
|
||||||
|
import { Auth } from "@/components/auth"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Page } from "@/components/page"
|
import { Page } from "@/components/page"
|
||||||
import {
|
import {
|
||||||
@@ -17,8 +18,10 @@ import {
|
|||||||
AlertDialogTrigger,
|
AlertDialogTrigger,
|
||||||
} from "@/components/ui/alert-dialog"
|
} from "@/components/ui/alert-dialog"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ScopeCouponWriteAssign } from "@/lib/scopes"
|
||||||
import type { Coupon } from "@/models/coupon"
|
import type { Coupon } from "@/models/coupon"
|
||||||
import { CreateDiscount } from "./create"
|
import { CreateDiscount } from "./create"
|
||||||
|
import { ReleaseCoupon } from "./release"
|
||||||
import { UpdateCoupon } from "./update"
|
import { UpdateCoupon } from "./update"
|
||||||
|
|
||||||
export default function CouponPage() {
|
export default function CouponPage() {
|
||||||
@@ -36,30 +39,59 @@ export default function CouponPage() {
|
|||||||
<DataTable<Coupon>
|
<DataTable<Coupon>
|
||||||
{...table}
|
{...table}
|
||||||
columns={[
|
columns={[
|
||||||
{ header: "所属用户", accessorKey: "user_id" },
|
{ header: "优惠券名称", accessorKey: "name" },
|
||||||
{ header: "代码", accessorKey: "code" },
|
{ header: "优惠券数量", accessorKey: "count" },
|
||||||
{ header: "备注", accessorKey: "remark" },
|
{ header: "优惠券金额", accessorKey: "amount" },
|
||||||
{ header: "金额", accessorKey: "amount" },
|
|
||||||
{ header: "最低消费金额", accessorKey: "min_amount" },
|
{ header: "最低消费金额", accessorKey: "min_amount" },
|
||||||
{
|
{
|
||||||
header: "状态",
|
header: "优惠券状态",
|
||||||
accessorKey: "status",
|
accessorKey: "status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const status = row.original.status
|
const status = row.original.status
|
||||||
if (status === 0) {
|
if (status === 0) {
|
||||||
return <span className="text-yellow-600">未使用</span>
|
return <span className="text-yellow-600">禁用</span>
|
||||||
}
|
}
|
||||||
if (status === 1) {
|
if (status === 1) {
|
||||||
return <span className="text-green-600">已使用</span>
|
return <span className="text-green-600">正常</span>
|
||||||
}
|
}
|
||||||
return <span>-</span>
|
return <span>-</span>
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
header: "过期类型",
|
||||||
|
accessorFn: row => {
|
||||||
|
switch (row.expire_type) {
|
||||||
|
case 0:
|
||||||
|
return "不过期"
|
||||||
|
case 1:
|
||||||
|
return "固定日期"
|
||||||
|
case 2:
|
||||||
|
return "相对日期"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "过期时长(天)",
|
||||||
|
accessorKey: "expire_in",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: "过期时间",
|
header: "过期时间",
|
||||||
accessorKey: "expire_at",
|
accessorKey: "expire_at",
|
||||||
cell: ({ row }) =>
|
cell: ({ row }) => {
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
const coupon = row.original
|
||||||
|
if (coupon.expire_type === 2 && coupon.expire_in) {
|
||||||
|
const expireDate = new Date(coupon.created_at)
|
||||||
|
expireDate.setDate(expireDate.getDate() + coupon.expire_in)
|
||||||
|
return format(expireDate, "yyyy-MM-dd HH:mm")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coupon.expire_type === 1 && coupon.expire_at) {
|
||||||
|
return format(new Date(coupon.expire_at), "yyyy-MM-dd HH:mm")
|
||||||
|
}
|
||||||
|
return <span>永久有效</span>
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "创建时间",
|
header: "创建时间",
|
||||||
@@ -67,12 +99,6 @@ export default function CouponPage() {
|
|||||||
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"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
header: "更新时间",
|
|
||||||
accessorKey: "updated_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
@@ -87,6 +113,12 @@ export default function CouponPage() {
|
|||||||
coupon={row.original}
|
coupon={row.original}
|
||||||
onSuccess={table.refresh}
|
onSuccess={table.refresh}
|
||||||
/>
|
/>
|
||||||
|
<Auth scope={ScopeCouponWriteAssign}>
|
||||||
|
<ReleaseCoupon
|
||||||
|
coupon={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -135,7 +167,7 @@ function DeleteCoupon({
|
|||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>确认删除</AlertDialogTitle>
|
<AlertDialogTitle>确认删除</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
确定要删除折扣「{coupon.code}」吗?此操作不可撤销。
|
确定要删除折扣「{coupon.name}」吗?此操作不可撤销。
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
|
|||||||
349
src/app/(root)/coupon/release.tsx
Normal file
349
src/app/(root)/coupon/release.tsx
Normal file
@@ -0,0 +1,349 @@
|
|||||||
|
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 { toast } from "sonner"
|
||||||
|
import z from "zod"
|
||||||
|
import { getReleaseCoupon } from "@/actions/coupon"
|
||||||
|
import { getPageUser } from "@/actions/user"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
|
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 function ReleaseCoupon(props: {
|
||||||
|
coupon: Coupon
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [userList, setUserList] = useState<User[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [currentFilters, setCurrentFilters] = useState<UserQueryParams>({})
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
phone: "",
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchUsers = useCallback(async (filters: UserQueryParams = {}) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
setOpen(true)
|
||||||
|
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 handleReset = useCallback(() => {
|
||||||
|
reset()
|
||||||
|
setCurrentFilters({})
|
||||||
|
setUserList([])
|
||||||
|
}, [reset])
|
||||||
|
|
||||||
|
const handleIssueCoupon = useCallback(
|
||||||
|
async (users: User[], coupon: Coupon) => {
|
||||||
|
console.log(coupon, "couponcouponcoupon")
|
||||||
|
|
||||||
|
const targetUser = users[0]
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.id) {
|
||||||
|
toast.error("用户信息无效")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!coupon || !coupon.id) {
|
||||||
|
toast.error("优惠券信息无效")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (coupon.status !== 1) {
|
||||||
|
toast.error("优惠券不可用,请检查优惠券状态")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await getReleaseCoupon({
|
||||||
|
coupon_id: coupon.id,
|
||||||
|
user_id: targetUser.id,
|
||||||
|
})
|
||||||
|
console.log({
|
||||||
|
coupon_id: coupon.id,
|
||||||
|
user_id: targetUser.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(result, "resultresultresultresultresult")
|
||||||
|
if (result.success) {
|
||||||
|
toast.success(
|
||||||
|
`成功发放优惠券给用户 ${targetUser.phone || targetUser.username}`,
|
||||||
|
)
|
||||||
|
setOpen(false)
|
||||||
|
handleReset()
|
||||||
|
props.onSuccess?.()
|
||||||
|
} else {
|
||||||
|
toast.error("发放失败,请稍后重试")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "发放失败"
|
||||||
|
toast.error(`发放优惠券失败: ${message}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[props.onSuccess, handleReset],
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onOpenChange={newOpen => {
|
||||||
|
setOpen(newOpen)
|
||||||
|
if (!newOpen) {
|
||||||
|
handleReset()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button size="sm" variant="secondary">
|
||||||
|
发放
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
|
||||||
|
<DialogContent
|
||||||
|
className="max-h-[85vh] overflow-y-auto"
|
||||||
|
style={{ width: "auto", minWidth: "800px", maxWidth: "90vw" }}
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>发放优惠券</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={onFilter} className="bg-card rounded-lg">
|
||||||
|
<div className="flex items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
|
<FieldLabel>手机号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入手机号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Button type="button" variant="outline" onClick={handleReset}>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
<Button type="submit">搜索</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<Suspense fallback={<div className="py-8 text-center">加载中...</div>}>
|
||||||
|
{loading ? (
|
||||||
|
<div className="py-8 text-center">加载中...</div>
|
||||||
|
) : userList.length === 0 ? (
|
||||||
|
<div className="py-8 text-center text-gray-500">暂无用户数据</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4 max-h-[60vh] overflow-y-auto pr-1">
|
||||||
|
{userList.map(user => (
|
||||||
|
<div
|
||||||
|
key={user.id}
|
||||||
|
className="border rounded-lg overflow-hidden hover:shadow-md transition-shadow"
|
||||||
|
>
|
||||||
|
<div className="bg-gray-50 px-4 py-3 border-b flex items-center justify-between flex-wrap gap-2">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span className="font-medium text-base">
|
||||||
|
{user.phone || "未绑定手机"}
|
||||||
|
</span>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Badge
|
||||||
|
variant={user.id_type === 1 ? "default" : "secondary"}
|
||||||
|
className={
|
||||||
|
user.id_type === 1
|
||||||
|
? "bg-green-100 text-green-700 hover:bg-green-100"
|
||||||
|
: "bg-gray-100 text-gray-600 hover:bg-gray-100"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{user.id_type === 1 ? "✓ 已认证" : "○ 未认证"}
|
||||||
|
</Badge>
|
||||||
|
<Badge
|
||||||
|
variant={
|
||||||
|
user.status === 1 ? "default" : "destructive"
|
||||||
|
}
|
||||||
|
className={
|
||||||
|
user.status === 1
|
||||||
|
? "bg-green-100 text-green-700 hover:bg-green-100"
|
||||||
|
: "bg-red-100 text-red-700 hover:bg-red-100"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{user.status === 1 ? "正常" : "禁用"}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-sm text-gray-500">
|
||||||
|
余额:
|
||||||
|
<span
|
||||||
|
className={`ml-1 font-semibold ${
|
||||||
|
Number(user.balance) > 0
|
||||||
|
? "text-green-600"
|
||||||
|
: "text-orange-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
¥{(Number(user.balance) || 0).toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-4">
|
||||||
|
<div className="grid grid-cols-3 gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
姓名:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.name || ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
账号:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.username || ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
客户经理:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.admin?.name || ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
客户来源:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{(() => {
|
||||||
|
const sourceMap: Record<number, string> = {
|
||||||
|
0: "官网注册",
|
||||||
|
1: "管理员添加",
|
||||||
|
2: "代理商注册",
|
||||||
|
3: "代理商添加",
|
||||||
|
}
|
||||||
|
return sourceMap[user.source] ?? "官网注册"
|
||||||
|
})()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
联系方式:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.contact_wechat || ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
创建时间:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.created_at
|
||||||
|
? format(new Date(user.created_at), "yyyy-MM-dd")
|
||||||
|
: ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
最后登录:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.last_login
|
||||||
|
? format(
|
||||||
|
new Date(user.last_login),
|
||||||
|
"yyyy-MM-dd HH:mm",
|
||||||
|
)
|
||||||
|
: "-"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">
|
||||||
|
<span className="text-gray-500 w-20 inline-block">
|
||||||
|
登录IP:
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{user.last_login_ip || "-"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Suspense>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost" onClick={handleReset}>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleIssueCoupon(userList, props.coupon)}
|
||||||
|
disabled={!userList || userList.length === 0}
|
||||||
|
>
|
||||||
|
发放优惠券
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -26,12 +26,40 @@ import {
|
|||||||
import type { Coupon } from "@/models/coupon"
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
code: z.string().min(1, "请输入优惠券名称"),
|
name: z.string().min(1, "请输入优惠券名称"),
|
||||||
amount: z.string().min(1, "请输入优惠券金额"),
|
amount: z.string()
|
||||||
remark: z.string().optional(),
|
.min(1, "请输入优惠券金额")
|
||||||
min_amount: z.string().optional(),
|
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
|
||||||
|
.refine(val => Number(val) > 0, "优惠券金额必须大于0"),
|
||||||
|
count: z.string()
|
||||||
|
.min(1, "请输入优惠券数量")
|
||||||
|
.regex(/^\d+$/, "请输入正整数")
|
||||||
|
.refine(val => Number(val) >= 1, "优惠券数量至少为1"),
|
||||||
|
min_amount: z.string()
|
||||||
|
.min(1, "请输入最低消费金额")
|
||||||
|
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
|
||||||
|
.refine(val => Number(val) >= 0, "最低消费金额不能为负数"),
|
||||||
expire_at: z.string().optional(),
|
expire_at: z.string().optional(),
|
||||||
status: z.string().optional(),
|
expire_type: z.string().min(1, "请选择过期类型"),
|
||||||
|
expire_in: z.string().optional(),
|
||||||
|
status:z.string().optional()
|
||||||
|
}).superRefine((data, ctx) => {
|
||||||
|
const expireType = Number(data.expire_type);
|
||||||
|
if (!data.expire_type) return;
|
||||||
|
if (expireType === 1 && !data.expire_at) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "请选择过期时间",
|
||||||
|
path: ["expire_at"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (expireType === 2 && !data.expire_in) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "请输入过期时长天数",
|
||||||
|
path: ["expire_in"]
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export function UpdateCoupon(props: {
|
export function UpdateCoupon(props: {
|
||||||
@@ -43,30 +71,34 @@ export function UpdateCoupon(props: {
|
|||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
code: props.coupon.code || "",
|
name: props.coupon.name,
|
||||||
remark: props.coupon.remark || "",
|
amount: String(props.coupon.amount),
|
||||||
amount: String(props.coupon.amount || 0),
|
min_amount: String(props.coupon.min_amount),
|
||||||
min_amount: String(props.coupon.min_amount || 0),
|
expire_at: props?.coupon.expire_at
|
||||||
expire_at: props.coupon.expire_at
|
? new Date(props?.coupon.expire_at).toISOString().split("T")[0]
|
||||||
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
|
|
||||||
: "",
|
: "",
|
||||||
status: String(props.coupon.status || "0"),
|
status: String(props.coupon.status),
|
||||||
|
count: String(props.coupon.count),
|
||||||
|
expire_in: String(props?.coupon.expire_in),
|
||||||
},
|
},
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
})
|
})
|
||||||
|
|
||||||
const { control, handleSubmit, reset } = form
|
const { control, handleSubmit, reset, watch } = form
|
||||||
|
const watchExpireType = watch("expire_type")
|
||||||
const onSubmit = async (data: z.infer<typeof schema>) => {
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
try {
|
try {
|
||||||
|
const expireType = Number(data.expire_type)
|
||||||
const payload = {
|
const payload = {
|
||||||
id: props.coupon.id,
|
id: props.coupon.id,
|
||||||
code: data.code,
|
name: data.name,
|
||||||
amount: Number(data.amount),
|
amount: Number(data.amount),
|
||||||
remark: data.remark,
|
|
||||||
min_amount: Number(data.min_amount),
|
min_amount: Number(data.min_amount),
|
||||||
expire_at: data.expire_at ? new Date(data.expire_at) : undefined,
|
count: Number(data.count),
|
||||||
status: Number(data.status),
|
status: Number(data.status),
|
||||||
|
expire_type: expireType,
|
||||||
|
expire_at: data.expire_at ? new Date(data.expire_at) : undefined,
|
||||||
|
expire_in: expireType === 2 ? Number(data.expire_in) : undefined,
|
||||||
}
|
}
|
||||||
const resp = await updateCoupon(payload)
|
const resp = await updateCoupon(payload)
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
@@ -85,14 +117,16 @@ export function UpdateCoupon(props: {
|
|||||||
const handleOpenChange = (value: boolean) => {
|
const handleOpenChange = (value: boolean) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
reset({
|
reset({
|
||||||
code: props.coupon.code || "",
|
name: props.coupon.name,
|
||||||
remark: props.coupon.remark || "",
|
count: String(props.coupon.count),
|
||||||
amount: String(props.coupon.amount || 0),
|
amount: String(props.coupon.amount ),
|
||||||
min_amount: String(props.coupon.min_amount || 0),
|
min_amount: String(props.coupon.min_amount),
|
||||||
expire_at: props.coupon.expire_at
|
expire_at: props.coupon.expire_at
|
||||||
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
|
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
|
||||||
: "",
|
: "",
|
||||||
status: String(props.coupon.status || "0"),
|
status: String(props.coupon.status),
|
||||||
|
expire_type: String(props.coupon.expire_type),
|
||||||
|
expire_in: String(props.coupon.expire_in),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
setOpen(value)
|
setOpen(value)
|
||||||
@@ -115,10 +149,10 @@ export function UpdateCoupon(props: {
|
|||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="code"
|
name="name"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">名称:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券名称:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -129,10 +163,10 @@ export function UpdateCoupon(props: {
|
|||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="remark"
|
name="count"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">备注:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券数量:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -146,20 +180,9 @@ export function UpdateCoupon(props: {
|
|||||||
name="amount"
|
name="amount"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">金额:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券金额:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input {...field} />
|
||||||
type="number"
|
|
||||||
min={0}
|
|
||||||
step={5}
|
|
||||||
{...field}
|
|
||||||
onChange={e => {
|
|
||||||
const value = e.target.value
|
|
||||||
if (value === "" || parseFloat(value) >= 0) {
|
|
||||||
field.onChange(value)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -171,58 +194,28 @@ export function UpdateCoupon(props: {
|
|||||||
name="min_amount"
|
name="min_amount"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">最低消费:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">最低消费金额:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input {...field} />
|
||||||
type="number"
|
|
||||||
min={0}
|
|
||||||
step={5}
|
|
||||||
{...field}
|
|
||||||
onChange={e => {
|
|
||||||
const value = e.target.value
|
|
||||||
if (value === "" || parseFloat(value) >= 0) {
|
|
||||||
field.onChange(value)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="expire_at"
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<div className="flex items-start gap-4">
|
|
||||||
<FieldLabel className="w-28 pt-2">过期时间:</FieldLabel>
|
|
||||||
<div className="flex-1">
|
|
||||||
<Input
|
|
||||||
type="date"
|
|
||||||
min={new Date().toISOString().split("T")[0]}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="status"
|
name="status"
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
<FieldLabel className="w-28 pt-2">状态:</FieldLabel>
|
<FieldLabel className="w-28 pt-2">优惠券状态:</FieldLabel>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Select value={field.value} onValueChange={field.onChange}>
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="请选择状态" />
|
<SelectValue placeholder="请选择状态" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="0">未使用</SelectItem>
|
<SelectItem value="0">禁用</SelectItem>
|
||||||
<SelectItem value="1">已使用</SelectItem>
|
<SelectItem value="1">正常</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -230,6 +223,68 @@ export function UpdateCoupon(props: {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_type"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期类型:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择过期类型" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="0">不过期</SelectItem>
|
||||||
|
<SelectItem value="1">固定日期</SelectItem>
|
||||||
|
<SelectItem value="2">相对日期</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{watchExpireType === "1" && (
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_at"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期时间:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
min={new Date().toISOString().split("T")[0]}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{watchExpireType === "2" && (
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_in"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期时长(天):</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
placeholder="请输入过期天数"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,7 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import {
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
Field,
|
|
||||||
FieldError,
|
|
||||||
FieldGroup,
|
|
||||||
FieldLabel,
|
|
||||||
} from "@/components/ui/field"
|
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
@@ -37,6 +32,7 @@ import {
|
|||||||
ScopeBatchReadOfUser,
|
ScopeBatchReadOfUser,
|
||||||
ScopeBillReadOfUser,
|
ScopeBillReadOfUser,
|
||||||
ScopeChannelReadOfUser,
|
ScopeChannelReadOfUser,
|
||||||
|
ScopeCouponWriteAssign,
|
||||||
ScopeResourceRead,
|
ScopeResourceRead,
|
||||||
ScopeTradeReadOfUser,
|
ScopeTradeReadOfUser,
|
||||||
ScopeUserWrite,
|
ScopeUserWrite,
|
||||||
@@ -126,15 +122,12 @@ export default function CustPage() {
|
|||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="account"
|
name="account"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-80 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
className="w-80 flex-none"
|
|
||||||
>
|
|
||||||
<FieldLabel>账号/手机号/邮箱</FieldLabel>
|
<FieldLabel>账号/手机号/邮箱</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
|
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -146,10 +139,7 @@ export default function CustPage() {
|
|||||||
name="name"
|
name="name"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
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>
|
||||||
@@ -203,10 +193,7 @@ export default function CustPage() {
|
|||||||
name="created_at_start"
|
name="created_at_start"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
className="w-40 flex-none"
|
|
||||||
>
|
|
||||||
<FieldLabel>开始时间</FieldLabel>
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
<Input type="date" {...field} />
|
<Input type="date" {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
@@ -218,19 +205,13 @@ export default function CustPage() {
|
|||||||
name="created_at_end"
|
name="created_at_end"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field
|
<Field data-invalid={fieldState.invalid} className="w-40 flex">
|
||||||
data-invalid={fieldState.invalid}
|
|
||||||
className="w-40 flex-none"
|
|
||||||
>
|
|
||||||
<FieldLabel>结束时间</FieldLabel>
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
<Input type="date" {...field} />
|
<Input type="date" {...field} />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Auth scope={ScopeUserWrite}>
|
<Auth scope={ScopeUserWrite}>
|
||||||
<AddUserDialog onSuccess={refreshTable} />
|
<AddUserDialog onSuccess={refreshTable} />
|
||||||
</Auth>
|
</Auth>
|
||||||
@@ -246,7 +227,7 @@ export default function CustPage() {
|
|||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -462,6 +443,17 @@ export default function CustPage() {
|
|||||||
余额明细
|
余额明细
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Auth>
|
</Auth>
|
||||||
|
<Auth scope={ScopeCouponWriteAssign}>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() =>
|
||||||
|
router.push(
|
||||||
|
`/client/coupon?userId=${user.id}&phone=${user.phone}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
优惠券
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</Auth>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { Suspense, useCallback, useState } from "react"
|
import { Suspense, useCallback, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { getGatewayPage, updateGateway } from "@/actions/gateway"
|
import { clear, getGatewayPage, updateGateway } from "@/actions/gateway"
|
||||||
import { Auth } from "@/components/auth"
|
import { Auth } from "@/components/auth"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Page } from "@/components/page"
|
import { Page } from "@/components/page"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { ScopeProxyWrite } from "@/lib/scopes"
|
import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes"
|
||||||
import type { Gateway } from "@/models/gateway"
|
import type { Gateway } from "@/models/gateway"
|
||||||
import CreatePage from "./create"
|
import CreatePage from "./create"
|
||||||
|
|
||||||
@@ -41,15 +41,38 @@ export default function GatewayPage() {
|
|||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearExpired = async (val: Gateway) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await clear({
|
||||||
|
proxy_id: val.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
const count =
|
||||||
|
result.data && "count" in result.data ? result.data.count : 0
|
||||||
|
toast.success(`清理过期连接成功,共 ${count} 条`)
|
||||||
|
} else {
|
||||||
|
toast.error(result.message || "清理过期连接失败,请稍后重试一下~")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`清理过期连接失败: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<Auth scope={ScopeProxyWrite}>
|
<div className="flex justify-between items-stretch">
|
||||||
<div className="flex justify-between items-stretch">
|
<div className="flex gap-3">
|
||||||
<div className="flex gap-3">
|
<Auth scope={ScopeProxyWrite}>
|
||||||
<CreatePage onSuccess={table.refresh} />
|
<CreatePage onSuccess={table.refresh} />
|
||||||
</div>
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
</Auth>
|
</div>
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<DataTable<Gateway>
|
<DataTable<Gateway>
|
||||||
{...table}
|
{...table}
|
||||||
@@ -101,6 +124,11 @@ export default function GatewayPage() {
|
|||||||
>
|
>
|
||||||
{row.original.status === 0 ? "启用" : "停用"}
|
{row.original.status === 0 ? "启用" : "停用"}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Auth scope={ScopeChannelWriteClearExpired}>
|
||||||
|
<Button onClick={() => clearExpired(row.original)}>
|
||||||
|
清理过期连接
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { type ReactNode, Suspense } from "react"
|
import { type ReactNode, Suspense } from "react"
|
||||||
import { getProfile } from "@/actions/auth"
|
import { getProfile } from "@/actions/auth"
|
||||||
|
import Navigation from "@/app/(root)/_navigation"
|
||||||
import Appbar from "@/app/(root)/appbar"
|
import Appbar from "@/app/(root)/appbar"
|
||||||
import Navigation from "@/app/(root)/navigation"
|
|
||||||
import SetScopes from "./scopes"
|
import SetScopes from "./scopes"
|
||||||
|
|
||||||
export type RootLayoutProps = {
|
export type RootLayoutProps = {
|
||||||
|
|||||||
@@ -115,14 +115,14 @@ export default function TradePage() {
|
|||||||
<Page>
|
<Page>
|
||||||
{/* 筛选表单 */}
|
{/* 筛选表单 */}
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="user_phone"
|
name="user_phone"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<FieldLabel>会员号</FieldLabel>
|
<FieldLabel>会员号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入会员号" />
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
@@ -137,7 +137,7 @@ export default function TradePage() {
|
|||||||
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"
|
||||||
>
|
>
|
||||||
<FieldLabel>订单号</FieldLabel>
|
<FieldLabel>订单号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入订单号" />
|
<Input {...field} placeholder="请输入订单号" />
|
||||||
@@ -219,7 +219,7 @@ export default function TradePage() {
|
|||||||
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"
|
||||||
>
|
>
|
||||||
<FieldLabel>开始时间</FieldLabel>
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
<Input type="date" {...field} />
|
<Input type="date" {...field} />
|
||||||
@@ -234,7 +234,7 @@ export default function TradePage() {
|
|||||||
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"
|
||||||
>
|
>
|
||||||
<FieldLabel>结束时间</FieldLabel>
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
<Input type="date" {...field} />
|
<Input type="date" {...field} />
|
||||||
@@ -242,9 +242,7 @@ export default function TradePage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -257,7 +255,7 @@ export default function TradePage() {
|
|||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { Button } from "@/components/ui/button"
|
|||||||
import {
|
import {
|
||||||
Field,
|
Field,
|
||||||
FieldError,
|
FieldError,
|
||||||
FieldGroup,
|
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
} from "@/components/ui/field"
|
} from "@/components/ui/field"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
@@ -63,14 +62,14 @@ export default function UserPage() {
|
|||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
<form onSubmit={onFilter} className="bg-card p-4 rounded-lg">
|
||||||
<div className="flex flex-wrap items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<Controller
|
<Controller
|
||||||
name="phone"
|
name="phone"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<FieldLabel>手机号</FieldLabel>
|
<FieldLabel>手机号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入手机号" />
|
<Input {...field} placeholder="请输入手机号" />
|
||||||
@@ -78,9 +77,7 @@ export default function UserPage() {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
|
||||||
<Button type="submit">搜索</Button>
|
<Button type="submit">搜索</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -89,11 +86,12 @@ export default function UserPage() {
|
|||||||
reset()
|
reset()
|
||||||
setFilters({})
|
setFilters({})
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
</Button>
|
</Button>
|
||||||
</FieldGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export const ScopeUserWriteBind = "user:write:bind" // 用户认领
|
|||||||
export const ScopeCoupon = "coupon"
|
export const ScopeCoupon = "coupon"
|
||||||
export const ScopeCouponRead = "coupon:read" // 读取优惠券列表
|
export const ScopeCouponRead = "coupon:read" // 读取优惠券列表
|
||||||
export const ScopeCouponWrite = "coupon:write" // 写入优惠券
|
export const ScopeCouponWrite = "coupon:write" // 写入优惠券
|
||||||
|
export const ScopeCouponWriteAssign = "coupon:write:assign" // 发放优惠券
|
||||||
|
|
||||||
// 批次
|
// 批次
|
||||||
export const ScopeBatch = "batch"
|
export const ScopeBatch = "batch"
|
||||||
@@ -90,3 +91,4 @@ export const ScopeProxy = "proxy"
|
|||||||
export const ScopeProxyRead = "proxy:read" // 读取代理列表
|
export const ScopeProxyRead = "proxy:read" // 读取代理列表
|
||||||
export const ScopeProxyWrite = "proxy:write" // 写入代理
|
export const ScopeProxyWrite = "proxy:write" // 写入代理
|
||||||
export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态
|
export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态
|
||||||
|
export const ScopeChannelWriteClearExpired = "channel:write:clear_expired" //清理过期连接
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
export type Coupon = {
|
export type Coupon = {
|
||||||
id: number
|
id: number
|
||||||
created_at: Date
|
name: string
|
||||||
updated_at: Date
|
|
||||||
user_id: number
|
user_id: number
|
||||||
code: string
|
code: string
|
||||||
remark: string
|
remark: string
|
||||||
amount: number
|
amount: number
|
||||||
min_amount: number
|
min_amount: number
|
||||||
|
count: number
|
||||||
status: number
|
status: number
|
||||||
|
expire_type: number
|
||||||
|
created_at: Date
|
||||||
|
updated_at: Date
|
||||||
expire_at: Date
|
expire_at: Date
|
||||||
|
expire_in: number
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user