rentease-backend-new/models/Transaction.js

79 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-04-20 06:43:09 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Bill = require('./Bill');
const Transaction = sequelize.define('Transaction', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '流水ID'
},
billId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Bill,
key: 'id'
},
comment: '关联账单ID'
},
type: {
type: DataTypes.ENUM('income', 'expense'),
allowNull: false,
comment: '流水类型income收入expense支出'
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '金额'
},
paymentMethod: {
type: DataTypes.ENUM('cash', 'bank', 'wechat', 'alipay', 'other'),
allowNull: false,
defaultValue: 'cash',
comment: '支付方式cash现金bank银行转账wechat微信alipay支付宝other其他'
},
transactionDate: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '交易日期'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
},
createBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '创建人ID'
},
createTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
comment: '创建时间'
},
tenantId: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '租户ID'
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '删除状态0未删除1已删除'
}
}, {
tableName: 'transactions',
timestamps: false
});
// 建立关联
Transaction.belongsTo(Bill, { foreignKey: 'billId' });
Bill.hasMany(Transaction, { foreignKey: 'billId' });
module.exports = Transaction;