Files
rent/apps/server/src/entities/transaction.entity.ts
T
2026-05-13 17:49:33 +08:00

67 lines
2.1 KiB
TypeScript

import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, Index } from 'typeorm';
@Entity('transactions')
export class Transaction {
@PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
id: number;
@Column({ type: 'varchar', length: 32, unique: true, comment: '交易流水号(全局唯一)' })
transaction_no: string;
@Column({ type: 'bigint', unsigned: true, comment: '账户ID' })
@Index()
account_id: number;
@Column({
type: 'enum',
enum: ['user', 'merchant', 'platform'],
comment: '账户类型'
})
account_type: 'user' | 'merchant' | 'platform';
@Column({ type: 'bigint', unsigned: true, comment: '账户所有者ID' })
owner_id: number;
@Column({
type: 'enum',
enum: ['income', 'expense'],
comment: '方向:income-收入/expense-支出'
})
direction: 'income' | 'expense';
@Column({ type: 'decimal', precision: 12, scale: 2, comment: '金额(正数)' })
amount: number;
@Column({ type: 'decimal', precision: 12, scale: 2, comment: '交易前余额' })
balance_before: number;
@Column({ type: 'decimal', precision: 12, scale: 2, comment: '交易后余额' })
balance_after: number;
@Column({ type: 'varchar', length: 50, comment: '交易类型' })
@Index()
transaction_type: string;
@Column({ type: 'varchar', length: 50, comment: '业务类型:order/refund/settlement/cashback/withdraw' })
business_type: string;
@Column({ type: 'bigint', unsigned: true, nullable: true, comment: '业务ID(订单ID/提现ID等)' })
business_id: number;
@Column({ type: 'varchar', length: 32, nullable: true, comment: '业务单号(订单号/提现单号等)' })
business_no: string;
@Column({ type: 'bigint', unsigned: true, nullable: true, comment: '对方账户ID(复式记账关联)' })
related_account_id: number;
@Column({ type: 'varchar', length: 500, nullable: true, comment: '备注' })
remark: string;
@CreateDateColumn({ comment: '创建时间' })
@Index()
created_at: Date;
}
@Index(['business_type', 'business_id'])
export class TransactionIndex {}