This commit is contained in:
2026-09-03 10:46:07 +08:00
parent 913a8df7f3
commit 176f815519
17 changed files with 1128 additions and 44 deletions
@@ -0,0 +1,65 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export interface CustomerChargeRule {
id: string
tenantId: string
ruleCode: string
ruleVersion: number
customerId: string
customerName: string
businessType: string
chargeMode: 'KG' | 'CBM'
taxMode: 'TAX_INCLUDED' | 'TAX_EXCLUDED'
conversionFactor: number
lengthFactor: number
widthFactor: number
heightFactor: number
defaultRule: boolean
roundingScale: number
roundingMode: string
currency: string
effectiveFrom: string
effectiveTo: string | null
status: 'ACTIVE' | 'INACTIVE'
remark: string | null
}
export type CreateCustomerChargeRuleRequest = Omit<CustomerChargeRule, 'id' | 'tenantId' | 'ruleVersion' | 'status'> & {
id?: never
tenantId?: never
ruleVersion?: never
status?: never
}
const path = '/platform/v1/fba-pricing/customer-rules'
function normalize(value: CustomerChargeRule): CustomerChargeRule {
return {
...value,
id: String(value.id), tenantId: String(value.tenantId), customerId: String(value.customerId),
ruleVersion: Number(value.ruleVersion), conversionFactor: Number(value.conversionFactor),
lengthFactor: Number(value.lengthFactor ?? 1), widthFactor: Number(value.widthFactor ?? 1),
heightFactor: Number(value.heightFactor ?? 1), defaultRule: Boolean(value.defaultRule),
roundingScale: Number(value.roundingScale),
}
}
export async function listCustomerChargeRules(customerId: string, tenantId?: string) {
const response = await http.get<never, ApiEnvelope<CustomerChargeRule[]>>(path, {
params: { tenantId: tenantId || customerId, customerId },
})
return unwrapApiResponse(response).map(normalize)
}
export async function createCustomerChargeRule(tenantId: string, request: CreateCustomerChargeRuleRequest) {
const response = await http.post<never, ApiEnvelope<CustomerChargeRule>>(`${path}/versions`, request, { params: { tenantId } })
return normalize(unwrapApiResponse(response))
}
export async function setCustomerChargeRuleDefault(tenantId: string, ruleId: string) {
await http.put<never, ApiEnvelope<void>>(`${path}/${encodeURIComponent(ruleId)}/default`, undefined, { params: { tenantId } })
}
export async function retireCustomerChargeRule(tenantId: string, ruleId: string) {
await http.delete<never, ApiEnvelope<void>>(`${path}/${encodeURIComponent(ruleId)}`, { params: { tenantId } })
}
+1
View File
@@ -0,0 +1 @@
export * from './public'
+7
View File
@@ -0,0 +1,7 @@
export {
createCustomerChargeRule,
listCustomerChargeRules,
retireCustomerChargeRule,
setCustomerChargeRuleDefault,
} from './customer-rules/api'
export type { CustomerChargeRule, CreateCustomerChargeRuleRequest } from './customer-rules/api'