feat: 建立预约工作流状态历史

This commit is contained in:
que01 committed 2026-09-21 15:03:46 +08:00
1 parent 0381c0a902
commit e9d3f77639
3 files changed
+93 -4

No files matched your search

+48 -4
View File
@@ -97,6 +97,14 @@ export class BookingService {
...(input.extraData ? { extraData: input.extraData } : {}),
note: input.note ?? null,
items: { create: items },
stateTransitions: {
create: {
workflowKey: "booking.basic",
workflowVersion: "1.0.0",
toState: "received",
actorRole: "customer",
},
},
},
select: { bookingNo: true, status: true, estimatedAmount: true, createdAt: true },
});
@@ -115,7 +123,23 @@ export class BookingService {
const booking = await this.prisma.booking.findFirst({ where: { id, brandId, customerUserId } });
if (!booking) throw new NotFoundException("订单不存在");
if (booking.status !== "received") throw new BadRequestException("当前状态不可取消");
return this.prisma.booking.update({ where: { id }, data: { status: "cancelled" } });
return this.prisma.$transaction(async (tx) => {
const updated = await tx.booking.update({
where: { id },
data: { status: "cancelled", currentState: "cancelled" },
});
await tx.bookingStateTransition.create({
data: {
bookingId: id,
workflowKey: booking.workflowKey,
workflowVersion: booking.workflowVersion,
fromState: booking.currentState,
toState: "cancelled",
actorRole: "customer",
},
});
return updated;
});
}
async listForAdmin(
@@ -164,9 +188,29 @@ export class BookingService {
};
if (status !== booking.status && !allowed[booking.status]?.includes(status))
throw new BadRequestException("不允许的订单状态流转");
return this.prisma.booking.update({
where: { id },
data: { status, ...(adminNote !== undefined ? { adminNote } : {}), isRead: true },
return this.prisma.$transaction(async (tx) => {
const updated = await tx.booking.update({
where: { id },
data: {
status,
currentState: status,
...(adminNote !== undefined ? { adminNote } : {}),
isRead: true,
},
});
if (status !== booking.currentState) {
await tx.bookingStateTransition.create({
data: {
bookingId: id,
workflowKey: booking.workflowKey,
workflowVersion: booking.workflowVersion,
fromState: booking.currentState,
toState: status,
actorRole: "admin",
},
});
}
return updated;
});
}