feat: migrate app routes and business modules

This commit is contained in:
2026-08-12 18:22:59 +08:00
parent 555aa00043
commit cc706378c2
247 changed files with 28623 additions and 14988 deletions
+85
View File
@@ -0,0 +1,85 @@
import {
normalizeEarningLedger,
normalizeEarningPage,
normalizeEarningPageQuery,
normalizeEarningSummary,
normalizeEarningWithdrawal,
normalizeEarningWithdrawalPayload
} from './earning-contract.js'
import { normalizeResourcePathId } from './request-normalizers.js'
import { hasRemoteConfig } from '@/utils/runtime-config.js'
import {
createRequestError,
requestStrict
} from './request-client.js'
const requireRemoteEarning = (label, operation) => {
if (hasRemoteConfig()) return
throw createRequestError(
`${label}${operation}需要真实服务,当前本地预览不会伪造结果`,
operation === '读取' ? 'REMOTE_READ_REQUIRED' : 'REMOTE_WRITE_REQUIRED'
)
}
export const earningApi = {
async getEarningSummary(requestOptions = {}) {
requireRemoteEarning('收益汇总', '读取')
const earningSummary = await requestStrict({
url: '/genealogy/app/earnings/summary',
method: 'GET'
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeEarningSummary(earningSummary)
},
async getEarningLedgerPage(query = {}, requestOptions = {}) {
requireRemoteEarning('收益明细', '读取')
const ledgerPage = await requestStrict({
url: '/genealogy/app/earnings/ledger',
method: 'GET',
data: normalizeEarningPageQuery(query)
}, {
requireData: false,
requestController: requestOptions.requestController ?? null
})
return normalizeEarningPage(ledgerPage, normalizeEarningLedger, '收益明细')
},
async getEarningWithdrawalPage(query = {}, requestOptions = {}) {
requireRemoteEarning('提现记录', '读取')
const withdrawalPage = await requestStrict({
url: '/genealogy/app/earnings/withdrawals',
method: 'GET',
data: normalizeEarningPageQuery(query)
}, {
requireData: false,
requestController: requestOptions.requestController ?? null
})
return normalizeEarningPage(withdrawalPage, normalizeEarningWithdrawal, '提现记录')
},
async requestEarningWithdrawal(payload, requestOptions = {}) {
requireRemoteEarning('提现申请', '写入')
const withdrawal = await requestStrict({
url: '/genealogy/app/earnings/withdrawals',
method: 'POST',
data: normalizeEarningWithdrawalPayload(payload)
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeEarningWithdrawal(withdrawal)
},
async cancelEarningWithdrawal(withdrawalId, requestOptions = {}) {
const normalizedWithdrawalId = normalizeResourcePathId(withdrawalId, '提现记录标识')
requireRemoteEarning('取消提现', '写入')
const withdrawal = await requestStrict({
url: `/genealogy/app/earnings/withdrawals/${normalizedWithdrawalId}/cancel`,
method: 'POST'
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeEarningWithdrawal(withdrawal)
}
}