@@ -467,13 +467,38 @@ export class TradeService {
|
||||
return serializeBigInt(updated);
|
||||
}
|
||||
|
||||
async confirmReceive(userId: bigint, orderId: bigint) {
|
||||
async confirmReceive(
|
||||
userId: bigint,
|
||||
orderId: bigint,
|
||||
opts?: { onSitePickup?: boolean },
|
||||
) {
|
||||
const order = await this.prisma.order.findFirst({ where: { id: orderId, userId } });
|
||||
if (!order) throw new NotFoundException('订单不存在');
|
||||
if (order.status !== 'PENDING_RECEIVE') {
|
||||
|
||||
const onSitePickup = !!opts?.onSitePickup;
|
||||
const onSiteEligible = [
|
||||
'PENDING_SHIP',
|
||||
'OUT_WAREHOUSE',
|
||||
'SHIPPING',
|
||||
'SHIPPED',
|
||||
'PENDING_RECEIVE',
|
||||
'DELIVERED',
|
||||
];
|
||||
if (onSitePickup) {
|
||||
if (!onSiteEligible.includes(order.status)) {
|
||||
throw new BadRequestException('当前状态不可现场取货');
|
||||
}
|
||||
} else if (!['PENDING_RECEIVE', 'DELIVERED'].includes(order.status)) {
|
||||
throw new BadRequestException('当前状态不可确认收货');
|
||||
}
|
||||
await this.applyStatusTransition(order.id, order.status, 'COMPLETED', 'USER');
|
||||
|
||||
await this.applyStatusTransition(
|
||||
order.id,
|
||||
order.status,
|
||||
'COMPLETED',
|
||||
onSitePickup ? 'USER_ON_SITE' : 'USER',
|
||||
onSitePickup ? '用户现场取货确认收货' : undefined,
|
||||
);
|
||||
return this.getOrder(userId, orderId);
|
||||
}
|
||||
|
||||
@@ -892,6 +917,7 @@ export class TradeService {
|
||||
fromStatus: string,
|
||||
targetStatus: string,
|
||||
operator = 'MOCK',
|
||||
remark?: string,
|
||||
) {
|
||||
const order = await this.prisma.order.findUnique({ where: { id: orderId } });
|
||||
if (!order) return;
|
||||
@@ -913,7 +939,7 @@ export class TradeService {
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
await tx.order.update({ where: { id: orderId }, data: data as never });
|
||||
if (Object.keys(deliveryData).length) {
|
||||
await tx.orderDelivery.update({ where: { orderId }, data: deliveryData as never });
|
||||
await tx.orderDelivery.updateMany({ where: { orderId }, data: deliveryData as never });
|
||||
}
|
||||
await tx.commonEvent.create({
|
||||
data: buildOrderStatusEvent({
|
||||
@@ -921,6 +947,7 @@ export class TradeService {
|
||||
fromStatus: currentStatus,
|
||||
toStatus: targetStatus,
|
||||
operator,
|
||||
remark,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user