117 lines
3.4 KiB
TypeScript
117 lines
3.4 KiB
TypeScript
import { apiClient } from './client'
|
|
|
|
export interface Order {
|
|
id: number
|
|
order_no: string
|
|
listing_id: number
|
|
account_id: number
|
|
owner_id: number
|
|
renter_id: number
|
|
owner_phone?: string
|
|
renter_phone?: string
|
|
title: string
|
|
server_region: string
|
|
login_platform: string
|
|
rent_start_at?: string
|
|
rent_end_at?: string
|
|
rent_amount: number
|
|
deposit_amount: number
|
|
platform_fee: number
|
|
account_snapshot?: Record<string, unknown>
|
|
status: string
|
|
handoff_status: string
|
|
settlement_status: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface HandoffRecord {
|
|
id: number
|
|
order_id: number
|
|
from_user_id: number
|
|
to_user_id: number
|
|
type: string
|
|
content: string
|
|
confirmed_by_renter_at?: string
|
|
confirmed_by_owner_at?: string
|
|
created_at: string
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
code: string
|
|
message: string
|
|
data: T
|
|
}
|
|
|
|
export async function createOrder(listingId: number) {
|
|
const { data } = await apiClient.post<ApiResponse<Order>>('/orders', {
|
|
listing_id: listingId,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchOrders() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Order[] }>>('/orders')
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchAdminOrders() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Order[] }>>('/admin/orders')
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchOrder(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<Order>>(`/orders/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchAdminOrder(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<Order>>(`/admin/orders/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function cancelOrder(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<{ cancelled: boolean }>>(`/orders/${id}/cancel`)
|
|
return data.data
|
|
}
|
|
|
|
export async function submitHandoff(id: number, content: string) {
|
|
const { data } = await apiClient.post<ApiResponse<HandoffRecord>>(`/orders/${id}/handoff`, { content })
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchHandoffRecords(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: HandoffRecord[] }>>(`/orders/${id}/handoff-records`)
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchAdminHandoffRecords(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: HandoffRecord[] }>>(`/admin/orders/${id}/handoff-records`)
|
|
return data.data.items
|
|
}
|
|
|
|
export async function adminCloseOrder(id: number, reason: string) {
|
|
const { data } = await apiClient.post<ApiResponse<{ closed: boolean }>>(`/admin/orders/${id}/close`, { reason })
|
|
return data.data
|
|
}
|
|
|
|
export async function adminMarkOrderAbnormal(id: number, reason: string) {
|
|
const { data } = await apiClient.post<ApiResponse<{ abnormal: boolean }>>(`/admin/orders/${id}/mark-abnormal`, { reason })
|
|
return data.data
|
|
}
|
|
|
|
export async function confirmReceive(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<{ received: boolean }>>(`/orders/${id}/confirm-receive`)
|
|
return data.data
|
|
}
|
|
|
|
export async function submitReturn(id: number, content: string) {
|
|
const { data } = await apiClient.post<ApiResponse<HandoffRecord>>(`/orders/${id}/return`, { content })
|
|
return data.data
|
|
}
|
|
|
|
export async function confirmReturn(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<{ completed: boolean }>>(`/orders/${id}/confirm-return`)
|
|
return data.data
|
|
}
|