Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 7x 7x 10x 6x 5x 5x 5x 5x | import type { Policy, PolicyCommissionYear, CommissionStatus, CommissionType } from '../types'
import { get } from '../http'
import { COMMISSION_STATUSES, POLICY_STATUSES } from '../enums'
import { pickEnum, toNumber } from '@/utils/number'
// 后端 /c/policy 返回体(com.yd.csf.service.vo.ReferrerPolicy*)
interface PolicyDTO {
policyNo: string
productName: string
currency: string
fullPremium: number
myRatio: string | null
status: string
}
interface PolicyListDTO {
effectivePolicies: PolicyDTO[]
inactivePolicies: PolicyDTO[]
}
interface CommissionSegmentDTO {
stage: string // 后端已按 D4.1 输出的四态码
fortunePeriod: number
periodLabel: string // 首年 / 第2年 ...
fortuneName: string
statusDesc?: string | null
amount: number // 该段 HKD 金额
}
interface PolicyCommissionDTO {
policyNo: string
items: CommissionSegmentDTO[]
}
export async function fetchPolicies(): Promise<Policy[]> {
const dto = await get<PolicyListDTO>('/c/policy/list')
const all = [...(dto.effectivePolicies ?? []), ...(dto.inactivePolicies ?? [])]
return all.map((p) => ({
policyNo: p.policyNo,
// 未知状态归入「未生效/已失效」分组,避免污染生效件数与生效列表
status: pickEnum(p.status, POLICY_STATUSES, 'LAPSED'),
productName: p.productName,
fullPremium: toNumber(p.fullPremium),
currency: p.currency,
// myRatio 为字符串,'0.35%' 之类会让 Number() 产出 NaN 并渲染上屏
myRatio: toNumber(p.myRatio)
}))
}
export async function fetchPolicyCommissions(policyNo: string): Promise<PolicyCommissionYear[]> {
if (!policyNo) return []
const dto = await get<PolicyCommissionDTO>(`/c/policy/${policyNo}/commission`)
return (dto.items ?? []).map((it) => {
const type: CommissionType = it.fortunePeriod === 1 ? 'FYC' : 'RYC'
return {
year: it.periodLabel || `Y${it.fortunePeriod}`,
type,
amount: toNumber(it.amount),
currency: 'HKD',
status: pickEnum<CommissionStatus>(it.stage, COMMISSION_STATUSES, 'UNKNOWN'),
statusDesc: it.statusDesc ?? undefined
}
})
}
|