Files
client-web/src/modules/first-leg/api/unifiedOrders.ts
T

227 lines
6.7 KiB
TypeScript

import { apiRequest } from '@/api/http'
import type { ApiContainerMode, ApiDestinationType, ApiFirstLegStatus, ApiPickupMethod, ApiTaxMode, MerchantFirstLegOrderDetail, PageResult } from '@/modules/first-leg/api/firstLeg'
export type ApiUnifiedOrderMainStatus =
| 'PENDING_REVIEW'
| 'WAIT_MEASURE'
| 'WAIT_PALLETIZE'
| 'WAIT_SPLIT'
| 'LOADING'
| 'LOADED'
| 'DELIVERED'
| 'COMPLETED'
export interface MerchantUnifiedMeasurementSummary {
reviewStatus: string | null
actualGrossWeightKg: number | null
actualVolumeCbm: number | null
chargeableWeightKg: number | null
completedAt: string | null
}
export interface MerchantUnifiedPreloadSummary {
status: string
version: number
itemCount: number
updatedAt: string | null
}
export interface MerchantUnifiedLoadingSummary {
status: string
loadingVersion: number
pickingVersion: number
expectedCount: number | null
pickedCount: number | null
evidenceCount: number | null
sealNo: string | null
updatedAt: string | null
}
export interface MerchantUnifiedDeliverySummary {
status: string
completedAt: string | null
trackingNo: string | null
}
export interface MerchantUnifiedTransportSummary {
containerNo: string | null
cabinetNo: string | null
vesselName: string | null
voyageNo: string | null
estimatedSailingAt: string | null
actualSailingAt: string | null
effectiveSailingAt: string | null
effectiveSailingAtEstimated: boolean | null
estimatedPortArrivalAt: string | null
actualPortArrivalAt: string | null
effectivePortArrivalAt: string | null
effectivePortArrivalAtEstimated: boolean | null
}
export interface MerchantUnifiedOrderRow {
orderId: number | string
orderVersion: number
tenantId: number | string
orderNo: string | null
fulfillmentType?: 'STANDARD' | 'ONE_CLICK_DROPSHIP' | null
lxCode?: string | null
mainStatus: ApiUnifiedOrderMainStatus | 'DRAFT' | 'CANCELLED'
nextAction: string | null
customerFeeConfirmationRequired: boolean
internalOrderStatus: ApiFirstLegStatus | null
customerId: number | string | null
customerName: string
channelName: string | null
receivingWarehouseId: number | string | null
receivingWarehouseName: string | null
destinationWarehouseId: number | string | null
destinationWarehouseName: string | null
inboundId: number | string | null
inboundVersion: number | null
inboundCode: string | null
expectedShipDate: string | null
totalPackageCount: number | null
actualGrossWeightKg: number | null
actualVolumeCbm: number | null
pickupMethod: ApiPickupMethod | null
taxMode: ApiTaxMode | null
customsInspection: boolean | null
requestedPickupAt: string | null
containerMode: ApiContainerMode | null
destinationType: ApiDestinationType | null
destinationCode: string | null
skuNos: string[] | null
expressCompany: string | null
expressTrackingNo: string | null
totalNetWeightKg: number | null
totalQuantity: number | null
chargeableVolumeCbm: number | null
shipmentId: string | null
referenceId: string | null
inboundCompletedAt: string | null
measurement: MerchantUnifiedMeasurementSummary | null
preload: MerchantUnifiedPreloadSummary | null
loading: MerchantUnifiedLoadingSummary | null
delivery: MerchantUnifiedDeliverySummary | null
transport: MerchantUnifiedTransportSummary | null
customerRemark: string | null
createdAt: string
updatedAt: string
}
export interface MerchantUnifiedTimelineEvent {
source: string
eventType: string
mainStatus: ApiUnifiedOrderMainStatus | null
action: string | null
remark: string | null
operatorId: number | string | null
operatorName: string | null
occurredAt: string | null
}
export interface MerchantUnifiedCustomNode {
id: number | string
name: string
nodeType: string
sortOrder: number
customerVisible: boolean
plannedAt: string | null
completedAt: string | null
operatorName: string | null
remark: string | null
attachmentIds: Array<number | string>
}
export interface MerchantTransportNode {
standardNode: string
nodeSequence: number
providerCode: string | null
estimatedAt: string | null
actualAt: string | null
locationCode: string | null
locationName: string | null
}
export interface MerchantTransportFragment {
inboundCode: string | null
cabinetNo: string | null
containerNo: string | null
nodes: MerchantTransportNode[]
}
export interface MerchantUnifiedOrderDetail {
progress: MerchantOrderProgress
transportFragments: MerchantTransportFragment[]
summary: MerchantUnifiedOrderRow
order: MerchantFirstLegOrderDetail
timeline: MerchantUnifiedTimelineEvent[]
// C02 does not return custom nodes yet. Optionality keeps the client forward-compatible without inventing data.
customNodes?: MerchantUnifiedCustomNode[]
}
export interface MerchantUnifiedOrderQuery {
taxMode?: ApiTaxMode
loaded?: boolean
keyword?: string
fbaCode?: string
orderNo?: string
inboundCode?: string
mainStatus?: ApiUnifiedOrderMainStatus
receivingWarehouseId?: number | string
destinationWarehouseId?: number | string
createdFrom?: string
createdTo?: string
page?: number
size?: number
}
const unifiedOrderBaseUrl = '/merchant/v1/orders'
export type OrderQueue = 'all' | 'fee' | 'customs' | 'draft' | 'loaded' | 'declared' | 'cleared' | 'scheduled' | 'delivering' | 'delivered'
export type OrderProgressStage = 'none' | 'loaded' | 'declared' | 'cleared' | 'scheduled' | 'delivering' | 'delivered'
export interface MerchantOrderProgress { orderId: string | number; stage: OrderProgressStage; partial: boolean }
export type OrderQueueCounts = Record<OrderQueue, number>
export interface MerchantOrderWorkbenchQuery {
cargoKeyword?: string
receivingWarehouseId?: string
channelName?: string
destinationType?: string
trackingNumber?: string
mainStatus?: string
createdFrom?: string
createdTo?: string
queue?: OrderQueue
page?: number
size?: number
}
export interface MerchantOrderWorkbench {
page: PageResult<MerchantUnifiedOrderRow>
queues: OrderQueueCounts
progress: MerchantOrderProgress[]
channelNames: string[]
}
export function getMerchantOrderWorkbench(params: MerchantOrderWorkbenchQuery = {}) {
return apiRequest<MerchantOrderWorkbench>({ method: 'GET', url: `${unifiedOrderBaseUrl}/workbench`,
params: { ...params, page: params.page ?? 1, size: params.size ?? 10 } })
}
export function getMerchantUnifiedOrders(params: MerchantUnifiedOrderQuery = {}) {
const { page, size, ...filters } = params
return apiRequest<PageResult<MerchantUnifiedOrderRow>>({
method: 'GET',
url: unifiedOrderBaseUrl,
params: { page: page ?? 1, size: size ?? 200, ...filters },
})
}
export function getMerchantUnifiedOrder(orderId: number | string) {
return apiRequest<MerchantUnifiedOrderDetail>({
method: 'GET',
url: `${unifiedOrderBaseUrl}/${orderId}`,
})
}