Files
nxxmdata/bank-backend/models/LoanContract.js

99 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2025-09-24 17:49:32 +08:00
/**
* 贷款合同模型
* @file LoanContract.js
* @description 银行系统贷款合同数据模型
*/
const { DataTypes } = require('sequelize');
const BaseModel = require('./BaseModel');
class LoanContract extends BaseModel {
/**
* 获取合同状态文本
* @returns {String} 状态文本
*/
getStatusText() {
const statusMap = {
active: '已放款',
completed: '已完成',
defaulted: '违约',
cancelled: '已取消'
};
return statusMap[this.status] || this.status;
}
/**
* 格式化合同金额
* @returns {String} 格式化后的金额
*/
getFormattedAmount() {
2025-09-25 15:53:44 +08:00
return `${this.loan_amount.toFixed(2)}`;
2025-09-24 17:49:32 +08:00
}
}
// 初始化LoanContract模型
LoanContract.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
2025-09-25 15:53:44 +08:00
contract_number: {
2025-09-24 17:49:32 +08:00
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '合同编号'
},
2025-09-25 15:53:44 +08:00
customer_name: {
2025-09-24 17:49:32 +08:00
type: DataTypes.STRING(100),
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '客户姓名'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
customer_phone: {
2025-09-24 17:49:32 +08:00
type: DataTypes.STRING(20),
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '客户电话'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
customer_id_card: {
type: DataTypes.STRING(18),
2025-09-24 17:49:32 +08:00
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '客户身份证号'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
loan_amount: {
2025-09-24 17:49:32 +08:00
type: DataTypes.DECIMAL(15, 2),
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '贷款金额'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
loan_term: {
2025-09-24 17:49:32 +08:00
type: DataTypes.INTEGER,
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '贷款期限(月)'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
interest_rate: {
2025-09-24 17:49:32 +08:00
type: DataTypes.DECIMAL(5, 2),
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '贷款利率(%'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
contract_date: {
type: DataTypes.DATEONLY,
2025-09-24 17:49:32 +08:00
allowNull: false,
2025-09-25 15:53:44 +08:00
comment: '合同签订日期'
2025-09-24 17:49:32 +08:00
},
2025-09-25 15:53:44 +08:00
status: {
type: DataTypes.ENUM('active', 'completed', 'defaulted', 'cancelled'),
2025-09-24 17:49:32 +08:00
allowNull: true,
2025-09-25 15:53:44 +08:00
defaultValue: 'active',
comment: '合同状态'
2025-09-24 17:49:32 +08:00
}
}, {
sequelize: require('../config/database').sequelize,
modelName: 'LoanContract',
2025-09-25 15:53:44 +08:00
tableName: 'loan_contracts',
2025-09-24 17:49:32 +08:00
timestamps: true,
2025-09-25 15:53:44 +08:00
underscored: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
// 移除不存在的字段
omitNull: true
2025-09-24 17:49:32 +08:00
});
2025-09-25 15:53:44 +08:00
module.exports = LoanContract;