feat(birthday): 提醒页改回列表并支持自定义字段

布局对齐商户列表,可勾选展示列;仅管理员看明文手机号,去掉操作列。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-12 09:52:23 +08:00
co-authored by Cursor
parent 6a63e404f1
commit 4b2334fb70
3 changed files with 396 additions and 130 deletions
+7 -130
View File
@@ -1,31 +1,11 @@
import type { ReactNode } from "react";
import { Prisma } from "@prisma/client";
import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth";
import { isStaff, isSuperAdmin } from "@/lib/acl";
import { birthdayMatchLists, lunarBirthdaySolarThisYear } from "@/lib/lunar";
import { fmtDate, maskPhone } from "@/lib/utils";
import { isSuperAdmin } from "@/lib/acl";
import { birthdayMatchLists } from "@/lib/lunar";
import { Card } from "@/components/ui/card";
import { BirthdayControl } from "./birthday-control";
type Row = {
id: number;
customerName: string | null;
customerNo: string | null;
contacts: string | null;
contactsPhone: string | null;
balanceUser: string | null;
balanceUserPhone: string | null;
phone: string | null; // 旧公共电话,仅作结算人手机号为空时的回退
detail: string | null;
deposit: string | null;
buy: string | null;
salesman: string | null;
reportDate: Date | null;
birthday: Date | null;
birthdayType: number | null;
remark: string | null;
};
import { BirthdayList, type BirthdayRow } from "./birthday-list";
function baseDate(s?: string): Date {
if (s) {
@@ -35,19 +15,13 @@ function baseDate(s?: string): Date {
return new Date();
}
function showPhone(raw: string | null | undefined, full: boolean) {
const value = raw?.trim() || "";
if (!value) return "—";
return full ? value : maskPhone(value);
}
export default async function BirthdayPage({
searchParams,
}: {
searchParams: Promise<{ mode?: string; date?: string }>;
}) {
const session = await auth();
const fullPhone = isSuperAdmin(session?.user?.roles) || isStaff(session?.user?.roles);
const isAdmin = isSuperAdmin(session?.user?.roles);
const sp = await searchParams;
const mode = sp.mode === "week" ? "week" : "today";
const dateStr = sp.date ?? "";
@@ -58,7 +32,7 @@ export default async function BirthdayPage({
? birthdayMatchLists(base, 7, false)
: birthdayMatchLists(base, 1, true);
const rows = await prisma.$queryRaw<Row[]>(Prisma.sql`
const rows = await prisma.$queryRaw<BirthdayRow[]>(Prisma.sql`
SELECT
id,
customer_name AS customerName,
@@ -66,8 +40,7 @@ export default async function BirthdayPage({
contacts,
contacts_phone AS contactsPhone,
balance_user AS balanceUser,
balance_user_phone AS balanceUserPhone,
phone,
COALESCE(NULLIF(balance_user_phone, ''), phone) AS balanceUserPhone,
detail,
deposit,
buy,
@@ -94,103 +67,7 @@ export default async function BirthdayPage({
</div>
</Card>
{rows.length === 0 && (
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
没有过生日的商户
</Card>
)}
<div className="space-y-3">
{rows.map((c) => {
const balancePhone = c.balanceUserPhone || c.phone;
const lunar = Number(c.birthdayType) === 2;
const solarThisYear = lunar ? lunarBirthdaySolarThisYear(fmtDate(c.birthday)) : null;
return (
<Card key={c.id} className="p-4 md:p-5">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<div className="truncate text-base font-semibold">{c.customerName || "—"}</div>
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
编号 {c.customerNo || "—"}
</div>
</div>
<div className="shrink-0 text-right">
<div className="text-xs text-[var(--color-muted-foreground)]">
{lunar ? "今年是" : "生日"}
</div>
<div className="mt-0.5 text-sm font-medium tabular-nums">
{lunar ? solarThisYear || fmtDate(c.birthday) : fmtDate(c.birthday)}
</div>
</div>
</div>
<div className="mt-4 grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-3">
<Field label="商户名称" value={c.customerName} />
<Field label="商户编号" value={c.customerNo} />
<Field label="业务员" value={c.salesman} />
<Field label="报单日期" value={fmtDate(c.reportDate)} />
<Field label="联系人" value={c.contacts} />
<Field label="联系人手机号">
<Phone value={showPhone(c.contactsPhone, fullPhone)} callable={fullPhone} />
</Field>
<Field label="结算人" value={c.balanceUser} />
<Field label="结算人手机号">
<Phone value={showPhone(balancePhone, fullPhone)} callable={fullPhone} />
</Field>
<Field label="生日">
{lunar ? (
<span>
农历 {fmtDate(c.birthday).slice(5) || "—"}
<span className="mt-0.5 block text-xs text-[var(--color-warning)]">
按农历过生日{solarThisYear ? `,今年是 ${solarThisYear}` : ""}
</span>
</span>
) : (
fmtDate(c.birthday) || "—"
)}
</Field>
<Field label="押金" value={c.deposit} />
<Field label="买断" value={c.buy} />
</div>
<div className="mt-3 space-y-3 border-t pt-3">
<Field label="产品明细" value={c.detail} pre />
<Field label="备注" value={c.remark} pre />
</div>
</Card>
);
})}
</div>
<BirthdayList rows={rows} isAdmin={isAdmin} />
</div>
);
}
function Field({
label,
value,
pre,
children,
}: {
label: string;
value?: string | null;
pre?: boolean;
children?: ReactNode;
}) {
return (
<div className="min-w-0">
<div className="text-xs text-[var(--color-muted-foreground)]">{label}</div>
<div className={pre ? "mt-0.5 whitespace-pre-wrap break-words text-sm" : "mt-0.5 break-words text-sm"}>
{children ?? (value?.trim() ? value : "—")}
</div>
</div>
);
}
function Phone({ value, callable }: { value: string; callable: boolean }) {
if (!callable || value === "—") return <span className="tabular-nums">{value}</span>;
return (
<a href={`tel:${value}`} className="tabular-nums text-[var(--color-primary)] hover:underline">
{value}
</a>
);
}