拦截伪区县写入与下单;推单失败挂 fulfillmentHold,HQ 可见超区/推单失败。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { BadRequestException, Injectable, Logger, NotFoundException, Inject, forwardRef } from '@nestjs/common';
|
||||
import type { CityWarehouse, FulfillmentProvider, Order } from '@prisma/client';
|
||||
import { isXfxProviderCode } from '@dukang/shared-types';
|
||||
import {
|
||||
FULFILLMENT_HOLD_COURIER_DISPATCH_FAILED,
|
||||
FULFILLMENT_HOLD_COURIER_OUT_OF_SERVICE,
|
||||
isXfxProviderCode,
|
||||
} from '@dukang/shared-types';
|
||||
import {
|
||||
BOTTLES_PER_BOX,
|
||||
XFX_AUTO_DISPATCH_MAX_BOXES,
|
||||
@@ -29,6 +33,7 @@ export type ManualShipInput = {
|
||||
export type HqLogisticsShipInput = ManualShipInput;
|
||||
|
||||
export const FULFILLMENT_HOLD_LARGE_ORDER = 'LARGE_ORDER_GE_10_BOXES';
|
||||
export { FULFILLMENT_HOLD_COURIER_OUT_OF_SERVICE, FULFILLMENT_HOLD_COURIER_DISPATCH_FAILED };
|
||||
|
||||
@Injectable()
|
||||
export class FulfillmentService {
|
||||
@@ -138,6 +143,7 @@ export class FulfillmentService {
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
await this.logDispatchFailure(order, provider, message);
|
||||
await this.markCourierDispatchHold(order.id, message);
|
||||
await this.ensureDeliveryRecord(order.id, 'MANUAL', provider.id);
|
||||
return;
|
||||
}
|
||||
@@ -213,6 +219,7 @@ export class FulfillmentService {
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
await this.logDispatchFailure(order, provider, message);
|
||||
await this.markCourierDispatchHold(order.id, message);
|
||||
await this.ensureDeliveryRecord(order.id, 'MANUAL', provider.id);
|
||||
}
|
||||
}
|
||||
@@ -559,6 +566,22 @@ export class FulfillmentService {
|
||||
});
|
||||
}
|
||||
|
||||
/** 自动推单失败:挂履约拦截,HQ 可见,避免静默 MANUAL 像「没推单」 */
|
||||
private async markCourierDispatchHold(orderId: bigint, error: string) {
|
||||
const outOfService = /超出服务区/.test(error);
|
||||
const reason = outOfService
|
||||
? FULFILLMENT_HOLD_COURIER_OUT_OF_SERVICE
|
||||
: FULFILLMENT_HOLD_COURIER_DISPATCH_FAILED;
|
||||
this.logger.warn(`承运商推单失败挂起:orderId=${orderId} reason=${reason} err=${error}`);
|
||||
await this.prisma.order.update({
|
||||
where: { id: orderId },
|
||||
data: {
|
||||
fulfillmentHold: true,
|
||||
fulfillmentHoldReason: reason,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async buildQueryUrlFromTemplate(warehouseId: bigint | null, trackingNo: string) {
|
||||
if (!warehouseId) return undefined;
|
||||
const wh = await this.prisma.cityWarehouse.findUnique({ where: { id: warehouseId } });
|
||||
|
||||
Reference in New Issue
Block a user