diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 55ce49b..ea150c8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -17,9 +17,11 @@ datasource db { model Customer { id Int @id @default(autoincrement()) customerName String? @default("") @map("customer_name") - contacts String? // 联系人 - balanceUser String? @map("balance_user") // 结算人 - phone String? + contacts String? // 联系人 + contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号 + balanceUser String? @map("balance_user") // 结算人 + balanceUserPhone String? @default("") @map("balance_user_phone") // 结算人手机号 + phone String? // 旧公共联系电话(已停用录入/展示,保留历史数据) detail String? deposit String? // 押金 buy String? // 买断 diff --git a/sql/add-contact-phones.sql b/sql/add-contact-phones.sql new file mode 100644 index 0000000..7ad00c0 --- /dev/null +++ b/sql/add-contact-phones.sql @@ -0,0 +1,12 @@ +-- 商户表增加联系人/结算人手机号 +-- 背景:contacts / balance_user 原来只有姓名,全表共用一个 phone 字段; +-- 改为联系人、结算人各自独立手机号。phone 列保留(历史数据不丢),界面不再展示。 +-- 执行:本地库与生产库均需执行;执行后运行 npm run prisma:generate(或 prisma db pull 校准) + +ALTER TABLE customers + ADD COLUMN contacts_phone VARCHAR(20) NOT NULL DEFAULT '' COMMENT '联系人手机号' AFTER contacts, + ADD COLUMN balance_user_phone VARCHAR(20) NOT NULL DEFAULT '' COMMENT '结算人手机号' AFTER balance_user; + +-- 可选:把旧公共 phone 回填到联系人手机号,避免历史号码在界面上彻底不可见(执行前请确认) +-- UPDATE customers SET contacts_phone = phone +-- WHERE contacts_phone = '' AND phone IS NOT NULL AND phone <> ''; diff --git a/src/app/(dashboard)/customers/actions.ts b/src/app/(dashboard)/customers/actions.ts index ea43603..0dd8b77 100644 --- a/src/app/(dashboard)/customers/actions.ts +++ b/src/app/(dashboard)/customers/actions.ts @@ -22,7 +22,8 @@ const schema = z.object({ .trim() .min(1, "报单日期必填") .refine((s) => parseDate(s) !== null, "报单日期格式应为 YYYY-MM-DD"), - phone: z.string().trim().optional().default(""), + contactsPhone: z.string().trim().optional().default(""), + balanceUserPhone: z.string().trim().optional().default(""), deposit: z.string().trim().optional().default(""), buy: z.string().trim().optional().default(""), birthdayType: z.coerce.number().int().min(1).max(2).default(1), @@ -31,7 +32,7 @@ const schema = z.object({ remark: z.string().trim().optional().default(""), }); -// 新增商户更严格:名称无空格、手机号必填 11 位、押金/买断/生日必填(仅用于创建,编辑仍用 schema) +// 新增商户更严格:名称无空格、联系人/结算人手机号必填 11 位、押金/买断/生日必填(仅用于创建,编辑仍用 schema) const createSchema = schema.extend({ customerName: z .string() @@ -39,7 +40,8 @@ const createSchema = schema.extend({ .min(1, "商户名称必填") .max(500) .refine((s) => !/\s/.test(s), "商户名称不能包含空格"), - phone: z.string().trim().regex(/^1\d{10}$/, "手机号必须为 11 位数字"), + contactsPhone: z.string().trim().regex(/^1\d{10}$/, "联系人手机号必须为 11 位数字"), + balanceUserPhone: z.string().trim().regex(/^1\d{10}$/, "结算人手机号必须为 11 位数字"), deposit: z.string().trim().min(1, "押金必填"), buy: z.string().trim().min(1, "买断必填"), birthday: z @@ -60,7 +62,8 @@ function pickForm(formData: FormData) { detail: formData.get("detail"), salesman: formData.get("salesman"), reportDate: formData.get("reportDate"), - phone: formData.get("phone") ?? "", + contactsPhone: formData.get("contactsPhone") ?? "", + balanceUserPhone: formData.get("balanceUserPhone") ?? "", deposit: formData.get("deposit") ?? "", buy: formData.get("buy") ?? "", birthdayType: formData.get("birthdayType") ?? 1, @@ -123,7 +126,10 @@ export async function deleteCustomer(id: number): Promise { const HEADER_MAP: Record = { 商户名称: "customerName", 联系人: "contacts", + 联系人电话: "contactsPhone", 结算人: "balanceUser", + 结算人电话: "balanceUserPhone", + // 旧公共电话字段:仅兼容老版导入文件,界面已不再录入/展示 联系电话: "phone", 产品明细: "detail", 押金: "deposit", @@ -174,7 +180,9 @@ export async function importCustomers(formData: FormData): Promise validData.push({ customerName: rec.customerName, contacts: rec.contacts || null, + contactsPhone: rec.contactsPhone || null, balanceUser: rec.balanceUser || null, + balanceUserPhone: rec.balanceUserPhone || null, phone: rec.phone || null, detail: rec.detail || null, deposit: rec.deposit || null, diff --git a/src/app/(dashboard)/customers/birthday/page.tsx b/src/app/(dashboard)/customers/birthday/page.tsx index 30f3536..0c0d5fd 100644 --- a/src/app/(dashboard)/customers/birthday/page.tsx +++ b/src/app/(dashboard)/customers/birthday/page.tsx @@ -13,7 +13,10 @@ type Row = { id: number; customerName: string | null; contacts: string | null; - phone: string | null; + contactsPhone: string | null; + balanceUser: string | null; + balanceUserPhone: string | null; + phone: string | null; // 旧公共电话,仅作新字段为空时的回退 salesman: string | null; reportDate: Date | null; birthday: Date | null; @@ -52,6 +55,9 @@ export default async function BirthdayPage({ id, customer_name AS customerName, contacts, + contacts_phone AS contactsPhone, + balance_user AS balanceUser, + balance_user_phone AS balanceUserPhone, phone, salesman, report_date AS reportDate, @@ -82,8 +88,7 @@ export default async function BirthdayPage({ 商户名称 - 联系人 - 联系电话 + 归属人 业务员 生日 历法 @@ -93,16 +98,25 @@ export default async function BirthdayPage({ {rows.length === 0 && ( - + 该时段暂无生日商户 )} - {rows.map((c) => ( + {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 ( {c.customerName} - {c.contacts} - {superAdmin ? c.phone : maskPhone(c.phone)} + +
{ownerName}
+
+ {superAdmin ? ownerPhone : maskPhone(ownerPhone)} +
+ {c.salesman} {fmtDate(c.birthday)} @@ -112,7 +126,8 @@ export default async function BirthdayPage({ {c.birthdayOwner === 1 ? "结算人" : "联系人"} - ))} + ); + })} diff --git a/src/app/(dashboard)/customers/customer-form.tsx b/src/app/(dashboard)/customers/customer-form.tsx index 86b09da..dc3c9b1 100644 --- a/src/app/(dashboard)/customers/customer-form.tsx +++ b/src/app/(dashboard)/customers/customer-form.tsx @@ -11,8 +11,9 @@ import type { ActionState } from "./actions"; type CustomerValues = { customerName?: string | null; contacts?: string | null; + contactsPhone?: string | null; balanceUser?: string | null; - phone?: string | null; + balanceUserPhone?: string | null; detail?: string | null; deposit?: string | null; buy?: string | null; @@ -107,18 +108,7 @@ export function CustomerForm({ pattern={requireAll ? "\\S+" : undefined} title={requireAll ? "商户名称不能包含空格" : undefined} /> - - - + +
+ + +
+
+ + +
+ + +
+
+
diff --git a/src/app/(dashboard)/customers/customer-view.tsx b/src/app/(dashboard)/customers/customer-view.tsx index 1e02b26..3314c50 100644 --- a/src/app/(dashboard)/customers/customer-view.tsx +++ b/src/app/(dashboard)/customers/customer-view.tsx @@ -10,8 +10,9 @@ type CustomerViewProps = { customer: { customerName?: string | null; contacts?: string | null; + contactsPhone?: string | null; balanceUser?: string | null; - phone?: string | null; + balanceUserPhone?: string | null; detail?: string | null; deposit?: string | null; buy?: string | null; @@ -41,7 +42,9 @@ export function CustomerView({ customer }: CustomerViewProps) { const birthdayOwnerLabel = customer.birthdayOwner === 1 ? "结算人" : "联系人"; // 各分区是否至少有一个字段,用于隐藏整块为空的小标题 - const hasBasic = !!(customer.customerName || customer.contacts || customer.balanceUser || customer.phone || customer.detail); + const hasBasic = !!(customer.customerName || customer.detail); + const hasContacts = !!(customer.contacts || customer.contactsPhone); + const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone); const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate); return ( @@ -77,12 +80,21 @@ export function CustomerView({ customer }: CustomerViewProps) { {hasBasic && (
- - -
)} + {hasContacts && ( +
+ + +
+ )} + {hasBalanceUser && ( +
+ + +
+ )} {customer.birthday && (
diff --git a/src/app/(dashboard)/customers/export/route.ts b/src/app/(dashboard)/customers/export/route.ts index 6595197..89e9257 100644 --- a/src/app/(dashboard)/customers/export/route.ts +++ b/src/app/(dashboard)/customers/export/route.ts @@ -33,8 +33,9 @@ export async function GET(req: NextRequest) { aoa.push([ c.customerName ?? "", c.contacts ?? "", + c.contactsPhone ?? "", c.balanceUser ?? "", - c.phone ?? "", + c.balanceUserPhone ?? "", c.detail ?? "", c.deposit ?? "", c.buy ?? "", diff --git a/src/app/(dashboard)/customers/page.tsx b/src/app/(dashboard)/customers/page.tsx index b808bf9..0ad94ed 100644 --- a/src/app/(dashboard)/customers/page.tsx +++ b/src/app/(dashboard)/customers/page.tsx @@ -66,7 +66,6 @@ export default async function CustomersPage({ 商户名称 联系人 结算人 - 联系电话 产品明细 押金 买断 @@ -80,17 +79,29 @@ export default async function CustomersPage({ {rows.length === 0 && ( - + 暂无数据 )} - {rows.map((c) => ( + {rows.map((c) => { + // 旧公共 phone 已停用,不随序列化下发到客户端 + const { phone: _legacyPhone, ...rest } = c; + return ( {c.customerName} - {c.contacts} - {c.balanceUser} - {superAdmin ? c.phone : maskPhone(c.phone)} + +
{c.contacts}
+
+ {superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone)} +
+ + +
{c.balanceUser}
+
+ {superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone)} +
+ {c.detail} {c.deposit} {c.buy} @@ -112,7 +123,14 @@ export default async function CustomersPage({ {c.remark}
- + {/* 弹窗展示用的手机号在服务端预脱敏,业务员拿不到明文 */} + @@ -120,7 +138,8 @@ export default async function CustomersPage({
- ))} + ); + })} diff --git a/src/app/(dashboard)/customers/query.ts b/src/app/(dashboard)/customers/query.ts index 76c7fa2..0fd106b 100644 --- a/src/app/(dashboard)/customers/query.ts +++ b/src/app/(dashboard)/customers/query.ts @@ -15,7 +15,9 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu where.OR = [ { customerName: { contains: keyword } }, { contacts: { contains: keyword } }, + { contactsPhone: { contains: keyword } }, { balanceUser: { contains: keyword } }, + { balanceUserPhone: { contains: keyword } }, { phone: { contains: keyword } }, { detail: { contains: keyword } }, { salesman: { contains: keyword } }, @@ -31,8 +33,9 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu export const EXCEL_COLUMNS: { header: string; key: string }[] = [ { header: "商户名称", key: "customerName" }, { header: "联系人", key: "contacts" }, + { header: "联系人电话", key: "contactsPhone" }, { header: "结算人", key: "balanceUser" }, - { header: "联系电话", key: "phone" }, + { header: "结算人电话", key: "balanceUserPhone" }, { header: "产品明细", key: "detail" }, { header: "押金", key: "deposit" }, { header: "买断", key: "buy" }, diff --git a/src/app/(dashboard)/customers/template/route.ts b/src/app/(dashboard)/customers/template/route.ts index e31e2f1..94a74ee 100644 --- a/src/app/(dashboard)/customers/template/route.ts +++ b/src/app/(dashboard)/customers/template/route.ts @@ -11,8 +11,9 @@ export async function GET() { const headers = [ "商户名称", "联系人", + "联系人电话", "结算人", - "联系电话", + "结算人电话", "产品明细", "押金", "买断", @@ -28,8 +29,9 @@ export async function GET() { const example = [ "模板名称_此行删除", "侯磊", - "张三", "13813855555", + "张三", + "13913966666", "POS+CRM", "100", "100",