refactor: 移除旧服务模型统一使用业务提供项

This commit is contained in:
que01 committed 2026-09-21 17:11:45 +08:00
1 parent ca85a583ce
commit 844a3bd715
13 files changed
+92 -146

No files matched your search

+15 -17
View File
@@ -12,13 +12,13 @@ export interface CreateBookingInput {
wechatId?: string;
contactPreference: "wechat" | "phone" | "none";
fulfillmentType?: "pickup" | "delivery";
serviceId?: string;
offeringId?: string;
requestedDate?: string;
requestedTime?: string;
deliveryAddress?: string;
note?: string;
extraData?: Prisma.InputJsonObject;
items?: Array<{ serviceId: string; quantity: number }>;
items?: Array<{ offeringId: string; quantity: number }>;
}
@Injectable()
@@ -52,27 +52,26 @@ export class BookingService {
) {
throw new BadRequestException("私厨需求必须填写日期、人数和地点");
}
const services = input.items?.length
? await this.prisma.service.findMany({
const offerings = input.items?.length
? await this.prisma.offering.findMany({
where: {
id: { in: input.items.map((item) => item.serviceId) },
id: { in: input.items.map((item) => item.offeringId) },
brandId,
isEnabled: true,
},
})
: [];
const serviceMap = new Map(services.map((service) => [service.id, service]));
const offeringMap = new Map(offerings.map((offering) => [offering.id, offering]));
const items = (input.items ?? []).map((item) => {
const service = serviceMap.get(item.serviceId);
if (!service || !service.bookingEnabled || service.priceAmount === null)
const offering = offeringMap.get(item.offeringId);
if (!offering || offering.priceAmount === null)
throw new BadRequestException("套餐不存在或暂不可预订");
return {
serviceId: service.id,
offeringId: service.offeringId,
serviceNameSnapshot: service.name,
unitPriceSnapshot: service.priceAmount,
offeringId: offering.id,
serviceNameSnapshot: offering.name,
unitPriceSnapshot: offering.priceAmount,
quantity: item.quantity,
subtotalSnapshot: service.priceAmount * item.quantity,
subtotalSnapshot: offering.priceAmount * item.quantity,
};
});
const estimatedAmount = items.reduce((sum, item) => sum + item.subtotalSnapshot, 0) || null;
@@ -89,8 +88,7 @@ export class BookingService {
wechatId: input.wechatId?.trim() ?? null,
contactPreference: input.contactPreference,
fulfillmentType: input.fulfillmentType ?? null,
serviceId: items[0]?.serviceId ?? input.serviceId ?? null,
offeringId: items[0]?.offeringId ?? null,
offeringId: items[0]?.offeringId ?? input.offeringId ?? null,
requestedDate: input.requestedDate
? new Date(`${input.requestedDate}T00:00:00.000Z`)
: null,
@@ -118,7 +116,7 @@ export class BookingService {
return this.prisma.booking.findMany({
where: { brandId, customerUserId },
orderBy: { createdAt: "desc" },
include: { items: true, service: { select: { name: true } } },
include: { items: true, offering: { select: { name: true } } },
});
}
@@ -165,7 +163,7 @@ export class BookingService {
async getForAdmin(brandId: string, id: string) {
const booking = await this.prisma.booking.findFirst({
where: { id, brandId },
include: { items: true, tags: { include: { tag: true } }, service: true },
include: { items: true, tags: { include: { tag: true } }, offering: true },
});
if (!booking) throw new NotFoundException("订单不存在");
return booking;