refactor: 统一客户→商户命名;字段一致;导入失败返回错误Excel
- 全局:客户→商户(表单/列表/查看/编辑/新增/导出/导航/品牌) - 字段统一:详情→产品明细、电话→联系电话、报单时间→报单日期 - 新增商户导入模板下载(/customers/template) - 导入失败时返回含错误列的 Excel,提示具体原因 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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",
|
||||
"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)}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user