This commit is contained in:
2026-08-11 10:46:01 +08:00
parent 88788dc473
commit de0a90e853
12 changed files with 517 additions and 19 deletions
+55
View File
@@ -0,0 +1,55 @@
import { apiRequest } from '@/api/http'
import type { FinanceBillDetail, FinanceBillPage, FinanceBillQuery, FinanceReceiptRecord } from '../contracts'
import {
mapFinanceBillDetail,
mapFinanceBills,
mapFinanceReceipts,
sumDecimalStrings,
type FinanceBillWire,
type FinanceReceiptWire,
} from './adapters'
/** The customer scope is resolved by the authenticated merchant session. */
export async function getMerchantFinanceBills(params: FinanceBillQuery = {}): Promise<FinanceBillPage> {
const response = await apiRequest<FinanceBillWire[]>({
method: 'GET',
url: '/client/finance/v1/bills',
})
const keyword = params.keyword?.trim().toLocaleLowerCase('zh-CN')
const filtered = mapFinanceBills(response).filter((bill) => {
const matchesStatus = !params.status || bill.status === params.status
const matchesKeyword = !keyword || bill.billNo.toLocaleLowerCase('zh-CN').includes(keyword)
|| bill.customerName.toLocaleLowerCase('zh-CN').includes(keyword)
return matchesStatus && matchesKeyword
})
const page = Math.max(1, params.page ?? 1)
const size = Math.max(1, params.size ?? 20)
const start = (page - 1) * size
return {
records: filtered.slice(start, start + size),
total: filtered.length,
page,
size,
pages: Math.ceil(filtered.length / size),
totalBilledAmount: sumDecimalStrings(filtered.map((bill) => bill.totalAmount)),
totalReceivedAmount: sumDecimalStrings(filtered.map((bill) => bill.receivedAmount)),
totalOutstandingAmount: sumDecimalStrings(filtered.map((bill) => bill.outstandingAmount)),
currencyCode: 'CNY',
}
}
export async function getMerchantFinanceBill(id: string): Promise<FinanceBillDetail> {
const response = await apiRequest<FinanceBillWire>({
method: 'GET',
url: `/client/finance/v1/bills/${encodeURIComponent(id)}`,
})
return mapFinanceBillDetail(response)
}
export async function getMerchantFinanceReceipts(billId: string): Promise<FinanceReceiptRecord[]> {
const response = await apiRequest<FinanceReceiptWire[]>({
method: 'GET',
url: '/client/finance/v1/receipts',
})
return mapFinanceReceipts(response, billId)
}