feat(customers): 联系人/结算人各自独立手机号
- customers 表新增 contacts_phone / balance_user_phone 两列(sql/add-contact-phones.sql) - 新增表单拆出"联系人信息/结算人信息"分区,手机号必填并校验 11 位;编辑选填 - 列表联系人/结算人列改为姓名+手机号两行展示,沿用业务员脱敏规则 - 查看弹窗同步分区并在服务端预脱敏,旧公共 phone 不再下发客户端 - 生日提醒页按生日归属展示对应人姓名+手机号,空值回退旧 phone - 导入模板/导出增加两个新列,保留"联系电话"表头兼容旧导入文件 - 旧 phone 列保留历史数据,界面不再录入/展示 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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<void> {
|
||||
const HEADER_MAP: Record<string, string> = {
|
||||
商户名称: "customerName",
|
||||
联系人: "contacts",
|
||||
联系人电话: "contactsPhone",
|
||||
结算人: "balanceUser",
|
||||
结算人电话: "balanceUserPhone",
|
||||
// 旧公共电话字段:仅兼容老版导入文件,界面已不再录入/展示
|
||||
联系电话: "phone",
|
||||
产品明细: "detail",
|
||||
押金: "deposit",
|
||||
@@ -174,7 +180,9 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
||||
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,
|
||||
|
||||
@@ -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({
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>商户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>联系电话</TH>
|
||||
<TH>归属人</TH>
|
||||
<TH>业务员</TH>
|
||||
<TH>生日</TH>
|
||||
<TH>历法</TH>
|
||||
@@ -93,16 +98,25 @@ export default async function BirthdayPage({
|
||||
<tbody>
|
||||
{rows.length === 0 && (
|
||||
<tr>
|
||||
<TD colSpan={7} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
<TD colSpan={6} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
该时段暂无生日商户
|
||||
</TD>
|
||||
</tr>
|
||||
)}
|
||||
{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 (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD className="tabular-nums">{superAdmin ? c.phone : maskPhone(c.phone)}</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>
|
||||
@@ -112,7 +126,8 @@ export default async function BirthdayPage({
|
||||
</TD>
|
||||
<TD>{c.birthdayOwner === 1 ? "结算人" : "联系人"}</TD>
|
||||
</TR>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
<Field label="联系人" name="contacts" defaultValue={v.contacts} required />
|
||||
<Field label="结算人" name="balanceUser" defaultValue={v.balanceUser} required />
|
||||
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
||||
<Field
|
||||
label="联系电话"
|
||||
name="phone"
|
||||
defaultValue={v.phone}
|
||||
required={requireAll}
|
||||
pattern={requireAll ? "1\\d{10}" : undefined}
|
||||
inputMode={requireAll ? "numeric" : undefined}
|
||||
title={requireAll ? "请输入 11 位手机号" : undefined}
|
||||
/>
|
||||
<Field
|
||||
label="报单日期"
|
||||
name="reportDate"
|
||||
@@ -129,6 +119,36 @@ export function CustomerForm({
|
||||
</div>
|
||||
</FormSection>
|
||||
|
||||
<FormSection title="联系人信息">
|
||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<Field label="姓名" name="contacts" defaultValue={v.contacts} required />
|
||||
<Field
|
||||
label="手机号"
|
||||
name="contactsPhone"
|
||||
defaultValue={v.contactsPhone}
|
||||
required={requireAll}
|
||||
pattern={requireAll ? "1\\d{10}" : undefined}
|
||||
inputMode={requireAll ? "numeric" : undefined}
|
||||
title={requireAll ? "请输入 11 位手机号" : undefined}
|
||||
/>
|
||||
</div>
|
||||
</FormSection>
|
||||
|
||||
<FormSection title="结算人信息">
|
||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<Field label="姓名" name="balanceUser" defaultValue={v.balanceUser} required />
|
||||
<Field
|
||||
label="手机号"
|
||||
name="balanceUserPhone"
|
||||
defaultValue={v.balanceUserPhone}
|
||||
required={requireAll}
|
||||
pattern={requireAll ? "1\\d{10}" : undefined}
|
||||
inputMode={requireAll ? "numeric" : undefined}
|
||||
title={requireAll ? "请输入 11 位手机号" : undefined}
|
||||
/>
|
||||
</div>
|
||||
</FormSection>
|
||||
|
||||
<FormSection title="生日">
|
||||
<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">
|
||||
|
||||
@@ -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 && (
|
||||
<Section title="基本">
|
||||
<InfoRow label="商户名称" value={customer.customerName} />
|
||||
<InfoRow label="联系人" value={customer.contacts} />
|
||||
<InfoRow label="结算人" value={customer.balanceUser} />
|
||||
<InfoRow label="联系电话" value={customer.phone} />
|
||||
<InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" />
|
||||
</Section>
|
||||
)}
|
||||
{hasContacts && (
|
||||
<Section title="联系人信息">
|
||||
<InfoRow label="姓名" value={customer.contacts} />
|
||||
<InfoRow label="手机号" value={customer.contactsPhone} />
|
||||
</Section>
|
||||
)}
|
||||
{hasBalanceUser && (
|
||||
<Section title="结算人信息">
|
||||
<InfoRow label="姓名" value={customer.balanceUser} />
|
||||
<InfoRow label="手机号" value={customer.balanceUserPhone} />
|
||||
</Section>
|
||||
)}
|
||||
{customer.birthday && (
|
||||
<Section title="生日">
|
||||
<InfoRow label="生日类型" value={birthdayLabel} />
|
||||
|
||||
@@ -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 ?? "",
|
||||
|
||||
@@ -66,7 +66,6 @@ export default async function CustomersPage({
|
||||
<TH>商户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>结算人</TH>
|
||||
<TH>联系电话</TH>
|
||||
<TH>产品明细</TH>
|
||||
<TH>押金</TH>
|
||||
<TH>买断</TH>
|
||||
@@ -80,17 +79,29 @@ 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={11} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
暂无数据
|
||||
</TD>
|
||||
</tr>
|
||||
)}
|
||||
{rows.map((c) => (
|
||||
{rows.map((c) => {
|
||||
// 旧公共 phone 已停用,不随序列化下发到客户端
|
||||
const { phone: _legacyPhone, ...rest } = c;
|
||||
return (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD>{c.balanceUser}</TD>
|
||||
<TD className="tabular-nums">{superAdmin ? c.phone : maskPhone(c.phone)}</TD>
|
||||
<TD>
|
||||
<div>{c.contacts}</div>
|
||||
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||
{superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone)}
|
||||
</div>
|
||||
</TD>
|
||||
<TD>
|
||||
<div>{c.balanceUser}</div>
|
||||
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||
{superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone)}
|
||||
</div>
|
||||
</TD>
|
||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.detail}</TD>
|
||||
<TD>{c.deposit}</TD>
|
||||
<TD>{c.buy}</TD>
|
||||
@@ -112,7 +123,14 @@ export default async function CustomersPage({
|
||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
|
||||
<TD>
|
||||
<div className="flex justify-end gap-1.5">
|
||||
<CustomerView customer={c} />
|
||||
{/* 弹窗展示用的手机号在服务端预脱敏,业务员拿不到明文 */}
|
||||
<CustomerView
|
||||
customer={{
|
||||
...rest,
|
||||
contactsPhone: superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone),
|
||||
balanceUserPhone: superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
||||
}}
|
||||
/>
|
||||
<Link href={`/customers/${c.id}/edit`}>
|
||||
<Button variant="outline" size="sm">编辑</Button>
|
||||
</Link>
|
||||
@@ -120,7 +138,8 @@ export default async function CustomersPage({
|
||||
</div>
|
||||
</TD>
|
||||
</TR>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user