From ae2653f9ddefc28e29acdd2526b43fde61f41248 Mon Sep 17 00:00:00 2001 From: tangweijie <877588133@qq.com> Date: Mon, 5 Jan 2026 18:13:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E5=92=8C=E8=B4=A6=E5=8A=A1=20API=20=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 src/api/points.ts - 积分 API 客户端 - 新增 src/api/ledger.ts - 账务 API 客户端 - 新增 src/types/points.ts - 积分类型定义 - 新增 src/types/ledger.ts - 账务类型定义 - 更新 src/api/index.ts - 导出新增模块 --- src/api/index.ts | 4 ++ src/api/ledger.ts | 141 ++++++++++++++++++++++++++++++++++++++++++++ src/api/points.ts | 100 +++++++++++++++++++++++++++++++ src/types/ledger.ts | 110 ++++++++++++++++++++++++++++++++++ src/types/points.ts | 120 +++++++++++++++++++++++++++++++++++++ 5 files changed, 475 insertions(+) create mode 100644 src/api/ledger.ts create mode 100644 src/api/points.ts create mode 100644 src/types/ledger.ts create mode 100644 src/types/points.ts diff --git a/src/api/index.ts b/src/api/index.ts index 1afb723..59bb4e5 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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' diff --git a/src/api/ledger.ts b/src/api/ledger.ts new file mode 100644 index 0000000..2a11463 --- /dev/null +++ b/src/api/ledger.ts @@ -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 { + return apiClient.get('/ledger/subjects') + } + + /** + * 获取会计科目详情 + * @param code 科目代码 + * @returns 会计科目 + */ + static async getSubject(code: string): Promise { + return apiClient.get(`/ledger/subjects/${code}`) + } + + /** + * 获取分录详情 + * @param id 分录ID + * @returns 分录详情(包含明细行) + */ + static async getEntry(id: number): Promise { + 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> { + return apiClient.get(`/ledger/accounts/${accountId}/entries`, { + params: { account_type: accountType, ...query } + }) + } + + /** + * 根据交易号获取分录 + * @param txnNo 交易号 + * @returns 分录详情 + */ + static async getEntryByTxnNo(txnNo: string): Promise { + 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> { + return apiClient.get(`/ledger/accounts/${accountId}/balance-history`, { + params: { account_type: accountType, ...query } + }) + } + + /** + * 获取科目汇总报表 + * @param query 查询参数 + * @returns 科目汇总数据 + */ + static async getSubjectSummary(query: SubjectSummaryQuery): Promise { + 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 + diff --git a/src/api/points.ts b/src/api/points.ts new file mode 100644 index 0000000..9065fb2 --- /dev/null +++ b/src/api/points.ts @@ -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 { + return apiClient.get(`/points/accounts/${subAccountId}`) + } + + /** + * 获取单个积分账户详情 + * @param accountId 积分账户ID + * @returns 积分账户 + */ + static async getAccount(accountId: number): Promise { + return apiClient.get(`/points/accounts/detail/${accountId}`) + } + + /** + * 获取积分 (发放积分) + * @param data 积分获取请求 + * @returns 积分交易记录 + */ + static async earnPoints(data: EarnPointsRequest): Promise { + return apiClient.post('/points/earn', data) + } + + /** + * 消费积分 + * @param data 积分消费请求 + * @returns 积分交易记录 + */ + static async spendPoints(data: SpendPointsRequest): Promise { + 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> { + return apiClient.get('/points/transactions', { params: query }) + } + + /** + * 获取积分统计 + * @param accountId 积分账户ID + * @returns 积分统计信息 + */ + static async getStatistics(accountId: number): Promise { + 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 + diff --git a/src/types/ledger.ts b/src/types/ledger.ts new file mode 100644 index 0000000..c32a643 --- /dev/null +++ b/src/types/ledger.ts @@ -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 = { + asset: '资产类', + liability: '负债类', + income: '收入类', + expense: '支出类', +} + +/** + * 借贷方向显示名称映射 + */ +export const DirectionLabels: Record = { + debit: '借方', + credit: '贷方', +} + +/** + * 分录状态显示名称映射 + */ +export const EntryStatusLabels: Record = { + 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 }, +] + diff --git a/src/types/points.ts b/src/types/points.ts new file mode 100644 index 0000000..d362aa0 --- /dev/null +++ b/src/types/points.ts @@ -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 + enabled: boolean + created_at: string +} + +/** + * 积分类型显示名称映射 + */ +export const PointsTypeLabels: Record = { + production: '生产积分', + management: '管理积分', + other: '其他积分', +} + +/** + * 积分交易类型显示名称映射 + */ +export const PointsTransactionTypeLabels: Record = { + earn: '获取', + spend: '消费', + transfer: '转移', + expire: '过期', + adjust: '调整', +} +