All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m43s
Co-authored-by: Cursor <cursoragent@cursor.com>
154 lines
3.8 KiB
TypeScript
154 lines
3.8 KiB
TypeScript
import { axiosInstance } from '@/api/rbac'
|
|
import { assertBusinessOk, omsUrl, parseListPayload } from '@/api/oms/common'
|
|
|
|
export type AgentStatus = 0 | 1 | 2
|
|
|
|
export interface AgentDto {
|
|
id: number
|
|
agentCode: string
|
|
agentName: string
|
|
phone?: string
|
|
email?: string
|
|
status: AgentStatus
|
|
baseType: string
|
|
commissionRate: number
|
|
salesProductIds?: string
|
|
remark?: string
|
|
createTime?: string
|
|
}
|
|
|
|
export interface AgentCommissionDto {
|
|
id: number
|
|
agentId: number
|
|
agentCode?: string
|
|
agentName?: string
|
|
orderId: number
|
|
serviceNo?: string
|
|
customerId: number
|
|
customerCode?: string
|
|
customerName?: string
|
|
salesProductId?: number
|
|
baseType: string
|
|
baseAmount: number
|
|
commissionRate: number
|
|
commissionAmount: number
|
|
status: string
|
|
triggerOrderStatus: string
|
|
paidTime?: string
|
|
remark?: string
|
|
createTime?: string
|
|
}
|
|
|
|
export interface AgentPortalCustomerDto {
|
|
id: number
|
|
customerCode: string
|
|
customerName: string
|
|
phone?: string
|
|
agentBindTime?: string
|
|
createTime?: string
|
|
}
|
|
|
|
export interface AgentPortalOrderDto {
|
|
id: number
|
|
serviceNo: string
|
|
trackNo?: string
|
|
customerId?: number
|
|
customerCode?: string
|
|
customerName?: string
|
|
productCode?: string
|
|
orderStatus?: string
|
|
consigneeCountryName?: string
|
|
receivableSubtotal?: number
|
|
createTime?: string
|
|
}
|
|
|
|
interface PageResult<T> {
|
|
items: T[]
|
|
total: number
|
|
}
|
|
|
|
function unwrapPage<T>(data: any): PageResult<T> {
|
|
const parsed = parseListPayload(data)
|
|
return {
|
|
items: (parsed.items || []) as T[],
|
|
total: parsed.total,
|
|
}
|
|
}
|
|
|
|
export const AgentAdminApi = {
|
|
async list(body: {
|
|
page?: number
|
|
pageSize?: number
|
|
keyword?: string
|
|
status?: number
|
|
}): Promise<PageResult<AgentDto>> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/list'), body)
|
|
return unwrapPage(r.data)
|
|
},
|
|
|
|
async create(body: Record<string, unknown>): Promise<void> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/create'), body)
|
|
assertBusinessOk(r.data)
|
|
},
|
|
|
|
async update(body: Record<string, unknown>): Promise<void> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/update'), body)
|
|
assertBusinessOk(r.data)
|
|
},
|
|
|
|
async rebind(body: { customerId: number; agentId?: number | null }): Promise<void> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/rebind'), body)
|
|
assertBusinessOk(r.data)
|
|
},
|
|
|
|
async commissionList(body: {
|
|
page?: number
|
|
pageSize?: number
|
|
agentId?: number
|
|
orderId?: number
|
|
status?: string
|
|
}): Promise<PageResult<AgentCommissionDto>> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/commission/list'), body)
|
|
return unwrapPage(r.data)
|
|
},
|
|
|
|
async markPaid(ids: number[], remark?: string): Promise<void> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/admin/commission/mark-paid'), { ids, remark })
|
|
assertBusinessOk(r.data)
|
|
},
|
|
}
|
|
|
|
export const AgentPortalApi = {
|
|
async profile(): Promise<AgentDto> {
|
|
const r = await axiosInstance.get(omsUrl('/agent/portal/profile'))
|
|
assertBusinessOk(r.data)
|
|
return r.data?.data ?? r.data
|
|
},
|
|
|
|
async customers(body: {
|
|
page?: number
|
|
pageSize?: number
|
|
keyword?: string
|
|
}): Promise<PageResult<AgentPortalCustomerDto>> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/portal/customers/list'), body)
|
|
return unwrapPage(r.data)
|
|
},
|
|
|
|
async orders(body: {
|
|
page?: number
|
|
pageSize?: number
|
|
keyword?: string
|
|
}): Promise<PageResult<AgentPortalOrderDto>> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/portal/orders/list'), body)
|
|
return unwrapPage(r.data)
|
|
},
|
|
|
|
async commissions(body: {
|
|
page?: number
|
|
pageSize?: number
|
|
}): Promise<PageResult<AgentCommissionDto>> {
|
|
const r = await axiosInstance.post(omsUrl('/agent/portal/commission/list'), body)
|
|
return unwrapPage(r.data)
|
|
},
|
|
}
|