- 新增许可证服务器 (license-server/) - 新增 Agent 部署模块 (flnxi-agent/) - 添加许可证验证和激活页面 - 添加 Harbor 镜像同步脚本 - 更新素材系统支持许可证验证
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getAdminSession } from '@/lib/auth';
|
|
import { prisma } from '@/lib/db';
|
|
|
|
export async function GET() {
|
|
const session = await getAdminSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: '未授权' }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const customers = await prisma.customer.findMany({
|
|
orderBy: { createdAt: 'desc' },
|
|
include: {
|
|
_count: { select: { licenses: true } },
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ customers });
|
|
} catch (error) {
|
|
console.error('获取客户列表失败:', error);
|
|
return NextResponse.json({ error: '服务器错误' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const session = await getAdminSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: '未授权' }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const { companyName, contactName, contactEmail, contactPhone } = await request.json();
|
|
|
|
if (!companyName) {
|
|
return NextResponse.json(
|
|
{ success: false, error: '公司名称不能为空' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const customer = await prisma.customer.create({
|
|
data: {
|
|
companyName,
|
|
contactName: contactName || null,
|
|
contactEmail: contactEmail || null,
|
|
contactPhone: contactPhone || null,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ success: true, customer });
|
|
} catch (error) {
|
|
console.error('创建客户失败:', error);
|
|
return NextResponse.json({ success: false, error: '服务器错误' }, { status: 500 });
|
|
}
|
|
}
|