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
+1 -1
View File
@@ -4,7 +4,7 @@ DATABASE_URL="mysql://crm_dev:PASSWORD@124.223.187.95:3306/crm_dev"
# Auth.js 会话加密密钥:openssl rand -base64 32 # Auth.js 会话加密密钥:openssl rand -base64 32
AUTH_SECRET="please-run-openssl-rand-base64-32" AUTH_SECRET="please-run-openssl-rand-base64-32"
# 开发环境不需要 AUTH_URL(trustHost:true 自动识别 host/端口)。 # 本地开发不要设置 AUTH_URL,否则打开 localhost 会被跳到该地址。
# 生产必须设为浏览器可访问的地址(真实域名或公网 IP), # 生产必须设为浏览器可访问的地址(真实域名或公网 IP),
# 切勿写成监听地址 0.0.0.0,否则登录/退出会跳到 http://0.0.0.0:端口 # 切勿写成监听地址 0.0.0.0,否则登录/退出会跳到 http://0.0.0.0:端口
# AUTH_URL="https://crm.yourdomain.com" # AUTH_URL="https://crm.yourdomain.com"
+1
View File
@@ -17,6 +17,7 @@ datasource db {
model Customer { model Customer {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
customerName String? @default("") @map("customer_name") customerName String? @default("") @map("customer_name")
customerNo String? @map("customer_no") @db.Text // 商户编号,数字与字母,区分大小写,不限位数
contacts String? // 联系人 contacts String? // 联系人
contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号 contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号
balanceUser String? @map("balance_user") // 结算人 balanceUser String? @map("balance_user") // 结算人
+6
View File
@@ -0,0 +1,6 @@
-- 商户表增加商户编号(数字+字母,区分大小写,不限位数)
-- 执行:本地与生产库均需执行;执行后运行 npm run prisma:generate
-- 历史行保持 NULL,新录入/导入必填
ALTER TABLE customers
ADD COLUMN customer_no TEXT NULL COMMENT '商户编号' AFTER customer_name;
+27 -9
View File
@@ -11,8 +11,15 @@ import { isSuperAdmin } from "@/lib/acl";
import { fmtDate, parseDate } from "@/lib/utils"; import { fmtDate, parseDate } from "@/lib/utils";
// 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date) // 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date)
const customerNoSchema = z
.string()
.trim()
.min(1, "商户编号必填")
.regex(/^[A-Za-z0-9]+$/, "商户编号只能包含数字和字母,区分大小写");
const schema = z.object({ const schema = z.object({
customerName: z.string().trim().min(1, "商户名称必填").max(500), customerName: z.string().trim().min(1, "商户名称必填").max(500),
customerNo: customerNoSchema,
contacts: z.string().trim().min(1, "联系人必填").max(500), contacts: z.string().trim().min(1, "联系人必填").max(500),
balanceUser: z.string().trim().min(1, "结算人必填").max(500), balanceUser: z.string().trim().min(1, "结算人必填").max(500),
detail: z.string().trim().min(1, "产品明细必填"), detail: z.string().trim().min(1, "产品明细必填"),
@@ -26,8 +33,8 @@ const schema = z.object({
balanceUserPhone: z.string().trim().optional().default(""), balanceUserPhone: z.string().trim().optional().default(""),
deposit: z.string().trim().optional().default(""), deposit: z.string().trim().optional().default(""),
buy: z.string().trim().optional().default(""), buy: z.string().trim().optional().default(""),
birthdayType: z.coerce.number().int().min(1).max(2).default(1), birthdayType: z.coerce.number().refine((n) => n === 1, "生日类型只能是阳历"),
birthdayOwner: z.coerce.number().int().min(1).max(2).default(2), birthdayOwner: z.coerce.number().refine((n) => n === 1, "生日归属只能是结算人"),
birthday: z.string().trim().optional().default(""), birthday: z.string().trim().optional().default(""),
remark: z.string().trim().optional().default(""), remark: z.string().trim().optional().default(""),
}); });
@@ -57,6 +64,7 @@ export type ActionState = { error?: string };
function pickForm(formData: FormData) { function pickForm(formData: FormData) {
return { return {
customerName: formData.get("customerName"), customerName: formData.get("customerName"),
customerNo: formData.get("customerNo"),
contacts: formData.get("contacts"), contacts: formData.get("contacts"),
balanceUser: formData.get("balanceUser"), balanceUser: formData.get("balanceUser"),
detail: formData.get("detail"), detail: formData.get("detail"),
@@ -66,8 +74,8 @@ function pickForm(formData: FormData) {
balanceUserPhone: formData.get("balanceUserPhone") ?? "", balanceUserPhone: formData.get("balanceUserPhone") ?? "",
deposit: formData.get("deposit") ?? "", deposit: formData.get("deposit") ?? "",
buy: formData.get("buy") ?? "", buy: formData.get("buy") ?? "",
birthdayType: formData.get("birthdayType") ?? 1, birthdayType: 1,
birthdayOwner: formData.get("birthdayOwner") ?? 2, birthdayOwner: 1,
birthday: formData.get("birthday") ?? "", birthday: formData.get("birthday") ?? "",
remark: formData.get("remark") ?? "", remark: formData.get("remark") ?? "",
}; };
@@ -105,7 +113,15 @@ export async function updateCustomer(
const r = schema.safeParse(pickForm(formData)); const r = schema.safeParse(pickForm(formData));
if (!r.success) return { error: r.error.issues[0].message }; if (!r.success) return { error: r.error.issues[0].message };
await prisma.customer.update({ where: { id }, data: toData(r.data) }); const existing = await prisma.customer.findUnique({
where: { id },
select: { birthdayType: true },
});
const data = toData(r.data);
// 改版前的阴历生日不能在保存其它字段时改成阳历,否则明年提醒日会错
if (existing?.birthdayType === 2) data.birthdayType = 2;
await prisma.customer.update({ where: { id }, data });
revalidatePath("/customers"); revalidatePath("/customers");
redirect("/customers"); redirect("/customers");
} }
@@ -125,6 +141,7 @@ export async function deleteCustomer(id: number): Promise<void> {
const HEADER_MAP: Record<string, string> = { const HEADER_MAP: Record<string, string> = {
商户名称: "customerName", 商户名称: "customerName",
商户编号: "customerNo",
联系人: "contacts", 联系人: "contacts",
联系人电话: "contactsPhone", 联系人电话: "contactsPhone",
结算人: "balanceUser", 结算人: "balanceUser",
@@ -134,8 +151,6 @@ const HEADER_MAP: Record<string, string> = {
产品明细: "detail", 产品明细: "detail",
押金: "deposit", 押金: "deposit",
买断: "buy", 买断: "buy",
生日类型: "birthdayType",
生日归属: "birthdayOwner",
生日: "birthday", 生日: "birthday",
业务员: "salesman", 业务员: "salesman",
报单日期: "reportDate", 报单日期: "reportDate",
@@ -170,6 +185,8 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
const errors: string[] = []; const errors: string[] = [];
if (!rec.customerName) errors.push("商户名称必填"); if (!rec.customerName) errors.push("商户名称必填");
if (!rec.customerNo) errors.push("商户编号必填");
else if (!/^[A-Za-z0-9]+$/.test(rec.customerNo)) errors.push("商户编号只能包含数字和字母");
const reportDate = parseDate(rec.reportDate); const reportDate = parseDate(rec.reportDate);
if (!rec.reportDate || !reportDate) errors.push("报单日期必填且格式为 YYYY-MM-DD"); if (!rec.reportDate || !reportDate) errors.push("报单日期必填且格式为 YYYY-MM-DD");
if (rec.birthday && !parseDate(rec.birthday)) errors.push("生日格式应为 YYYY-MM-DD"); if (rec.birthday && !parseDate(rec.birthday)) errors.push("生日格式应为 YYYY-MM-DD");
@@ -179,6 +196,7 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
} else { } else {
validData.push({ validData.push({
customerName: rec.customerName, customerName: rec.customerName,
customerNo: rec.customerNo,
contacts: rec.contacts || null, contacts: rec.contacts || null,
contactsPhone: rec.contactsPhone || null, contactsPhone: rec.contactsPhone || null,
balanceUser: rec.balanceUser || null, balanceUser: rec.balanceUser || null,
@@ -189,8 +207,8 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
buy: rec.buy || null, buy: rec.buy || null,
salesman: rec.salesman || null, salesman: rec.salesman || null,
remark: rec.remark || null, remark: rec.remark || null,
birthdayType: rec.birthdayType === "阴历" || rec.birthdayType === "2" ? 2 : 1, birthdayType: 1,
birthdayOwner: rec.birthdayOwner === "结算人" || rec.birthdayOwner === "1" ? 1 : 2, birthdayOwner: 1,
birthday: parseDate(rec.birthday), birthday: parseDate(rec.birthday),
reportDate, reportDate,
}); });
+105 -89
View File
@@ -1,27 +1,29 @@
import type { ReactNode } from "react";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { prisma } from "@/lib/prisma"; import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth"; import { auth } from "@/lib/auth";
import { isSuperAdmin } from "@/lib/acl"; import { isStaff, isSuperAdmin } from "@/lib/acl";
import { birthdayMatchLists } from "@/lib/lunar"; import { birthdayMatchLists, lunarBirthdaySolarThisYear } from "@/lib/lunar";
import { fmtDate, maskPhone } from "@/lib/utils"; import { fmtDate, maskPhone } from "@/lib/utils";
import { Card } from "@/components/ui/card"; 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"; import { BirthdayControl } from "./birthday-control";
type Row = { type Row = {
id: number; id: number;
customerName: string | null; customerName: string | null;
customerNo: string | null;
contacts: string | null; contacts: string | null;
contactsPhone: string | null; contactsPhone: string | null;
balanceUser: string | null; balanceUser: string | null;
balanceUserPhone: string | null; balanceUserPhone: string | null;
phone: string | null; // 旧公共电话,仅作新字段为空时的回退 phone: string | null; // 旧公共电话,仅作结算人手机号为空时的回退
detail: string | null;
deposit: string | null;
buy: string | null;
salesman: string | null; salesman: string | null;
reportDate: Date | null; reportDate: Date | null;
birthday: Date | null; birthday: Date | null;
birthdayType: number | null; birthdayType: number | null;
birthdayOwner: number | null;
remark: string | null; remark: string | null;
}; };
@@ -33,13 +35,19 @@ function baseDate(s?: string): Date {
return new 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({ export default async function BirthdayPage({
searchParams, searchParams,
}: { }: {
searchParams: Promise<{ mode?: string; date?: string }>; searchParams: Promise<{ mode?: string; date?: string }>;
}) { }) {
const session = await auth(); 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 sp = await searchParams;
const mode = sp.mode === "week" ? "week" : "today"; const mode = sp.mode === "week" ? "week" : "today";
const dateStr = sp.date ?? ""; const dateStr = sp.date ?? "";
@@ -54,16 +62,19 @@ export default async function BirthdayPage({
SELECT SELECT
id, id,
customer_name AS customerName, customer_name AS customerName,
customer_no AS customerNo,
contacts, contacts,
contacts_phone AS contactsPhone, contacts_phone AS contactsPhone,
balance_user AS balanceUser, balance_user AS balanceUser,
balance_user_phone AS balanceUserPhone, balance_user_phone AS balanceUserPhone,
phone, phone,
detail,
deposit,
buy,
salesman, salesman,
report_date AS reportDate, report_date AS reportDate,
birthday, birthday,
birthday_type AS birthdayType, birthday_type AS birthdayType,
birthday_owner AS birthdayOwner,
remark remark
FROM customers FROM customers
WHERE deleted_at IS NULL AND ( 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"> <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} /> <BirthdayControl mode={mode} date={dateStr} />
<div className="text-sm text-[var(--color-muted-foreground)] sm:pr-1"> <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> </div>
</Card> </Card>
<Card className="hidden overflow-hidden md:block"> {rows.length === 0 && (
<Table> <Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
<THead> 没有过生日的商户
<tr> </Card>
<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>
<div className="space-y-3 md:hidden"> <div className="space-y-3">
{rows.length === 0 && (
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
该时段暂无生日商户
</Card>
)}
{rows.map((c) => { {rows.map((c) => {
const ownerName = c.birthdayOwner === 1 ? c.balanceUser : c.contacts; const balancePhone = c.balanceUserPhone || c.phone;
const ownerPhone = const lunar = Number(c.birthdayType) === 2;
(c.birthdayOwner === 1 ? c.balanceUserPhone : c.contactsPhone) || c.phone; const solarThisYear = lunar ? lunarBirthdaySolarThisYear(fmtDate(c.birthday)) : null;
return ( 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="flex items-start justify-between gap-3">
<div className="min-w-0"> <div className="min-w-0">
<div className="truncate font-medium">{c.customerName}</div> <div className="truncate text-base font-semibold">{c.customerName || "—"}</div>
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]"> <div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
{c.salesman || "—"} 编号 {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>
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="shrink-0">
{c.birthdayType === 2 ? "农历" : "阳历"}
</Badge>
</div> </div>
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
<div> <div className="mt-4 grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-3">
<dt className="text-xs text-[var(--color-muted-foreground)]">归属人</dt> <Field label="商户名称" value={c.customerName} />
<dd>{ownerName || "—"}</dd> <Field label="商户编号" value={c.customerNo} />
<dd className="text-xs tabular-nums text-[var(--color-muted-foreground)]"> <Field label="业务员" value={c.salesman} />
{superAdmin ? ownerPhone : maskPhone(ownerPhone)} <Field label="报单日期" value={fmtDate(c.reportDate)} />
</dd> <Field label="联系人" value={c.contacts} />
</div> <Field label="联系人手机号">
<div> <Phone value={showPhone(c.contactsPhone, fullPhone)} callable={fullPhone} />
<dt className="text-xs text-[var(--color-muted-foreground)]">生日</dt> </Field>
<dd className="tabular-nums">{fmtDate(c.birthday)}</dd> <Field label="结算人" value={c.balanceUser} />
<dd className="text-xs text-[var(--color-muted-foreground)]"> <Field label="结算人手机号">
{c.birthdayOwner === 1 ? "结算人" : "联系人"} <Phone value={showPhone(balancePhone, fullPhone)} callable={fullPhone} />
</dd> </Field>
</div> <Field label="生日">
</dl> {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> </Card>
); );
})} })}
@@ -178,3 +164,33 @@ export default async function BirthdayPage({
</div> </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>
);
}
+16 -21
View File
@@ -3,13 +3,14 @@
import { useActionState } from "react"; import { useActionState } from "react";
import Link from "next/link"; import Link from "next/link";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Input, Textarea, Select } from "@/components/ui/input"; import { Input, Textarea } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { fmtDate } from "@/lib/utils"; import { fmtDate } from "@/lib/utils";
import type { ActionState } from "./actions"; import type { ActionState } from "./actions";
type CustomerValues = { type CustomerValues = {
customerName?: string | null; customerName?: string | null;
customerNo?: string | null;
contacts?: string | null; contacts?: string | null;
contactsPhone?: string | null; contactsPhone?: string | null;
balanceUser?: string | null; balanceUser?: string | null;
@@ -17,9 +18,8 @@ type CustomerValues = {
detail?: string | null; detail?: string | null;
deposit?: string | null; deposit?: string | null;
buy?: string | null; buy?: string | null;
birthdayType?: number | null;
birthdayOwner?: number | null;
birthday?: Date | null; birthday?: Date | null;
birthdayType?: number | null;
salesman?: string | null; salesman?: string | null;
reportDate?: Date | null; reportDate?: Date | null;
remark?: string | null; remark?: string | null;
@@ -108,6 +108,14 @@ export function CustomerForm({
pattern={requireAll ? "\\S+" : undefined} pattern={requireAll ? "\\S+" : undefined}
title={requireAll ? "商户名称不能包含空格" : undefined} title={requireAll ? "商户名称不能包含空格" : undefined}
/> />
<Field
label="商户编号"
name="customerNo"
defaultValue={v.customerNo}
required
pattern="[A-Za-z0-9]+"
title="只能填写数字和字母,区分大小写,位数不限"
/>
<Field label="业务员" name="salesman" defaultValue={v.salesman} required /> <Field label="业务员" name="salesman" defaultValue={v.salesman} required />
<Field <Field
label="报单日期" label="报单日期"
@@ -151,24 +159,6 @@ export function CustomerForm({
<FormSection title="生日"> <FormSection title="生日">
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3"> <div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
<div className="space-y-1.5">
<Label htmlFor="birthdayOwner">
生日归属<span className="ml-0.5 text-[var(--color-danger)]">*</span>
</Label>
<Select id="birthdayOwner" name="birthdayOwner" defaultValue={String(v.birthdayOwner ?? 2)}>
<option value="1">结算人</option>
<option value="2">联系人</option>
</Select>
</div>
<div className="space-y-1.5">
<Label htmlFor="birthdayType">
生日类型<span className="ml-0.5 text-[var(--color-danger)]">*</span>
</Label>
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
<option value="1">阳历</option>
<option value="2">阴历</option>
</Select>
</div>
<Field <Field
label="生日" label="生日"
name="birthday" name="birthday"
@@ -177,6 +167,11 @@ export function CustomerForm({
required={requireAll} required={requireAll}
/> />
</div> </div>
{v.birthdayType === 2 && (
<p className="text-sm text-[var(--color-warning)]">
这个生日是按农历记的。
</p>
)}
</FormSection> </FormSection>
<FormSection title="其它"> <FormSection title="其它">
@@ -84,7 +84,7 @@ export function CustomerToolbar({
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--color-muted-foreground)]" /> <Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--color-muted-foreground)]" />
<Input <Input
name="keyword" name="keyword"
placeholder="商户 / 联系人 / 联系电话 / 业务员" placeholder="商户 / 编号 / 联系人 / 电话 / 业务员"
defaultValue={defaultKeyword} defaultValue={defaultKeyword}
className="w-full pl-8 sm:w-64" className="w-full pl-8 sm:w-64"
/> />
@@ -9,6 +9,7 @@ import { fmtDate, cn } from "@/lib/utils";
type CustomerViewProps = { type CustomerViewProps = {
customer: { customer: {
customerName?: string | null; customerName?: string | null;
customerNo?: string | null;
contacts?: string | null; contacts?: string | null;
contactsPhone?: string | null; contactsPhone?: string | null;
balanceUser?: string | null; balanceUser?: string | null;
@@ -16,8 +17,6 @@ type CustomerViewProps = {
detail?: string | null; detail?: string | null;
deposit?: string | null; deposit?: string | null;
buy?: string | null; buy?: string | null;
birthdayType?: number | null;
birthdayOwner?: number | null;
birthday?: Date | null; birthday?: Date | null;
salesman?: string | null; salesman?: string | null;
reportDate?: Date | null; reportDate?: Date | null;
@@ -43,11 +42,8 @@ export function CustomerView({ customer }: CustomerViewProps) {
}; };
}, [open]); }, [open]);
const birthdayLabel = customer.birthdayType === 2 ? "阴历" : "阳历";
const birthdayOwnerLabel = customer.birthdayOwner === 1 ? "结算人" : "联系人";
// 各分区是否至少有一个字段,用于隐藏整块为空的小标题 // 各分区是否至少有一个字段,用于隐藏整块为空的小标题
const hasBasic = !!(customer.customerName || customer.detail); const hasBasic = !!(customer.customerName || customer.customerNo || customer.detail);
const hasContacts = !!(customer.contacts || customer.contactsPhone); const hasContacts = !!(customer.contacts || customer.contactsPhone);
const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone); const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone);
const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate); const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate);
@@ -85,6 +81,7 @@ export function CustomerView({ customer }: CustomerViewProps) {
{hasBasic && ( {hasBasic && (
<Section title="基本"> <Section title="基本">
<InfoRow label="商户名称" value={customer.customerName} /> <InfoRow label="商户名称" value={customer.customerName} />
<InfoRow label="商户编号" value={customer.customerNo} />
<InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" /> <InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" />
</Section> </Section>
)} )}
@@ -102,8 +99,6 @@ export function CustomerView({ customer }: CustomerViewProps) {
)} )}
{customer.birthday && ( {customer.birthday && (
<Section title="生日"> <Section title="生日">
<InfoRow label="生日类型" value={birthdayLabel} />
<InfoRow label="生日归属" value={birthdayOwnerLabel} />
<InfoRow label="生日" value={fmtDate(customer.birthday)} /> <InfoRow label="生日" value={fmtDate(customer.birthday)} />
</Section> </Section>
)} )}
@@ -32,6 +32,7 @@ export async function GET(req: NextRequest) {
for (const c of rows) { for (const c of rows) {
aoa.push([ aoa.push([
c.customerName ?? "", c.customerName ?? "",
c.customerNo ?? "",
c.contacts ?? "", c.contacts ?? "",
c.contactsPhone ?? "", c.contactsPhone ?? "",
c.balanceUser ?? "", c.balanceUser ?? "",
@@ -39,8 +40,6 @@ export async function GET(req: NextRequest) {
c.detail ?? "", c.detail ?? "",
c.deposit ?? "", c.deposit ?? "",
c.buy ?? "", c.buy ?? "",
c.birthdayType === 2 ? "阴历" : "阳历",
c.birthdayOwner === 1 ? "结算人" : "联系人",
fmtDate(c.birthday), fmtDate(c.birthday),
c.salesman ?? "", c.salesman ?? "",
fmtDate(c.reportDate), fmtDate(c.reportDate),
+12 -20
View File
@@ -5,7 +5,6 @@ import { isStaff, isSuperAdmin } from "@/lib/acl";
import { fmtDate, maskPhone } from "@/lib/utils"; import { fmtDate, maskPhone } from "@/lib/utils";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
import { Table, THead, TR, TH, TD } from "@/components/ui/table"; import { Table, THead, TR, TH, TD } from "@/components/ui/table";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { CustomerToolbar } from "./customer-toolbar"; import { CustomerToolbar } from "./customer-toolbar";
import { DeleteButton } from "./delete-button"; import { DeleteButton } from "./delete-button";
@@ -66,6 +65,7 @@ export default async function CustomersPage({
<THead> <THead>
<tr> <tr>
<TH>商户名称</TH> <TH>商户名称</TH>
<TH>商户编号</TH>
<TH>联系人</TH> <TH>联系人</TH>
<TH>结算人</TH> <TH>结算人</TH>
<TH>产品明细</TH> <TH>产品明细</TH>
@@ -81,7 +81,7 @@ export default async function CustomersPage({
<tbody> <tbody>
{rows.length === 0 && ( {rows.length === 0 && (
<tr> <tr>
<TD colSpan={11} className="py-14 text-center text-[var(--color-muted-foreground)]"> <TD colSpan={12} className="py-14 text-center text-[var(--color-muted-foreground)]">
暂无数据 暂无数据
</TD> </TD>
</tr> </tr>
@@ -92,6 +92,7 @@ export default async function CustomersPage({
return ( return (
<TR key={c.id}> <TR key={c.id}>
<TD className="font-medium">{c.customerName}</TD> <TD className="font-medium">{c.customerName}</TD>
<TD className="font-medium break-all">{c.customerNo || "—"}</TD>
<TD> <TD>
<div>{c.contacts}</div> <div>{c.contacts}</div>
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]"> <div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
@@ -107,19 +108,7 @@ export default async function CustomersPage({
<TD className="max-w-[280px] whitespace-normal break-words">{c.detail}</TD> <TD className="max-w-[280px] whitespace-normal break-words">{c.detail}</TD>
<TD>{c.deposit}</TD> <TD>{c.deposit}</TD>
<TD>{c.buy}</TD> <TD>{c.buy}</TD>
<TD> <TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
<span className="tabular-nums">{fmtDate(c.birthday)}</span>
{c.birthday && (
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="ml-2">
{c.birthdayType === 2 ? "农历" : "阳历"}
</Badge>
)}
{c.birthday && (
<Badge tone="neutral" className="ml-2">
{c.birthdayOwner === 1 ? "结算人" : "联系人"}
</Badge>
)}
</TD>
<TD>{c.salesman}</TD> <TD>{c.salesman}</TD>
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD> <TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD> <TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
@@ -159,16 +148,19 @@ export default async function CustomersPage({
<div className="flex items-start justify-between gap-3"> <div className="flex items-start justify-between gap-3">
<div className="min-w-0"> <div className="min-w-0">
<div className="truncate font-medium">{c.customerName}</div> <div className="truncate font-medium">{c.customerName}</div>
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
编号 {c.customerNo || "—"}
</div>
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]"> <div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
{c.salesman} {c.salesman}
{c.reportDate ? ` · ${fmtDate(c.reportDate)}` : ""} {c.reportDate ? ` · ${fmtDate(c.reportDate)}` : ""}
</div> </div>
</div> </div>
{c.birthday && ( {c.birthday ? (
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="shrink-0"> <span className="shrink-0 text-xs tabular-nums text-[var(--color-muted-foreground)]">
{c.birthdayType === 2 ? "农历" : "阳历"} {fmtDate(c.birthday)} {fmtDate(c.birthday)}
</Badge> </span>
)} ) : null}
</div> </div>
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm"> <dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
<div> <div>
+2 -2
View File
@@ -14,6 +14,7 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
if (keyword) { if (keyword) {
where.OR = [ where.OR = [
{ customerName: { contains: keyword } }, { customerName: { contains: keyword } },
{ customerNo: { contains: keyword } },
{ contacts: { contains: keyword } }, { contacts: { contains: keyword } },
{ contactsPhone: { contains: keyword } }, { contactsPhone: { contains: keyword } },
{ balanceUser: { contains: keyword } }, { balanceUser: { contains: keyword } },
@@ -32,6 +33,7 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
/** 导出/导入的列定义(表头 ↔ 字段) */ /** 导出/导入的列定义(表头 ↔ 字段) */
export const EXCEL_COLUMNS: { header: string; key: string }[] = [ export const EXCEL_COLUMNS: { header: string; key: string }[] = [
{ header: "商户名称", key: "customerName" }, { header: "商户名称", key: "customerName" },
{ header: "商户编号", key: "customerNo" },
{ header: "联系人", key: "contacts" }, { header: "联系人", key: "contacts" },
{ header: "联系人电话", key: "contactsPhone" }, { header: "联系人电话", key: "contactsPhone" },
{ header: "结算人", key: "balanceUser" }, { header: "结算人", key: "balanceUser" },
@@ -39,8 +41,6 @@ export const EXCEL_COLUMNS: { header: string; key: string }[] = [
{ header: "产品明细", key: "detail" }, { header: "产品明细", key: "detail" },
{ header: "押金", key: "deposit" }, { header: "押金", key: "deposit" },
{ header: "买断", key: "buy" }, { header: "买断", key: "buy" },
{ header: "生日类型", key: "birthdayType" },
{ header: "生日归属", key: "birthdayOwner" },
{ header: "生日", key: "birthday" }, { header: "生日", key: "birthday" },
{ header: "业务员", key: "salesman" }, { header: "业务员", key: "salesman" },
{ header: "报单日期", key: "reportDate" }, { header: "报单日期", key: "reportDate" },
@@ -10,6 +10,7 @@ export async function GET() {
const headers = [ const headers = [
"商户名称", "商户名称",
"商户编号",
"联系人", "联系人",
"联系人电话", "联系人电话",
"结算人", "结算人",
@@ -17,8 +18,6 @@ export async function GET() {
"产品明细", "产品明细",
"押金", "押金",
"买断", "买断",
"生日类型",
"生日归属",
"生日", "生日",
"业务员", "业务员",
"报单日期", "报单日期",
@@ -28,6 +27,7 @@ export async function GET() {
// 示例行(用户导入前需删除此行) // 示例行(用户导入前需删除此行)
const example = [ const example = [
"模板名称_此行删除", "模板名称_此行删除",
"Ab12Cd",
"侯磊", "侯磊",
"13813855555", "13813855555",
"张三", "张三",
@@ -35,8 +35,6 @@ export async function GET() {
"POS+CRM", "POS+CRM",
"100", "100",
"100", "100",
"阴历",
"联系人",
"生日格式要求:2022-06-21", "生日格式要求:2022-06-21",
"A", "A",
"报单日期格式要求:2022-06-21", "报单日期格式要求:2022-06-21",
+13 -14
View File
@@ -6,7 +6,6 @@ import { birthdayMatchLists } from "@/lib/lunar";
import { fmtDate } from "@/lib/utils"; import { fmtDate } from "@/lib/utils";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Table, THead, TR, TH, TD } from "@/components/ui/table"; import { Table, THead, TR, TH, TD } from "@/components/ui/table";
import { Badge } from "@/components/ui/badge";
import { MonthlyReportChart, type MonthPoint } from "./report-chart"; import { MonthlyReportChart, type MonthPoint } from "./report-chart";
export default async function DashboardPage() { export default async function DashboardPage() {
@@ -131,6 +130,7 @@ export default async function DashboardPage() {
<THead> <THead>
<tr> <tr>
<TH>商户名称</TH> <TH>商户名称</TH>
<TH>商户编号</TH>
<TH>联系人</TH> <TH>联系人</TH>
<TH>业务员</TH> <TH>业务员</TH>
<TH>报单时间</TH> <TH>报单时间</TH>
@@ -141,17 +141,11 @@ export default async function DashboardPage() {
{recent.map((c) => ( {recent.map((c) => (
<TR key={c.id}> <TR key={c.id}>
<TD className="font-medium">{c.customerName}</TD> <TD className="font-medium">{c.customerName}</TD>
<TD className="break-all">{c.customerNo || "—"}</TD>
<TD>{c.contacts}</TD> <TD>{c.contacts}</TD>
<TD>{c.salesman}</TD> <TD>{c.salesman}</TD>
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD> <TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
<TD> <TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
<span className="tabular-nums">{fmtDate(c.birthday)}</span>
{c.birthday && (
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="ml-2">
{c.birthdayType === 2 ? "农历" : "阳历"}
</Badge>
)}
</TD>
</TR> </TR>
))} ))}
</tbody> </tbody>
@@ -167,6 +161,11 @@ export default async function DashboardPage() {
<div key={c.id} className="flex items-start justify-between gap-3 px-4 py-3"> <div key={c.id} className="flex items-start justify-between gap-3 px-4 py-3">
<div className="min-w-0"> <div className="min-w-0">
<div className="truncate font-medium">{c.customerName}</div> <div className="truncate font-medium">{c.customerName}</div>
{c.customerNo ? (
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
编号 {c.customerNo}
</div>
) : null}
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]"> <div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
{c.contacts || "—"} {c.contacts || "—"}
{c.salesman ? ` · ${c.salesman}` : ""} {c.salesman ? ` · ${c.salesman}` : ""}
@@ -176,11 +175,11 @@ export default async function DashboardPage() {
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]"> <div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
{fmtDate(c.reportDate)} {fmtDate(c.reportDate)}
</div> </div>
{c.birthday && ( {c.birthday ? (
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="mt-1"> <div className="mt-1 text-xs tabular-nums text-[var(--color-muted-foreground)]">
{c.birthdayType === 2 ? "农历" : "阳历"} {fmtDate(c.birthday)} {fmtDate(c.birthday)}
</Badge> </div>
)} ) : null}
</div> </div>
</div> </div>
))} ))}
+5
View File
@@ -1,5 +1,10 @@
import type { NextAuthConfig, DefaultSession } from "next-auth"; import type { NextAuthConfig, DefaultSession } from "next-auth";
// 本地 `next dev` 忽略 .env 里的生产 AUTH_URL,避免 localhost 被跳到公网机。
if (process.env.NODE_ENV === "development") {
delete process.env.AUTH_URL;
}
// Edge 安全的基础配置:不引入 Prisma / bcrypt,供 middleware 使用。 // Edge 安全的基础配置:不引入 Prisma / bcrypt,供 middleware 使用。
// 真正带数据库校验的 Credentials provider 在 auth.ts 里注入。 // 真正带数据库校验的 Credentials provider 在 auth.ts 里注入。
+19 -1
View File
@@ -1,4 +1,4 @@
import { Solar } from "lunar-typescript"; import { Lunar, Solar } from "lunar-typescript";
function pad2(n: number): string { function pad2(n: number): string {
return String(Math.abs(n)).padStart(2, "0"); return String(Math.abs(n)).padStart(2, "0");
@@ -39,3 +39,21 @@ export function birthdayMatchLists(
return { solar: [...solar], lunar: [...lunar] }; return { solar: [...solar], lunar: [...lunar] };
} }
/**
* 历史阴历生日存的是农历月日(年份占位)。换成今年对应的公历日期,供提醒页对照。
* 闰月等无法换算时返回 null,不猜日期。
*/
export function lunarBirthdaySolarThisYear(
isoDate: string,
year = new Date().getFullYear()
): string | null {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(isoDate);
if (!m) return null;
try {
const solar = Lunar.fromYmd(year, Number(m[2]), Number(m[3])).getSolar();
return `${solar.getYear()}-${pad2(solar.getMonth())}-${pad2(solar.getDay())}`;
} catch {
return null;
}
}