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

92 lines
2.0 KiB
JavaScript
Raw Normal View History

2025-09-24 17:49:32 +08:00
/**
* 贷款申请模型
* @file LoanApplication.js
* @description 银行系统贷款申请数据模型
*/
const { DataTypes } = require('sequelize');
const BaseModel = require('./BaseModel');
class LoanApplication extends BaseModel {
/**
* 获取申请状态文本
* @returns {String} 状态文本
*/
getStatusText() {
const statusMap = {
2025-09-25 15:53:44 +08:00
pending: '待审核',
2025-09-24 17:49:32 +08:00
approved: '已通过',
2025-09-25 15:53:44 +08:00
rejected: '已拒绝',
completed: '已完成'
2025-09-24 17:49:32 +08:00
};
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
}
}
// 初始化LoanApplication模型
LoanApplication.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
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
application_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('pending', 'approved', 'rejected', 'completed'),
2025-09-24 17:49:32 +08:00
allowNull: true,
2025-09-25 15:53:44 +08:00
defaultValue: 'pending',
comment: '申请状态'
2025-09-24 17:49:32 +08:00
}
}, {
sequelize: require('../config/database').sequelize,
modelName: 'LoanApplication',
2025-09-25 15:53:44 +08:00
tableName: 'loan_applications',
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'
2025-09-24 17:49:32 +08:00
});
module.exports = LoanApplication;