- customers 表新增 contacts_phone / balance_user_phone 两列(sql/add-contact-phones.sql) - 新增表单拆出"联系人信息/结算人信息"分区,手机号必填并校验 11 位;编辑选填 - 列表联系人/结算人列改为姓名+手机号两行展示,沿用业务员脱敏规则 - 查看弹窗同步分区并在服务端预脱敏,旧公共 phone 不再下发客户端 - 生日提醒页按生日归属展示对应人姓名+手机号,空值回退旧 phone - 导入模板/导出增加两个新列,保留"联系电话"表头兼容旧导入文件 - 旧 phone 列保留历史数据,界面不再录入/展示 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import * as XLSX from "xlsx";
|
|
import { auth } from "@/lib/auth";
|
|
|
|
/** 生成商户导入模板 Excel */
|
|
export async function GET() {
|
|
if (!(await auth())) {
|
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
|
}
|
|
|
|
const headers = [
|
|
"商户名称",
|
|
"联系人",
|
|
"联系人电话",
|
|
"结算人",
|
|
"结算人电话",
|
|
"产品明细",
|
|
"押金",
|
|
"买断",
|
|
"生日类型",
|
|
"生日归属",
|
|
"生日",
|
|
"业务员",
|
|
"报单日期",
|
|
"备注",
|
|
];
|
|
|
|
// 示例行(用户导入前需删除此行)
|
|
const example = [
|
|
"模板名称_此行删除",
|
|
"侯磊",
|
|
"13813855555",
|
|
"张三",
|
|
"13913966666",
|
|
"POS+CRM",
|
|
"100",
|
|
"100",
|
|
"阴历",
|
|
"联系人",
|
|
"生日格式要求:2022-06-21",
|
|
"A",
|
|
"报单日期格式要求:2022-06-21",
|
|
"导入备注",
|
|
];
|
|
|
|
const aoa: (string | number)[][] = [headers, example];
|
|
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
|
ws["!cols"] = headers.map(() => ({ wch: 18 }));
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, "商户导入模板");
|
|
const buf = XLSX.write(wb, { type: "buffer", bookType: "xlsx" }) as Buffer;
|
|
|
|
const filename = "商户导入模板.xlsx";
|
|
return new NextResponse(new Uint8Array(buf), {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type":
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"Content-Disposition": `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`,
|
|
},
|
|
});
|
|
}
|