feat: 补充积分和账务 API 客户端
- 新增 src/api/points.ts - 积分 API 客户端 - 新增 src/api/ledger.ts - 账务 API 客户端 - 新增 src/types/points.ts - 积分类型定义 - 新增 src/types/ledger.ts - 账务类型定义 - 更新 src/api/index.ts - 导出新增模块
This commit is contained in:
parent
5099f2e87e
commit
ae2653f9dd
@ -3,8 +3,12 @@ export { apiClient, ApiClient } from './client'
|
||||
export { AccountAPI } from './account'
|
||||
export { TransactionAPI } from './transaction'
|
||||
export { ReconciliationAPI } from './reconciliation'
|
||||
export { PointsAPI } from './points'
|
||||
export { LedgerAPI } from './ledger'
|
||||
|
||||
// 类型重新导出
|
||||
export type * from '@/types/api'
|
||||
export type * from '@/types/account'
|
||||
export type * from '@/types/transaction'
|
||||
export type * from '@/types/points'
|
||||
export type * from '@/types/ledger'
|
||||
|
||||
141
src/api/ledger.ts
Normal file
141
src/api/ledger.ts
Normal file
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 账务 API 客户端
|
||||
* 提供会计科目、分录查询等功能
|
||||
*/
|
||||
import apiClient from './client'
|
||||
import type {
|
||||
AccountingSubject,
|
||||
LedgerEntry,
|
||||
LedgerEntryQuery,
|
||||
} from '@/types/ledger'
|
||||
import type { PageResponse } from '@/types/api'
|
||||
|
||||
export class LedgerAPI {
|
||||
/**
|
||||
* 获取会计科目列表
|
||||
* @returns 会计科目列表
|
||||
*/
|
||||
static async getSubjects(): Promise<AccountingSubject[]> {
|
||||
return apiClient.get('/ledger/subjects')
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会计科目详情
|
||||
* @param code 科目代码
|
||||
* @returns 会计科目
|
||||
*/
|
||||
static async getSubject(code: string): Promise<AccountingSubject> {
|
||||
return apiClient.get(`/ledger/subjects/${code}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分录详情
|
||||
* @param id 分录ID
|
||||
* @returns 分录详情(包含明细行)
|
||||
*/
|
||||
static async getEntry(id: number): Promise<LedgerEntry> {
|
||||
return apiClient.get(`/ledger/entries/${id}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户分录列表
|
||||
* @param accountId 账户ID
|
||||
* @param accountType 账户类型 (physical/virtual)
|
||||
* @param query 查询参数
|
||||
* @returns 分页的分录列表
|
||||
*/
|
||||
static async getAccountEntries(
|
||||
accountId: number,
|
||||
accountType: 'physical' | 'virtual',
|
||||
query?: LedgerEntryQuery
|
||||
): Promise<PageResponse<LedgerEntry>> {
|
||||
return apiClient.get(`/ledger/accounts/${accountId}/entries`, {
|
||||
params: { account_type: accountType, ...query }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据交易号获取分录
|
||||
* @param txnNo 交易号
|
||||
* @returns 分录详情
|
||||
*/
|
||||
static async getEntryByTxnNo(txnNo: string): Promise<LedgerEntry> {
|
||||
return apiClient.get(`/ledger/entries/by-txn/${txnNo}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户余额变动历史
|
||||
* @param accountId 账户ID
|
||||
* @param accountType 账户类型
|
||||
* @param query 查询参数
|
||||
* @returns 余额变动记录
|
||||
*/
|
||||
static async getBalanceHistory(
|
||||
accountId: number,
|
||||
accountType: 'physical' | 'virtual',
|
||||
query?: BalanceHistoryQuery
|
||||
): Promise<PageResponse<BalanceChange>> {
|
||||
return apiClient.get(`/ledger/accounts/${accountId}/balance-history`, {
|
||||
params: { account_type: accountType, ...query }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取科目汇总报表
|
||||
* @param query 查询参数
|
||||
* @returns 科目汇总数据
|
||||
*/
|
||||
static async getSubjectSummary(query: SubjectSummaryQuery): Promise<SubjectSummary[]> {
|
||||
return apiClient.get('/ledger/reports/subject-summary', { params: query })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额变动查询参数
|
||||
*/
|
||||
export interface BalanceHistoryQuery {
|
||||
start_date?: string
|
||||
end_date?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额变动记录
|
||||
*/
|
||||
export interface BalanceChange {
|
||||
id: number
|
||||
account_id: number
|
||||
account_type: string
|
||||
change_type: string
|
||||
amount: string
|
||||
balance_before: string
|
||||
balance_after: string
|
||||
txn_no?: string
|
||||
description?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 科目汇总查询参数
|
||||
*/
|
||||
export interface SubjectSummaryQuery {
|
||||
start_date: string
|
||||
end_date: string
|
||||
subject_code?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 科目汇总数据
|
||||
*/
|
||||
export interface SubjectSummary {
|
||||
subject_code: string
|
||||
subject_name: string
|
||||
debit_total: string
|
||||
credit_total: string
|
||||
balance: string
|
||||
transaction_count: number
|
||||
}
|
||||
|
||||
export default LedgerAPI
|
||||
|
||||
100
src/api/points.ts
Normal file
100
src/api/points.ts
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 积分 API 客户端
|
||||
* 提供积分账户管理、积分获取/消费/转移等功能
|
||||
*/
|
||||
import apiClient from './client'
|
||||
import type {
|
||||
PointsAccount,
|
||||
PointsTransaction,
|
||||
PointsTransactionQuery,
|
||||
EarnPointsRequest,
|
||||
SpendPointsRequest,
|
||||
TransferPointsRequest,
|
||||
} from '@/types/points'
|
||||
import type { PageResponse } from '@/types/api'
|
||||
|
||||
export class PointsAPI {
|
||||
/**
|
||||
* 获取积分账户
|
||||
* @param subAccountId 子账户ID
|
||||
* @returns 积分账户列表
|
||||
*/
|
||||
static async getAccounts(subAccountId: number): Promise<PointsAccount[]> {
|
||||
return apiClient.get(`/points/accounts/${subAccountId}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个积分账户详情
|
||||
* @param accountId 积分账户ID
|
||||
* @returns 积分账户
|
||||
*/
|
||||
static async getAccount(accountId: number): Promise<PointsAccount> {
|
||||
return apiClient.get(`/points/accounts/detail/${accountId}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分 (发放积分)
|
||||
* @param data 积分获取请求
|
||||
* @returns 积分交易记录
|
||||
*/
|
||||
static async earnPoints(data: EarnPointsRequest): Promise<PointsTransaction> {
|
||||
return apiClient.post('/points/earn', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费积分
|
||||
* @param data 积分消费请求
|
||||
* @returns 积分交易记录
|
||||
*/
|
||||
static async spendPoints(data: SpendPointsRequest): Promise<PointsTransaction> {
|
||||
return apiClient.post('/points/spend', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转移积分
|
||||
* @param data 积分转移请求
|
||||
* @returns 转出和转入两笔交易记录
|
||||
*/
|
||||
static async transferPoints(data: TransferPointsRequest): Promise<{
|
||||
from_transaction: PointsTransaction
|
||||
to_transaction: PointsTransaction
|
||||
}> {
|
||||
return apiClient.post('/points/transfer', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分交易列表
|
||||
* @param query 查询参数
|
||||
* @returns 分页的积分交易列表
|
||||
*/
|
||||
static async getTransactions(query: PointsTransactionQuery): Promise<PageResponse<PointsTransaction>> {
|
||||
return apiClient.get('/points/transactions', { params: query })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分统计
|
||||
* @param accountId 积分账户ID
|
||||
* @returns 积分统计信息
|
||||
*/
|
||||
static async getStatistics(accountId: number): Promise<PointsStatistics> {
|
||||
return apiClient.get(`/points/accounts/${accountId}/statistics`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分统计信息
|
||||
*/
|
||||
export interface PointsStatistics {
|
||||
account_id: number
|
||||
balance: string
|
||||
total_earned: string
|
||||
total_spent: string
|
||||
total_expired: string
|
||||
earn_count: number
|
||||
spend_count: number
|
||||
transfer_in_count: number
|
||||
transfer_out_count: number
|
||||
}
|
||||
|
||||
export default PointsAPI
|
||||
|
||||
110
src/types/ledger.ts
Normal file
110
src/types/ledger.ts
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* 账务相关类型定义
|
||||
*/
|
||||
|
||||
/**
|
||||
* 科目类别
|
||||
*/
|
||||
export type SubjectCategory = 'asset' | 'liability' | 'income' | 'expense'
|
||||
|
||||
/**
|
||||
* 借贷方向
|
||||
*/
|
||||
export type Direction = 'debit' | 'credit'
|
||||
|
||||
/**
|
||||
* 分录状态
|
||||
*/
|
||||
export type EntryStatus = 'pending' | 'posted' | 'reversed'
|
||||
|
||||
/**
|
||||
* 会计科目
|
||||
*/
|
||||
export interface AccountingSubject {
|
||||
code: string
|
||||
name: string
|
||||
category: SubjectCategory
|
||||
direction_default: number
|
||||
parent_code?: string
|
||||
level: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 分录明细行
|
||||
*/
|
||||
export interface LedgerLine {
|
||||
id: number
|
||||
entry_id: number
|
||||
account_id: number
|
||||
account_type: string
|
||||
subject_code: string
|
||||
direction: Direction
|
||||
amount: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 记账分录
|
||||
*/
|
||||
export interface LedgerEntry {
|
||||
id: number
|
||||
entry_no: string
|
||||
txn_no: string
|
||||
post_date: string
|
||||
post_time: string
|
||||
description?: string
|
||||
status: EntryStatus
|
||||
created_at: string
|
||||
lines: LedgerLine[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 分录查询参数
|
||||
*/
|
||||
export interface LedgerEntryQuery {
|
||||
subject_code?: string
|
||||
start_date?: string
|
||||
end_date?: string
|
||||
status?: EntryStatus
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 科目类别显示名称映射
|
||||
*/
|
||||
export const SubjectCategoryLabels: Record<SubjectCategory, string> = {
|
||||
asset: '资产类',
|
||||
liability: '负债类',
|
||||
income: '收入类',
|
||||
expense: '支出类',
|
||||
}
|
||||
|
||||
/**
|
||||
* 借贷方向显示名称映射
|
||||
*/
|
||||
export const DirectionLabels: Record<Direction, string> = {
|
||||
debit: '借方',
|
||||
credit: '贷方',
|
||||
}
|
||||
|
||||
/**
|
||||
* 分录状态显示名称映射
|
||||
*/
|
||||
export const EntryStatusLabels: Record<EntryStatus, string> = {
|
||||
pending: '待确认',
|
||||
posted: '已过账',
|
||||
reversed: '已冲销',
|
||||
}
|
||||
|
||||
/**
|
||||
* 预定义会计科目
|
||||
*/
|
||||
export const PredefinedSubjects: AccountingSubject[] = [
|
||||
{ code: '1002', name: '银行存款', category: 'asset', direction_default: 1, level: 1 },
|
||||
{ code: '1003', name: '在途资金', category: 'asset', direction_default: 1, level: 1 },
|
||||
{ code: '2001', name: '客户存款', category: 'liability', direction_default: -1, level: 1 },
|
||||
{ code: '2002', name: '待清算款项', category: 'liability', direction_default: -1, level: 1 },
|
||||
{ code: '3001', name: '手续费收入', category: 'income', direction_default: -1, level: 1 },
|
||||
{ code: '4001', name: '利息支出', category: 'expense', direction_default: 1, level: 1 },
|
||||
]
|
||||
|
||||
120
src/types/points.ts
Normal file
120
src/types/points.ts
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* 积分相关类型定义
|
||||
*/
|
||||
|
||||
/**
|
||||
* 积分类型
|
||||
*/
|
||||
export type PointsType = 'production' | 'management' | 'other'
|
||||
|
||||
/**
|
||||
* 积分交易类型
|
||||
*/
|
||||
export type PointsTransactionType = 'earn' | 'spend' | 'transfer' | 'expire' | 'adjust'
|
||||
|
||||
/**
|
||||
* 积分账户
|
||||
*/
|
||||
export interface PointsAccount {
|
||||
id: number
|
||||
sub_account_id: number
|
||||
points_type: PointsType
|
||||
balance: string
|
||||
total_earned: string
|
||||
total_spent: string
|
||||
total_expired: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分交易记录
|
||||
*/
|
||||
export interface PointsTransaction {
|
||||
id: number
|
||||
txn_no: string
|
||||
points_account_id: number
|
||||
txn_type: PointsTransactionType
|
||||
amount: string
|
||||
balance_before: string
|
||||
balance_after: string
|
||||
related_business_id?: string
|
||||
remark?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分获取请求
|
||||
*/
|
||||
export interface EarnPointsRequest {
|
||||
points_account_id: number
|
||||
amount: string
|
||||
related_business_id?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分消费请求
|
||||
*/
|
||||
export interface SpendPointsRequest {
|
||||
points_account_id: number
|
||||
amount: string
|
||||
related_business_id?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分转移请求
|
||||
*/
|
||||
export interface TransferPointsRequest {
|
||||
from_account_id: number
|
||||
to_account_id: number
|
||||
amount: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分交易查询参数
|
||||
*/
|
||||
export interface PointsTransactionQuery {
|
||||
points_account_id?: number
|
||||
txn_type?: PointsTransactionType
|
||||
start_date?: string
|
||||
end_date?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分规则
|
||||
*/
|
||||
export interface PointsRule {
|
||||
id: number
|
||||
name: string
|
||||
points_type: PointsType
|
||||
rule_type: string
|
||||
config: Record<string, unknown>
|
||||
enabled: boolean
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分类型显示名称映射
|
||||
*/
|
||||
export const PointsTypeLabels: Record<PointsType, string> = {
|
||||
production: '生产积分',
|
||||
management: '管理积分',
|
||||
other: '其他积分',
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分交易类型显示名称映射
|
||||
*/
|
||||
export const PointsTransactionTypeLabels: Record<PointsTransactionType, string> = {
|
||||
earn: '获取',
|
||||
spend: '消费',
|
||||
transfer: '转移',
|
||||
expire: '过期',
|
||||
adjust: '调整',
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user