修整优惠券页面,添加发放功能及权限控制 & 用户添加查看优惠券发放详情 & 添加切换线上环境页面显示功能

This commit is contained in:
Eamon
2026-04-28 11:16:54 +08:00
parent 66ee6bb9fd
commit 7cd1a7cbe7
15 changed files with 765 additions and 198 deletions

View File

@@ -3,6 +3,7 @@ import { format } from "date-fns"
import { Suspense, useState } from "react"
import { toast } from "sonner"
import { deleteCoupon, getPagCoupon } from "@/actions/coupon"
import { Auth } from "@/components/auth"
import { DataTable, useDataTable } from "@/components/data-table"
import { Page } from "@/components/page"
import {
@@ -17,8 +18,10 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { ScopeCouponWriteAssign } from "@/lib/scopes"
import type { Coupon } from "@/models/coupon"
import { CreateDiscount } from "./create"
import { IssueCoupon } from "./issue"
import { UpdateCoupon } from "./update"
export default function CouponPage() {
@@ -36,30 +39,59 @@ export default function CouponPage() {
<DataTable<Coupon>
{...table}
columns={[
{ header: "所属用户", accessorKey: "user_id" },
{ header: "代码", accessorKey: "code" },
{ header: "备注", accessorKey: "remark" },
{ header: "金额", accessorKey: "amount" },
{ header: "优惠券名称", accessorKey: "name" },
{ header: "优惠券数量", accessorKey: "count" },
{ header: "优惠券金额", accessorKey: "amount" },
{ header: "最低消费金额", accessorKey: "min_amount" },
{
header: "状态",
header: "优惠券状态",
accessorKey: "status",
cell: ({ row }) => {
const status = row.original.status
if (status === 0) {
return <span className="text-yellow-600">使</span>
return <span className="text-yellow-600"></span>
}
if (status === 1) {
return <span className="text-green-600">使</span>
return <span className="text-green-600"></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: "过期时间",
accessorKey: "expire_at",
cell: ({ row }) =>
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
cell: ({ row }) => {
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: "创建时间",
@@ -67,12 +99,6 @@ export default function CouponPage() {
cell: ({ row }) =>
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",
meta: { pin: "right" },
@@ -87,6 +113,12 @@ export default function CouponPage() {
coupon={row.original}
onSuccess={table.refresh}
/>
<Auth scope={ScopeCouponWriteAssign}>
<IssueCoupon
coupon={row.original}
onSuccess={table.refresh}
/>
</Auth>
</div>
),
},
@@ -135,7 +167,7 @@ function DeleteCoupon({
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
{coupon.code}
{coupon.name}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>