From 2aafa871bca474cff6803b9c45d6adfe74c7b66d Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 22 Sep 2026 11:11:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E9=A1=B9=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/services/ServicesPage.tsx | 31 +++++++++++++++++-- apps/api/src/admin-workspace.controller.ts | 16 ++++++++++ packages/api-client/src/index.ts | 5 +++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/apps/admin/src/features/services/ServicesPage.tsx b/apps/admin/src/features/services/ServicesPage.tsx index 1bc7628..a69df4c 100644 --- a/apps/admin/src/features/services/ServicesPage.tsx +++ b/apps/admin/src/features/services/ServicesPage.tsx @@ -41,6 +41,18 @@ export function ServicesPage() { void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] }); }, }); + const deleteOffering = useMutation({ + mutationFn: (id: string) => client.deleteAdminOffering(id), + onSuccess: () => { + message.success("业务提供项已删除"); + void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] }); + }, + }); + const toggleOffering = useMutation({ + mutationFn: ({ id, isEnabled }: { id: string; isEnabled: boolean }) => + client.updateAdminOffering(id, { isEnabled }), + onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] }), + }); const beginOffering = (item?: Offering) => { setEditingOffering(item ?? null); setOfferingOpen(true); @@ -105,9 +117,22 @@ export function ServicesPage() { { title: "操作", render: (_: unknown, item: Offering) => ( - + + + + + ), }, ]} diff --git a/apps/api/src/admin-workspace.controller.ts b/apps/api/src/admin-workspace.controller.ts index dbbb3fd..27d0e9c 100644 --- a/apps/api/src/admin-workspace.controller.ts +++ b/apps/api/src/admin-workspace.controller.ts @@ -114,6 +114,22 @@ class AdminWorkspaceController { }, }); } + + @Delete("offerings/:id") + async deleteOffering(@Req() request: FastifyRequest, @Param("id") id: string): Promise { + this.requireAdmin(request); + const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); + if (!item) throw new BadRequestException("业务提供项不存在"); + const [forms, bookings, items] = await Promise.all([ + this.prisma.inquiryForm.count({ where: { offeringId: id } }), + this.prisma.booking.count({ where: { offeringId: id } }), + this.prisma.bookingItem.count({ where: { offeringId: id } }), + ]); + if (forms || bookings || items) + throw new BadRequestException("业务提供项已有业务记录,只能禁用不能删除"); + await this.prisma.offering.delete({ where: { id } }); + return { deleted: true }; + } private requireAdmin(request: FastifyRequest): void { const token = request.headers.authorization?.replace(/^Bearer\s+/i, ""); if (!token) throw new UnauthorizedException("缺少管理员登录态"); diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index f316e2f..86a9a6d 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -452,6 +452,11 @@ export class ApiClient { body, }); } + deleteAdminOffering(id: string): Promise<{ deleted: boolean }> { + return this.request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, { + method: "DELETE", + }); + } listAdminTrustContent(): Promise { return this.request("/admin/config/trust-content"); }