优化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { apiBlobRequest, apiRequest } from '@/api/http'
|
||||
import { ApiError, apiBlobRequest, apiBlobResponseRequest, apiRequest } from '@/api/http'
|
||||
|
||||
export type ApiFirstLegStatus = 'DRAFT' | 'SUBMITTED' | 'APPROVED' | 'ACCEPTED' | 'REJECTED' | 'CANCELLED' | 'PROCESSING' | 'COMPLETED'
|
||||
export type ApiTransportMode = 'SEA' | 'AIR' | 'RAIL' | 'TRUCK'
|
||||
@@ -205,6 +205,18 @@ export interface MerchantFirstLegOrder {
|
||||
referenceId: string | null
|
||||
expressCompany?: string | null
|
||||
expressTrackingNo?: string | null
|
||||
skuNos?: string[] | null
|
||||
totalPackageCount?: number | null
|
||||
totalGrossWeightKg?: number | null
|
||||
totalNetWeightKg?: number | null
|
||||
totalVolumeCbm?: number | null
|
||||
totalQuantity?: number | null
|
||||
chargeableWeightKg?: number | null
|
||||
chargeableVolumeCbm?: number | null
|
||||
inboundCode?: string | null
|
||||
inboundedAt?: string | null
|
||||
businessDate?: string | null
|
||||
internationalOrderNo?: string | null
|
||||
submittedAt?: string | null
|
||||
completedAt?: string | null
|
||||
version: number
|
||||
@@ -212,6 +224,40 @@ export interface MerchantFirstLegOrder {
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface MerchantFirstLegOrderRow {
|
||||
orderId: number | string
|
||||
orderNo: string | null
|
||||
packageCount: number | null
|
||||
weightKg: number | null
|
||||
inboundId: number | string | null
|
||||
inboundCode: string | null
|
||||
channelName: string | null
|
||||
destinationType: ApiDestinationType | null
|
||||
customerName: string | null
|
||||
receivingCompanyName: string | null
|
||||
specificationModel: string | null
|
||||
status: ApiFirstLegStatus
|
||||
totalQuantity: number | null
|
||||
totalGrossWeightKg: number | null
|
||||
totalNetWeightKg: number | null
|
||||
totalVolumeCbm: number | null
|
||||
trackingNo: string | null
|
||||
internationalOrderNo: string | null
|
||||
referenceId: string | null
|
||||
remark: string | null
|
||||
destinationWarehouseName: string | null
|
||||
expressCompany: string | null
|
||||
skuNos: string | string[] | null
|
||||
chargeableWeightKg: number | null
|
||||
chargeableVolumeCbm: number | null
|
||||
billingUnitPrice: number | null
|
||||
inboundedAt: string | null
|
||||
businessDate: string | null
|
||||
shipmentId: string | null
|
||||
createdAt: string
|
||||
cargoes?: Array<{ skuNo?: string | null }>
|
||||
}
|
||||
|
||||
export interface MerchantFirstLegOrderCargo extends FirstLegOrderCargoPayload {
|
||||
id: number | string
|
||||
itemNo: number
|
||||
@@ -251,6 +297,66 @@ export function downloadMerchantProductImage(fileId: number | string) {
|
||||
return apiBlobRequest({ method: 'GET', url: `/merchant/v1/files/product-images/${fileId}` })
|
||||
}
|
||||
|
||||
export async function downloadMerchantInboundCartonLabels(inboundId: number | string) {
|
||||
return downloadMerchantCartonLabelPdf(
|
||||
`/merchant/v1/first-leg/inbounds/${encodeURIComponent(String(inboundId))}/carton-label-pdf`,
|
||||
)
|
||||
}
|
||||
|
||||
export async function downloadMerchantOrderCartonLabels(orderId: number | string) {
|
||||
return downloadMerchantCartonLabelPdf(
|
||||
`/merchant/v1/first-leg/orders/${encodeURIComponent(String(orderId))}/carton-label-pdf`,
|
||||
)
|
||||
}
|
||||
|
||||
export async function downloadMerchantOrderCartonLabelsBatch(orderIds: Array<number | string>) {
|
||||
const response = await apiBlobResponseRequest({
|
||||
method: 'POST',
|
||||
url: '/merchant/v1/first-leg/orders/carton-label-pdf',
|
||||
data: orderIds.map(String),
|
||||
timeout: 120_000,
|
||||
})
|
||||
await requirePdfBlob(response.blob)
|
||||
return {
|
||||
blob: response.blob,
|
||||
failureCount: Number(response.headers['x-carton-label-failure-count'] ?? 0),
|
||||
failures: String(response.headers['x-carton-label-failures'] ?? ''),
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadMerchantCartonLabelPdf(url: string) {
|
||||
const blob = await apiBlobRequest({
|
||||
method: 'POST',
|
||||
url,
|
||||
data: null,
|
||||
timeout: 60_000,
|
||||
})
|
||||
await requirePdfBlob(blob)
|
||||
return blob
|
||||
}
|
||||
|
||||
async function requirePdfBlob(blob: Blob) {
|
||||
const signature = new TextDecoder().decode(await blob.slice(0, 5).arrayBuffer())
|
||||
if (signature === '%PDF-') return
|
||||
|
||||
const text = await blob.text()
|
||||
try {
|
||||
const error = JSON.parse(text) as { code?: unknown; message?: unknown; traceId?: unknown }
|
||||
if (typeof error.message === 'string') {
|
||||
throw new ApiError(
|
||||
error.message || '箱唛生成失败',
|
||||
typeof error.code === 'string' ? error.code : 'INVALID_PDF',
|
||||
undefined,
|
||||
undefined,
|
||||
typeof error.traceId === 'string' ? error.traceId : null,
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError) throw error
|
||||
}
|
||||
throw new ApiError('箱唛服务未返回有效的 PDF 文件', 'INVALID_PDF')
|
||||
}
|
||||
|
||||
export interface FirstLegOrderQuery {
|
||||
keyword?: string
|
||||
status?: ApiFirstLegStatus
|
||||
@@ -330,7 +436,7 @@ export function estimateMerchantFirstLegPrice(payload: MerchantPriceEstimateRequ
|
||||
}
|
||||
|
||||
export function getMerchantFirstLegOrders(params: FirstLegOrderQuery = {}) {
|
||||
return apiRequest<PageResult<MerchantFirstLegOrder>>({ method: 'GET', url: '/merchant/v1/orders/first-leg', params: { page: 1, size: 200, ...params } })
|
||||
return apiRequest<PageResult<MerchantFirstLegOrderRow>>({ method: 'GET', url: '/merchant/v1/orders/first-leg', params: { page: 1, size: 200, ...params } })
|
||||
}
|
||||
|
||||
export function getMerchantFirstLegOrder(id: number | string) {
|
||||
|
||||
@@ -73,6 +73,15 @@ export interface MerchantUnifiedOrderRow {
|
||||
totalPackageCount: number | null
|
||||
actualGrossWeightKg: number | null
|
||||
actualVolumeCbm: number | null
|
||||
skuNos?: string[] | null
|
||||
expressCompany?: string | null
|
||||
totalNetWeightKg?: number | null
|
||||
totalQuantity?: number | null
|
||||
chargeableVolumeCbm?: number | null
|
||||
shipmentId?: string | null
|
||||
referenceId?: string | null
|
||||
inboundedAt?: string | null
|
||||
businessDate?: string | null
|
||||
measurement: MerchantUnifiedMeasurementSummary | null
|
||||
preload: MerchantUnifiedPreloadSummary | null
|
||||
loading: MerchantUnifiedLoadingSummary | null
|
||||
|
||||
Reference in New Issue
Block a user