Files
client-web/src/modules/order-management/api/deliveryOrders.ts
T

192 lines
4.5 KiB
TypeScript

import { apiBlobRequest, apiRequest } from '@/api/http'
export interface DeliveryReceiptFile {
fileId: string
fileName: string
contentType: string | null
sizeBytes: number
uploadedAt: string
}
export interface DeliveryReceipts {
deliveryNo: string
files: DeliveryReceiptFile[]
}
export function getDeliveryReceipts(deliveryNo: string) {
return apiRequest<DeliveryReceipts>({
method: 'GET',
url: `/merchant/v1/last-leg/delivery-orders/${encodeURIComponent(deliveryNo)}/documents/receipt`,
})
}
export function downloadDeliveryReceipt(deliveryNo: string, fileId: string) {
return apiBlobRequest({
method: 'GET',
url: `/merchant/v1/last-leg/delivery-orders/${encodeURIComponent(deliveryNo)}/documents/receipt/files/${encodeURIComponent(fileId)}/download`,
})
}
export interface PageResult<T> {
records: T[]
page: number
size: number
total: number
pages: number
}
export interface DeliveryRow {
id: string
deliveryNo: string
outboundNo: string | null
dispatchNo: string
overseasWarehouseName: string | null
status: string
waybillNo: string | null
deliveryMethod: string
carrierName: string | null
vehiclePlate: string | null
driverName: string | null
palletCount: number
packageCount: number
signedPackages: number | null
totalWeightKg: number | null
totalVolumeCbm: number | null
plannedDeliveryAt: string
expectedArrivalAt: string | null
signedAt: string | null
createdAt: string
}
export interface DeliveryOrderFee {
id?: string
feeType: string
currency: string
amount: number
remark?: string | null
}
export interface DeliveryOrderItem {
id?: string
palletNo?: string | null
inboundCode?: string | null
skuCode?: string | null
productName?: string | null
packageCount?: number | null
weightKg?: number | null
volumeCbm?: number | null
}
export interface DeliveryOrderDetail extends DeliveryRow {
pickupMethod: string
loadingType: string
vehicleType: string | null
vehicleSize: string | null
driverPhone: string | null
appointmentAccount: string | null
sellerName: string | null
remark: string | null
fees: DeliveryOrderFee[]
items?: DeliveryOrderItem[] | PageResult<DeliveryOrderItem>
updatedAt?: string | null
}
interface DeliveryOrderDetailResponse {
order: Omit<DeliveryOrderDetail, 'fees' | 'items' | 'updatedAt'>
skus: DeliveryOrderItem[]
fees: DeliveryOrderFee[]
operations: Array<{
id: string
operatedAt: string
operationNode: string
operatorName: string
result: string
}>
}
export interface DeliveryTransferResult {
dispatchNo: string
outboundNo: string
outboundStatus: string
deliveryNo: string
deliveryStatus: string
palletCount: number
packageCount: number
replayed: boolean
}
export interface DeliveryQuery {
page: number
size: number
documentNo?: string
warehouseId?: string
status?: string
dispatchNo?: string
waybillNo?: string
vehiclePlate?: string
driverName?: string
deliveryMethod?: string
plannedFrom?: string
plannedTo?: string
}
export function normalizeDeliveryPage(data: PageResult<DeliveryRow>): PageResult<DeliveryRow> {
return {
...data,
page: Number(data.page),
size: Number(data.size),
total: Number(data.total),
pages: Number(data.pages),
}
}
export interface DeliveryTransferPayload {
dispatchNo: string
idempotencyKey: string
plannedDeliveryAt: string
deliveryMethod: string
pickupMethod: string
loadingType: string
waybillNo?: string
carrierName?: string
vehicleType?: string
vehicleSize?: string
driverName?: string
driverPhone?: string
vehiclePlate?: string
appointmentAccount?: string
sellerName?: string
remark?: string
fees: DeliveryOrderFee[]
}
export function listDeliveryOrders(params: DeliveryQuery) {
return apiRequest<PageResult<DeliveryRow>>({
method: 'GET',
url: '/merchant/v1/last-leg/delivery-orders',
params,
}).then(normalizeDeliveryPage)
}
export function getDeliveryOrder(deliveryNo: string) {
return apiRequest<DeliveryOrderDetailResponse>({
method: 'GET',
url: `/merchant/v1/last-leg/delivery-orders/${encodeURIComponent(deliveryNo)}`,
params: { page: 1, size: 200 },
}).then(({ order, skus, fees }) => ({
...order,
fees,
items: skus,
}))
}
export function createDeliveryOrder(payload: DeliveryTransferPayload) {
const { dispatchNo, ...request } = payload
return apiRequest<DeliveryTransferResult>({
method: 'POST',
url: '/merchant/v1/last-leg/delivery-orders',
params: { dispatchNo },
data: request,
})
}