2026-07-12 00:30:17 +08:00
|
|
|
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 = [
|
2026-09-22 13:29:55 +08:00
|
|
|
"商户注名称",
|
|
|
|
|
"商户经营名称",
|
2026-09-11 14:55:24 +08:00
|
|
|
"商户编号",
|
2026-07-12 00:30:17 +08:00
|
|
|
"联系人",
|
2026-07-19 23:45:20 +08:00
|
|
|
"联系人电话",
|
2026-07-12 00:30:17 +08:00
|
|
|
"结算人",
|
2026-07-19 23:45:20 +08:00
|
|
|
"结算人电话",
|
2026-07-12 00:30:17 +08:00
|
|
|
"产品明细",
|
|
|
|
|
"押金",
|
|
|
|
|
"买断",
|
|
|
|
|
"生日",
|
|
|
|
|
"业务员",
|
|
|
|
|
"报单日期",
|
|
|
|
|
"备注",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 示例行(用户导入前需删除此行)
|
|
|
|
|
const example = [
|
2026-09-22 13:29:55 +08:00
|
|
|
"模板注名称_此行删除",
|
|
|
|
|
"模板经营名称",
|
2026-09-11 14:55:24 +08:00
|
|
|
"Ab12Cd",
|
2026-07-12 00:30:17 +08:00
|
|
|
"侯磊",
|
|
|
|
|
"13813855555",
|
2026-07-19 23:45:20 +08:00
|
|
|
"张三",
|
|
|
|
|
"13913966666",
|
2026-07-12 00:30:17 +08:00
|
|
|
"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)}`,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|