feat(customers): 增加商户编号并补齐生日提醒信息

录入、列表和导入导出带上商户编号。生日提醒展示与录入一致的商户资料,旧阴历生日仍按农历提醒。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-11 14:55:24 +08:00
co-authored by Cursor
parent d981e53330
commit c81962b732
15 changed files with 214 additions and 172 deletions
+105 -89
View File
@@ -1,27 +1,29 @@
import type { ReactNode } from "react";
import { Prisma } from "@prisma/client";
import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth";
import { isSuperAdmin } from "@/lib/acl";
import { birthdayMatchLists } from "@/lib/lunar";
import { isStaff, isSuperAdmin } from "@/lib/acl";
import { birthdayMatchLists, lunarBirthdaySolarThisYear } from "@/lib/lunar";
import { fmtDate, maskPhone } from "@/lib/utils";
import { Card } from "@/components/ui/card";
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
import { Badge } from "@/components/ui/badge";
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; // 旧公共电话,仅作新字段为空时的回退
phone: string | null; // 旧公共电话,仅作结算人手机号为空时的回退
detail: string | null;
deposit: string | null;
buy: string | null;
salesman: string | null;
reportDate: Date | null;
birthday: Date | null;
birthdayType: number | null;
birthdayOwner: number | null;
remark: string | null;
};
@@ -33,13 +35,19 @@ 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 superAdmin = isSuperAdmin(session?.user?.roles);
const fullPhone = isSuperAdmin(session?.user?.roles) || isStaff(session?.user?.roles);
const sp = await searchParams;
const mode = sp.mode === "week" ? "week" : "today";
const dateStr = sp.date ?? "";
@@ -54,16 +62,19 @@ export default async function BirthdayPage({
SELECT
id,
customer_name AS customerName,
customer_no AS customerNo,
contacts,
contacts_phone AS contactsPhone,
balance_user AS balanceUser,
balance_user_phone AS balanceUserPhone,
phone,
detail,
deposit,
buy,
salesman,
report_date AS reportDate,
birthday,
birthday_type AS birthdayType,
birthday_owner AS birthdayOwner,
remark
FROM customers
WHERE deleted_at IS NULL AND (
@@ -79,98 +90,73 @@ export default async function BirthdayPage({
<Card className="flex flex-col gap-3 p-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between">
<BirthdayControl mode={mode} date={dateStr} />
<div className="text-sm text-[var(--color-muted-foreground)] sm:pr-1">
命中 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位商户
共 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位商户过生日
</div>
</Card>
<Card className="hidden overflow-hidden md:block">
<Table>
<THead>
<tr>
<TH>商户名称</TH>
<TH>归属人</TH>
<TH>业务员</TH>
<TH>生日</TH>
<TH>历法</TH>
<TH>归属</TH>
</tr>
</THead>
<tbody>
{rows.length === 0 && (
<tr>
<TD colSpan={6} className="py-14 text-center text-[var(--color-muted-foreground)]">
该时段暂无生日商户
</TD>
</tr>
)}
{rows.map((c) => {
// 生日归属人的姓名和手机号;新手机号为空时回退旧公共 phone(历史数据)
const ownerName = c.birthdayOwner === 1 ? c.balanceUser : c.contacts;
const ownerPhone =
(c.birthdayOwner === 1 ? c.balanceUserPhone : c.contactsPhone) || c.phone;
return (
<TR key={c.id}>
<TD className="font-medium">{c.customerName}</TD>
<TD>
<div>{ownerName}</div>
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
{superAdmin ? ownerPhone : maskPhone(ownerPhone)}
</div>
</TD>
<TD>{c.salesman}</TD>
<TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
<TD>
<Badge tone={c.birthdayType === 2 ? "warning" : "info"}>
{c.birthdayType === 2 ? "农历" : "阳历"}
</Badge>
</TD>
<TD>{c.birthdayOwner === 1 ? "结算人" : "联系人"}</TD>
</TR>
);
})}
</tbody>
</Table>
</Card>
{rows.length === 0 && (
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
没有过生日的商户
</Card>
)}
<div className="space-y-3 md:hidden">
{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 ownerName = c.birthdayOwner === 1 ? c.balanceUser : c.contacts;
const ownerPhone =
(c.birthdayOwner === 1 ? c.balanceUserPhone : c.contactsPhone) || c.phone;
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">
<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 font-medium">{c.customerName}</div>
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
{c.salesman || "—"}
<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>
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="shrink-0">
{c.birthdayType === 2 ? "农历" : "阳历"}
</Badge>
</div>
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
<div>
<dt className="text-xs text-[var(--color-muted-foreground)]">归属人</dt>
<dd>{ownerName || "—"}</dd>
<dd className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
{superAdmin ? ownerPhone : maskPhone(ownerPhone)}
</dd>
</div>
<div>
<dt className="text-xs text-[var(--color-muted-foreground)]">生日</dt>
<dd className="tabular-nums">{fmtDate(c.birthday)}</dd>
<dd className="text-xs text-[var(--color-muted-foreground)]">
{c.birthdayOwner === 1 ? "结算人" : "联系人"}
</dd>
</div>
</dl>
<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>
);
})}
@@ -178,3 +164,33 @@ export default async function BirthdayPage({
</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>
);
}