148 lines
4.4 KiB
TypeScript
148 lines
4.4 KiB
TypeScript
/**
|
||
* 换货管理 API 服务
|
||
*/
|
||
|
||
import { BaseService } from '../BaseService'
|
||
import type { BaseResponse } from '@/types/api'
|
||
|
||
// 换货单查询参数
|
||
export interface ExchangeQueryParams {
|
||
page?: number
|
||
page_size?: number
|
||
status?: number // 换货状态
|
||
flow_type?: string // 流程类型(shipping/direct)
|
||
identifier?: string // 资产标识符(模糊匹配,同时匹配旧资产、新资产)
|
||
created_at_start?: string // 创建时间起始
|
||
created_at_end?: string // 创建时间结束
|
||
}
|
||
|
||
// 创建换货单请求
|
||
export interface CreateExchangeRequest {
|
||
exchange_reason: string // 换货原因
|
||
old_asset_type: string // 旧资产类型 (iot_card 或 device)
|
||
old_identifier: string // 旧资产标识符(ICCID/虚拟号/IMEI/SN)
|
||
flow_type?: string // 流程类型(shipping/direct),默认 shipping
|
||
new_identifier?: string // 新资产标识符(direct 时必填)
|
||
migrate_data?: boolean // 是否迁移数据(默认 false)
|
||
remark?: string // 备注(可选)
|
||
}
|
||
|
||
// 换货单响应
|
||
export interface ExchangeResponse {
|
||
id: number
|
||
exchange_no: string
|
||
exchange_reason: string
|
||
old_asset_type: string
|
||
old_asset_identifier: string
|
||
new_asset_type: string
|
||
new_asset_identifier: string
|
||
status: number // 换货状态(1:待填写信息, 2:待发货, 3:已发货待确认, 4:已完成, 5:已取消)
|
||
status_text: string
|
||
flow_type: string // 流程类型(shipping/direct)
|
||
flow_type_name: string // 流程类型名称
|
||
shipped_at?: string | null // 发货时间(仅 shipping 发货后有值)
|
||
completed_at?: string | null // 换货完成时间
|
||
recipient_name?: string
|
||
recipient_phone?: string
|
||
recipient_address?: string
|
||
express_company?: string
|
||
express_no?: string
|
||
inherited_shop_id?: number | null
|
||
inherited_shop_name?: string | null
|
||
remark?: string
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
// 换货发货请求
|
||
export interface ShipExchangeRequest {
|
||
express_company: string // 快递公司
|
||
express_no: string // 快递单号
|
||
migrate_data: boolean // 是否迁移数据
|
||
new_identifier: string // 新资产标识符(ICCID/虚拟号/IMEI/SN)
|
||
}
|
||
|
||
// 取消换货请求
|
||
export interface CancelExchangeRequest {
|
||
remark?: string // 取消备注(可选)
|
||
}
|
||
|
||
export class ExchangeService extends BaseService {
|
||
/**
|
||
* 获取换货单列表
|
||
* GET /api/admin/exchanges
|
||
* @param params 查询参数
|
||
*/
|
||
static getExchanges(
|
||
params?: ExchangeQueryParams
|
||
): Promise<
|
||
BaseResponse<{ items: ExchangeResponse[]; page: number; page_size: number; total: number }>
|
||
> {
|
||
return this.get<
|
||
BaseResponse<{ items: ExchangeResponse[]; page: number; page_size: number; total: number }>
|
||
>('/api/admin/exchanges', params)
|
||
}
|
||
|
||
/**
|
||
* 创建换货单
|
||
* POST /api/admin/exchanges
|
||
* @param data 创建参数
|
||
*/
|
||
static createExchange(
|
||
data: CreateExchangeRequest,
|
||
config?: Record<string, any>
|
||
): Promise<BaseResponse<ExchangeResponse>> {
|
||
return this.post<BaseResponse<ExchangeResponse>>('/api/admin/exchanges', data, config)
|
||
}
|
||
|
||
/**
|
||
* 获取换货单详情
|
||
* GET /api/admin/exchanges/{id}
|
||
* @param id 换货单ID
|
||
*/
|
||
static getExchangeDetail(id: number): Promise<BaseResponse<ExchangeResponse>> {
|
||
return this.getOne<ExchangeResponse>(`/api/admin/exchanges/${id}`)
|
||
}
|
||
|
||
/**
|
||
* 取消换货
|
||
* POST /api/admin/exchanges/{id}/cancel
|
||
* @param id 换货单ID
|
||
* @param data 取消参数
|
||
*/
|
||
static cancelExchange(id: number, data?: CancelExchangeRequest): Promise<BaseResponse> {
|
||
return this.post<BaseResponse>(`/api/admin/exchanges/${id}/cancel`, data || {})
|
||
}
|
||
|
||
/**
|
||
* 确认换货完成
|
||
* POST /api/admin/exchanges/{id}/complete
|
||
* @param id 换货单ID
|
||
*/
|
||
static completeExchange(id: number): Promise<BaseResponse<ExchangeResponse>> {
|
||
return this.post<BaseResponse<ExchangeResponse>>(`/api/admin/exchanges/${id}/complete`, {})
|
||
}
|
||
|
||
/**
|
||
* 旧资产转新
|
||
* POST /api/admin/exchanges/{id}/renew
|
||
* @param id 换货单ID
|
||
*/
|
||
static renewExchange(id: number): Promise<BaseResponse> {
|
||
return this.post<BaseResponse>(`/api/admin/exchanges/${id}/renew`, {})
|
||
}
|
||
|
||
/**
|
||
* 换货发货
|
||
* POST /api/admin/exchanges/{id}/ship
|
||
* @param id 换货单ID
|
||
* @param data 发货参数
|
||
*/
|
||
static shipExchange(
|
||
id: number,
|
||
data: ShipExchangeRequest
|
||
): Promise<BaseResponse<ExchangeResponse>> {
|
||
return this.post<BaseResponse<ExchangeResponse>>(`/api/admin/exchanges/${id}/ship`, data)
|
||
}
|
||
}
|