添加银行政府后端接口

This commit is contained in:
2025-09-25 15:53:44 +08:00
parent b17bdcc24c
commit 5b6b7e0a96
60 changed files with 5345 additions and 1920 deletions

View File

@@ -14,7 +14,6 @@ class LoanContract extends BaseModel {
getStatusText() {
const statusMap = {
active: '已放款',
pending: '待放款',
completed: '已完成',
defaulted: '违约',
cancelled: '已取消'
@@ -22,43 +21,12 @@ class LoanContract extends BaseModel {
return statusMap[this.status] || this.status;
}
/**
* 获取合同类型文本
* @returns {String} 类型文本
*/
getTypeText() {
const typeMap = {
livestock_collateral: '畜禽活体抵押',
farmer_loan: '惠农贷',
business_loan: '商业贷款',
personal_loan: '个人贷款'
};
return typeMap[this.type] || this.type;
}
/**
* 格式化合同金额
* @returns {String} 格式化后的金额
*/
getFormattedAmount() {
return `${this.amount.toFixed(2)}`;
}
/**
* 计算剩余还款金额
* @returns {Number} 剩余金额
*/
getRemainingAmount() {
return this.amount - (this.paidAmount || 0);
}
/**
* 计算还款进度百分比
* @returns {Number} 进度百分比
*/
getRepaymentProgress() {
if (this.amount <= 0) return 0;
return Math.round(((this.paidAmount || 0) / this.amount) * 100);
return `${this.loan_amount.toFixed(2)}`;
}
}
@@ -69,167 +37,63 @@ LoanContract.init({
primaryKey: true,
autoIncrement: true
},
contractNumber: {
contract_number: {
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '合同编号'
},
applicationNumber: {
type: DataTypes.STRING(50),
allowNull: false,
comment: '申请单号'
},
productName: {
type: DataTypes.STRING(200),
allowNull: false,
comment: '贷款产品名称'
},
farmerName: {
customer_name: {
type: DataTypes.STRING(100),
allowNull: false,
comment: '申请养殖户姓名'
comment: '户姓名'
},
borrowerName: {
type: DataTypes.STRING(100),
allowNull: false,
comment: '贷款人姓名'
},
borrowerIdNumber: {
customer_phone: {
type: DataTypes.STRING(20),
allowNull: false,
comment: '贷款人身份证号'
comment: '客户电话'
},
assetType: {
type: DataTypes.STRING(50),
customer_id_card: {
type: DataTypes.STRING(18),
allowNull: false,
comment: '生资种类'
comment: '客户身份证号'
},
applicationQuantity: {
type: DataTypes.STRING(100),
allowNull: false,
comment: '申请数量'
},
amount: {
loan_amount: {
type: DataTypes.DECIMAL(15, 2),
allowNull: false,
comment: '合同金额'
comment: '贷款金额'
},
paidAmount: {
type: DataTypes.DECIMAL(15, 2),
allowNull: false,
defaultValue: 0,
comment: '已还款金额'
},
status: {
type: DataTypes.ENUM(
'active',
'pending',
'completed',
'defaulted',
'cancelled'
),
allowNull: false,
defaultValue: 'pending',
comment: '合同状态'
},
type: {
type: DataTypes.ENUM(
'livestock_collateral',
'farmer_loan',
'business_loan',
'personal_loan'
),
allowNull: false,
comment: '合同类型'
},
term: {
loan_term: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '合同期限(月)'
comment: '贷款期限(月)'
},
interestRate: {
interest_rate: {
type: DataTypes.DECIMAL(5, 2),
allowNull: false,
comment: '利率'
comment: '贷款利率(%'
},
phone: {
type: DataTypes.STRING(20),
contract_date: {
type: DataTypes.DATEONLY,
allowNull: false,
comment: '联系电话'
comment: '合同签订日期'
},
purpose: {
type: DataTypes.TEXT,
status: {
type: DataTypes.ENUM('active', 'completed', 'defaulted', 'cancelled'),
allowNull: true,
comment: '贷款用途'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
},
contractTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '合同签订时间'
},
disbursementTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '放款时间'
},
maturityTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '到期时间'
},
completedTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '完成时间'
},
createdBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '创建人ID',
references: {
model: 'bank_users',
key: 'id'
}
},
updatedBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '更新人ID',
references: {
model: 'bank_users',
key: 'id'
}
defaultValue: 'active',
comment: '合同状态'
}
}, {
sequelize: require('../config/database').sequelize,
modelName: 'LoanContract',
tableName: 'bank_loan_contracts',
tableName: 'loan_contracts',
timestamps: true,
createdAt: 'createdAt',
updatedAt: 'updatedAt',
hooks: {
beforeCreate: (contract) => {
// 生成合同编号
if (!contract.contractNumber) {
const now = new Date();
const timestamp = now.getFullYear().toString() +
(now.getMonth() + 1).toString().padStart(2, '0') +
now.getDate().toString().padStart(2, '0') +
now.getHours().toString().padStart(2, '0') +
now.getMinutes().toString().padStart(2, '0') +
now.getSeconds().toString().padStart(2, '0');
const random = Math.floor(Math.random() * 1000).toString().padStart(3, '0');
contract.contractNumber = 'HT' + timestamp + random;
}
}
}
underscored: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
// 移除不存在的字段
omitNull: true
});
module.exports = LoanContract;
module.exports = LoanContract;