feat(customers): 区分注名称与经营名称,商户编号改为选填
新增必填商户经营名称,原商户名称改为注名称;列表/导出/导入与生日提醒同步展示。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,14 +11,16 @@ import { isSuperAdmin } from "@/lib/acl";
|
||||
import { fmtDate, parseDate } from "@/lib/utils";
|
||||
|
||||
// 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date)
|
||||
// 商户编号非必填;有值时仅允许数字和字母
|
||||
const customerNoSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, "商户编号必填")
|
||||
.regex(/^[A-Za-z0-9]+$/, "商户编号只能包含数字和字母,区分大小写");
|
||||
.default("")
|
||||
.refine((s) => s === "" || /^[A-Za-z0-9]+$/.test(s), "商户编号只能包含数字和字母,区分大小写");
|
||||
|
||||
const schema = z.object({
|
||||
customerName: z.string().trim().min(1, "商户名称必填").max(500),
|
||||
customerName: z.string().trim().min(1, "商户注名称必填").max(500),
|
||||
businessName: z.string().trim().min(1, "商户经营名称必填").max(500),
|
||||
customerNo: customerNoSchema,
|
||||
contacts: z.string().trim().min(1, "联系人必填").max(500),
|
||||
balanceUser: z.string().trim().min(1, "结算人必填").max(500),
|
||||
@@ -39,14 +41,14 @@ const schema = z.object({
|
||||
remark: z.string().trim().optional().default(""),
|
||||
});
|
||||
|
||||
// 新增商户更严格:名称无空格、联系人/结算人手机号必填 11 位、押金/买断/生日必填(仅用于创建,编辑仍用 schema)
|
||||
// 新增商户更严格:注名称无空格、联系人/结算人手机号必填 11 位、押金/买断/生日必填(仅用于 create,编辑仍用 schema)
|
||||
const createSchema = schema.extend({
|
||||
customerName: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, "商户名称必填")
|
||||
.min(1, "商户注名称必填")
|
||||
.max(500)
|
||||
.refine((s) => !/\s/.test(s), "商户名称不能包含空格"),
|
||||
.refine((s) => !/\s/.test(s), "商户注名称不能包含空格"),
|
||||
contactsPhone: z.string().trim().regex(/^1\d{10}$/, "联系人手机号必须为 11 位数字"),
|
||||
balanceUserPhone: z.string().trim().regex(/^1\d{10}$/, "结算人手机号必须为 11 位数字"),
|
||||
deposit: z.string().trim().min(1, "押金必填"),
|
||||
@@ -64,7 +66,8 @@ export type ActionState = { error?: string };
|
||||
function pickForm(formData: FormData) {
|
||||
return {
|
||||
customerName: formData.get("customerName"),
|
||||
customerNo: formData.get("customerNo"),
|
||||
businessName: formData.get("businessName"),
|
||||
customerNo: formData.get("customerNo") ?? "",
|
||||
contacts: formData.get("contacts"),
|
||||
balanceUser: formData.get("balanceUser"),
|
||||
detail: formData.get("detail"),
|
||||
@@ -83,9 +86,10 @@ function pickForm(formData: FormData) {
|
||||
|
||||
/** 把校验后的表单值转成 Prisma 写入数据(日期字段转 Date) */
|
||||
function toData(v: z.infer<typeof schema>) {
|
||||
const { reportDate, birthday, ...rest } = v;
|
||||
const { reportDate, birthday, customerNo, ...rest } = v;
|
||||
return {
|
||||
...rest,
|
||||
customerNo: customerNo || null,
|
||||
reportDate: parseDate(reportDate),
|
||||
birthday: parseDate(birthday),
|
||||
};
|
||||
@@ -143,7 +147,10 @@ export async function deleteCustomer(id: number): Promise<void> {
|
||||
// ============ Excel 导入 ============
|
||||
|
||||
const HEADER_MAP: Record<string, string> = {
|
||||
商户注名称: "customerName",
|
||||
// 兼容旧版导入模板表头
|
||||
商户名称: "customerName",
|
||||
商户经营名称: "businessName",
|
||||
商户编号: "customerNo",
|
||||
联系人: "contacts",
|
||||
联系人电话: "contactsPhone",
|
||||
@@ -187,9 +194,11 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
||||
}
|
||||
|
||||
const errors: string[] = [];
|
||||
if (!rec.customerName) errors.push("商户名称必填");
|
||||
if (!rec.customerNo) errors.push("商户编号必填");
|
||||
else if (!/^[A-Za-z0-9]+$/.test(rec.customerNo)) errors.push("商户编号只能包含数字和字母");
|
||||
if (!rec.customerName) errors.push("商户注名称必填");
|
||||
if (!rec.businessName) errors.push("商户经营名称必填");
|
||||
if (rec.customerNo && !/^[A-Za-z0-9]+$/.test(rec.customerNo)) {
|
||||
errors.push("商户编号只能包含数字和字母");
|
||||
}
|
||||
const reportDate = parseDate(rec.reportDate);
|
||||
if (!rec.reportDate || !reportDate) errors.push("报单日期必填且格式为 YYYY-MM-DD");
|
||||
if (rec.birthday && !parseDate(rec.birthday)) errors.push("生日格式应为 YYYY-MM-DD");
|
||||
@@ -199,7 +208,8 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
||||
} else {
|
||||
validData.push({
|
||||
customerName: rec.customerName,
|
||||
customerNo: rec.customerNo,
|
||||
businessName: rec.businessName,
|
||||
customerNo: rec.customerNo || null,
|
||||
contacts: rec.contacts || null,
|
||||
contactsPhone: rec.contactsPhone || null,
|
||||
balanceUser: rec.balanceUser || null,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export const BIRTHDAY_COLUMN_STORAGE_KEY = "crm-birthday-columns-v1";
|
||||
export const BIRTHDAY_COLUMN_STORAGE_KEY = "crm-birthday-columns-v2";
|
||||
|
||||
export type BirthdayColumnKey =
|
||||
| "customerName"
|
||||
| "businessName"
|
||||
| "customerNo"
|
||||
| "contacts"
|
||||
| "balanceUser"
|
||||
@@ -23,13 +24,14 @@ export type BirthdayColumnDef = {
|
||||
};
|
||||
|
||||
export const BIRTHDAY_COLUMNS: BirthdayColumnDef[] = [
|
||||
{ key: "customerName", label: "商户名称", defaultVisible: true, className: "w-[12%]" },
|
||||
{ key: "customerNo", label: "商户编号", defaultVisible: true, className: "w-[10%]" },
|
||||
{ key: "balanceUser", label: "结算人", defaultVisible: true, className: "w-[12%]" },
|
||||
{ key: "contacts", label: "联系人", defaultVisible: true, className: "w-[12%]" },
|
||||
{ key: "birthday", label: "生日", defaultVisible: true, className: "w-[14%]" },
|
||||
{ key: "salesman", label: "业务员", defaultVisible: true, className: "w-[8%]" },
|
||||
{ key: "remark", label: "备注", defaultVisible: true, className: "w-[20%]" },
|
||||
{ key: "customerName", label: "商户注名称", defaultVisible: true, className: "w-[11%]" },
|
||||
{ key: "businessName", label: "商户经营名称", defaultVisible: true, className: "w-[11%]" },
|
||||
{ key: "customerNo", label: "商户编号", defaultVisible: true, className: "w-[9%]" },
|
||||
{ key: "balanceUser", label: "结算人", defaultVisible: true, className: "w-[11%]" },
|
||||
{ key: "contacts", label: "联系人", defaultVisible: true, className: "w-[11%]" },
|
||||
{ key: "birthday", label: "生日", defaultVisible: true, className: "w-[13%]" },
|
||||
{ key: "salesman", label: "业务员", defaultVisible: true, className: "w-[7%]" },
|
||||
{ key: "remark", label: "备注", defaultVisible: true, className: "w-[16%]" },
|
||||
{ key: "reportDate", label: "报单日期", defaultVisible: false, className: "w-[10%]" },
|
||||
{ key: "deposit", label: "押金", defaultVisible: false, className: "w-[8%]" },
|
||||
{ key: "buy", label: "买断", defaultVisible: false, className: "w-[8%]" },
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
export type BirthdayRow = {
|
||||
id: number;
|
||||
customerName: string | null;
|
||||
businessName: string | null;
|
||||
customerNo: string | null;
|
||||
contacts: string | null;
|
||||
contactsPhone: string | null;
|
||||
@@ -96,6 +97,8 @@ function renderCell(key: BirthdayColumnKey, row: BirthdayRow): ReactNode {
|
||||
switch (key) {
|
||||
case "customerName":
|
||||
return <span className="block break-words font-medium whitespace-normal">{text(row.customerName)}</span>;
|
||||
case "businessName":
|
||||
return <span className="block break-words font-medium whitespace-normal">{text(row.businessName)}</span>;
|
||||
case "customerNo":
|
||||
return <span className="block break-all whitespace-normal">{text(row.customerNo)}</span>;
|
||||
case "contacts":
|
||||
@@ -286,6 +289,11 @@ export function BirthdayList({ rows }: { rows: BirthdayRow[] }) {
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="break-words font-medium whitespace-normal">{text(row.customerName)}</div>
|
||||
{visible.includes("businessName") && row.businessName ? (
|
||||
<div className="mt-0.5 break-words text-xs text-[var(--color-muted-foreground)]">
|
||||
经营名称 {text(row.businessName)}
|
||||
</div>
|
||||
) : null}
|
||||
{visible.includes("customerNo") && (
|
||||
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||
编号 {text(row.customerNo)}
|
||||
@@ -298,7 +306,13 @@ export function BirthdayList({ rows }: { rows: BirthdayRow[] }) {
|
||||
</div>
|
||||
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
|
||||
{ordered
|
||||
.filter((c) => c.key !== "customerName" && c.key !== "customerNo" && c.key !== "birthday")
|
||||
.filter(
|
||||
(c) =>
|
||||
c.key !== "customerName" &&
|
||||
c.key !== "businessName" &&
|
||||
c.key !== "customerNo" &&
|
||||
c.key !== "birthday"
|
||||
)
|
||||
.map((col) => (
|
||||
<div key={col.key} className={col.key === "detail" || col.key === "remark" ? "col-span-2" : undefined}>
|
||||
<dt className="text-xs text-[var(--color-muted-foreground)]">{col.label}</dt>
|
||||
|
||||
@@ -32,6 +32,7 @@ export default async function BirthdayPage({
|
||||
SELECT
|
||||
id,
|
||||
customer_name AS customerName,
|
||||
business_name AS businessName,
|
||||
customer_no AS customerNo,
|
||||
contacts,
|
||||
contacts_phone AS contactsPhone,
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { ActionState } from "./actions";
|
||||
|
||||
type CustomerValues = {
|
||||
customerName?: string | null;
|
||||
businessName?: string | null;
|
||||
customerNo?: string | null;
|
||||
contacts?: string | null;
|
||||
contactsPhone?: string | null;
|
||||
@@ -101,20 +102,25 @@ export function CustomerForm({
|
||||
<FormSection title="基本">
|
||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<Field
|
||||
label="商户名称"
|
||||
label="商户注名称"
|
||||
name="customerName"
|
||||
defaultValue={v.customerName}
|
||||
required
|
||||
pattern={requireAll ? "\\S+" : undefined}
|
||||
title={requireAll ? "商户名称不能包含空格" : undefined}
|
||||
title={requireAll ? "商户注名称不能包含空格" : undefined}
|
||||
/>
|
||||
<Field
|
||||
label="商户经营名称"
|
||||
name="businessName"
|
||||
defaultValue={v.businessName}
|
||||
required
|
||||
/>
|
||||
<Field
|
||||
label="商户编号"
|
||||
name="customerNo"
|
||||
defaultValue={v.customerNo}
|
||||
required
|
||||
pattern="[A-Za-z0-9]+"
|
||||
title="只能填写数字和字母,区分大小写,位数不限"
|
||||
title="只能填写数字和字母,区分大小写,位数不限;可不填"
|
||||
/>
|
||||
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
||||
<Field
|
||||
|
||||
@@ -9,6 +9,7 @@ import { fmtDate, cn } from "@/lib/utils";
|
||||
type CustomerViewProps = {
|
||||
customer: {
|
||||
customerName?: string | null;
|
||||
businessName?: string | null;
|
||||
customerNo?: string | null;
|
||||
contacts?: string | null;
|
||||
contactsPhone?: string | null;
|
||||
@@ -43,7 +44,7 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
||||
}, [open]);
|
||||
|
||||
// 各分区是否至少有一个字段,用于隐藏整块为空的小标题
|
||||
const hasBasic = !!(customer.customerName || customer.customerNo || customer.detail);
|
||||
const hasBasic = !!(customer.customerName || customer.businessName || customer.customerNo || customer.detail);
|
||||
const hasContacts = !!(customer.contacts || customer.contactsPhone);
|
||||
const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone);
|
||||
const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate);
|
||||
@@ -80,7 +81,8 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
||||
<CardContent>
|
||||
{hasBasic && (
|
||||
<Section title="基本">
|
||||
<InfoRow label="商户名称" value={customer.customerName} />
|
||||
<InfoRow label="商户注名称" value={customer.customerName} />
|
||||
<InfoRow label="商户经营名称" value={customer.businessName} />
|
||||
<InfoRow label="商户编号" value={customer.customerNo} />
|
||||
<InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" />
|
||||
</Section>
|
||||
|
||||
@@ -32,6 +32,7 @@ export async function GET(req: NextRequest) {
|
||||
for (const c of rows) {
|
||||
aoa.push([
|
||||
c.customerName ?? "",
|
||||
c.businessName ?? "",
|
||||
c.customerNo ?? "",
|
||||
c.contacts ?? "",
|
||||
c.contactsPhone ?? "",
|
||||
|
||||
@@ -64,7 +64,8 @@ export default async function CustomersPage({
|
||||
<Table striped bordered>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>商户名称</TH>
|
||||
<TH>商户注名称</TH>
|
||||
<TH>商户经营名称</TH>
|
||||
<TH>商户编号</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>结算人</TH>
|
||||
@@ -81,7 +82,7 @@ export default async function CustomersPage({
|
||||
<tbody>
|
||||
{rows.length === 0 && (
|
||||
<tr>
|
||||
<TD colSpan={12} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
<TD colSpan={13} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
暂无数据
|
||||
</TD>
|
||||
</tr>
|
||||
@@ -92,6 +93,7 @@ export default async function CustomersPage({
|
||||
return (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD className="font-medium">{c.businessName || "—"}</TD>
|
||||
<TD className="font-medium break-all">{c.customerNo || "—"}</TD>
|
||||
<TD>
|
||||
<div>{c.contacts}</div>
|
||||
@@ -148,6 +150,11 @@ export default async function CustomersPage({
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-medium">{c.customerName}</div>
|
||||
{c.businessName ? (
|
||||
<div className="mt-0.5 truncate text-xs text-[var(--color-muted-foreground)]">
|
||||
经营名称 {c.businessName}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||
编号 {c.customerNo || "—"}
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,7 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
|
||||
if (keyword) {
|
||||
where.OR = [
|
||||
{ customerName: { contains: keyword } },
|
||||
{ businessName: { contains: keyword } },
|
||||
{ customerNo: { contains: keyword } },
|
||||
{ contacts: { contains: keyword } },
|
||||
{ contactsPhone: { contains: keyword } },
|
||||
@@ -32,7 +33,8 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
|
||||
|
||||
/** 导出/导入的列定义(表头 ↔ 字段) */
|
||||
export const EXCEL_COLUMNS: { header: string; key: string }[] = [
|
||||
{ header: "商户名称", key: "customerName" },
|
||||
{ header: "商户注名称", key: "customerName" },
|
||||
{ header: "商户经营名称", key: "businessName" },
|
||||
{ header: "商户编号", key: "customerNo" },
|
||||
{ header: "联系人", key: "contacts" },
|
||||
{ header: "联系人电话", key: "contactsPhone" },
|
||||
|
||||
@@ -9,7 +9,8 @@ export async function GET() {
|
||||
}
|
||||
|
||||
const headers = [
|
||||
"商户名称",
|
||||
"商户注名称",
|
||||
"商户经营名称",
|
||||
"商户编号",
|
||||
"联系人",
|
||||
"联系人电话",
|
||||
@@ -26,7 +27,8 @@ export async function GET() {
|
||||
|
||||
// 示例行(用户导入前需删除此行)
|
||||
const example = [
|
||||
"模板名称_此行删除",
|
||||
"模板注名称_此行删除",
|
||||
"模板经营名称",
|
||||
"Ab12Cd",
|
||||
"侯磊",
|
||||
"13813855555",
|
||||
|
||||
@@ -129,7 +129,8 @@ export default async function DashboardPage() {
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>商户名称</TH>
|
||||
<TH>商户注名称</TH>
|
||||
<TH>商户经营名称</TH>
|
||||
<TH>商户编号</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>业务员</TH>
|
||||
@@ -141,6 +142,7 @@ export default async function DashboardPage() {
|
||||
{recent.map((c) => (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD className="font-medium">{c.businessName || "—"}</TD>
|
||||
<TD className="break-all">{c.customerNo || "—"}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD>{c.salesman}</TD>
|
||||
@@ -161,6 +163,11 @@ export default async function DashboardPage() {
|
||||
<div key={c.id} className="flex items-start justify-between gap-3 px-4 py-3">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-medium">{c.customerName}</div>
|
||||
{c.businessName ? (
|
||||
<div className="mt-0.5 truncate text-xs text-[var(--color-muted-foreground)]">
|
||||
经营名称 {c.businessName}
|
||||
</div>
|
||||
) : null}
|
||||
{c.customerNo ? (
|
||||
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||
编号 {c.customerNo}
|
||||
|
||||
Reference in New Issue
Block a user