修改政府端前端,银行端小程序和后端接口
This commit is contained in:
201
bank-backend/models/LoanRelease.js
Normal file
201
bank-backend/models/LoanRelease.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* 贷款解押模型
|
||||
* @file LoanRelease.js
|
||||
* @description 银行系统贷款解押数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const BaseModel = require('./BaseModel');
|
||||
|
||||
class LoanRelease extends BaseModel {
|
||||
/**
|
||||
* 获取解押状态文本
|
||||
* @returns {String} 状态文本
|
||||
*/
|
||||
getStatusText() {
|
||||
const statusMap = {
|
||||
pending: '待处理',
|
||||
processing: '处理中',
|
||||
approved: '已通过',
|
||||
rejected: '已拒绝',
|
||||
completed: '已完成',
|
||||
released: '已解押'
|
||||
};
|
||||
return statusMap[this.status] || this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取解押状态颜色
|
||||
* @returns {String} 颜色
|
||||
*/
|
||||
getStatusColor() {
|
||||
const colorMap = {
|
||||
pending: 'orange',
|
||||
processing: 'blue',
|
||||
approved: 'green',
|
||||
rejected: 'red',
|
||||
completed: 'green',
|
||||
released: 'default'
|
||||
};
|
||||
return colorMap[this.status] || 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化解押金额
|
||||
* @returns {String} 格式化后的金额
|
||||
*/
|
||||
getFormattedAmount() {
|
||||
return `${this.release_amount.toFixed(2)}元`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抵押物类型文本
|
||||
* @returns {String} 类型文本
|
||||
*/
|
||||
getCollateralTypeText() {
|
||||
const typeMap = {
|
||||
house: '房产',
|
||||
car: '车辆',
|
||||
land: '土地',
|
||||
equipment: '设备',
|
||||
livestock: '牲畜'
|
||||
};
|
||||
return typeMap[this.collateral_type] || this.collateral_type;
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化LoanRelease模型
|
||||
LoanRelease.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
application_number: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '解押申请单号'
|
||||
},
|
||||
contract_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '关联合同ID'
|
||||
},
|
||||
customer_name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '客户姓名'
|
||||
},
|
||||
customer_phone: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
comment: '客户电话'
|
||||
},
|
||||
customer_id_card: {
|
||||
type: DataTypes.STRING(18),
|
||||
allowNull: false,
|
||||
comment: '客户身份证号'
|
||||
},
|
||||
farmer_name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
comment: '养殖户姓名'
|
||||
},
|
||||
product_name: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: true,
|
||||
comment: '贷款产品名称'
|
||||
},
|
||||
collateral_type: {
|
||||
type: DataTypes.ENUM('house', 'car', 'land', 'equipment', 'livestock'),
|
||||
allowNull: false,
|
||||
comment: '抵押物类型'
|
||||
},
|
||||
collateral_description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '抵押物描述'
|
||||
},
|
||||
collateral_value: {
|
||||
type: DataTypes.DECIMAL(15, 2),
|
||||
allowNull: true,
|
||||
comment: '抵押物价值'
|
||||
},
|
||||
loan_amount: {
|
||||
type: DataTypes.DECIMAL(15, 2),
|
||||
allowNull: true,
|
||||
comment: '贷款金额'
|
||||
},
|
||||
release_amount: {
|
||||
type: DataTypes.DECIMAL(15, 2),
|
||||
allowNull: false,
|
||||
comment: '解押金额'
|
||||
},
|
||||
release_quantity: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
comment: '解押数量'
|
||||
},
|
||||
application_reason: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '申请原因'
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('pending', 'processing', 'approved', 'rejected', 'completed', 'released'),
|
||||
allowNull: false,
|
||||
defaultValue: 'pending',
|
||||
comment: '解押状态'
|
||||
},
|
||||
application_date: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: '申请日期'
|
||||
},
|
||||
process_date: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: '处理日期'
|
||||
},
|
||||
complete_date: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: '完成日期'
|
||||
},
|
||||
processor_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '处理人ID'
|
||||
},
|
||||
processor_name: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
comment: '处理人姓名'
|
||||
},
|
||||
process_comment: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '处理意见'
|
||||
},
|
||||
rejection_reason: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '拒绝原因'
|
||||
},
|
||||
remark: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '备注'
|
||||
}
|
||||
}, {
|
||||
sequelize: require('../config/database').sequelize,
|
||||
modelName: 'LoanRelease',
|
||||
tableName: 'bank_loan_releases',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = LoanRelease;
|
||||
108
bank-backend/models/LoanReleaseHistory.js
Normal file
108
bank-backend/models/LoanReleaseHistory.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* 贷款解押历史记录模型
|
||||
* @file LoanReleaseHistory.js
|
||||
* @description 银行系统贷款解押历史记录数据模型
|
||||
*/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const BaseModel = require('./BaseModel');
|
||||
|
||||
class LoanReleaseHistory extends BaseModel {
|
||||
/**
|
||||
* 获取操作动作文本
|
||||
* @returns {String} 动作文本
|
||||
*/
|
||||
getActionText() {
|
||||
const actionMap = {
|
||||
apply: '提交申请',
|
||||
process: '开始处理',
|
||||
approve: '审核通过',
|
||||
reject: '审核拒绝',
|
||||
complete: '处理完成',
|
||||
release: '解押完成'
|
||||
};
|
||||
return actionMap[this.action] || this.action;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作动作颜色
|
||||
* @returns {String} 颜色
|
||||
*/
|
||||
getActionColor() {
|
||||
const colorMap = {
|
||||
apply: 'blue',
|
||||
process: 'orange',
|
||||
approve: 'green',
|
||||
reject: 'red',
|
||||
complete: 'green',
|
||||
release: 'default'
|
||||
};
|
||||
return colorMap[this.action] || 'default';
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化LoanReleaseHistory模型
|
||||
LoanReleaseHistory.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
release_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '解押申请ID'
|
||||
},
|
||||
action: {
|
||||
type: DataTypes.ENUM(
|
||||
'apply',
|
||||
'process',
|
||||
'approve',
|
||||
'reject',
|
||||
'complete',
|
||||
'release'
|
||||
),
|
||||
allowNull: false,
|
||||
comment: '操作动作'
|
||||
},
|
||||
operator: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '操作人'
|
||||
},
|
||||
operator_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '操作人ID'
|
||||
},
|
||||
comment: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '操作备注'
|
||||
},
|
||||
previous_status: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
comment: '操作前状态'
|
||||
},
|
||||
new_status: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
comment: '操作后状态'
|
||||
},
|
||||
operation_time: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: '操作时间'
|
||||
}
|
||||
}, {
|
||||
sequelize: require('../config/database').sequelize,
|
||||
modelName: 'LoanReleaseHistory',
|
||||
tableName: 'bank_loan_release_histories',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
});
|
||||
|
||||
module.exports = LoanReleaseHistory;
|
||||
@@ -16,6 +16,9 @@ class User extends BaseModel {
|
||||
*/
|
||||
async validPassword(password) {
|
||||
try {
|
||||
if (!password || !this.password) {
|
||||
return false;
|
||||
}
|
||||
const bcrypt = require('bcryptjs');
|
||||
return await bcrypt.compare(password, this.password);
|
||||
} catch (error) {
|
||||
@@ -178,12 +181,12 @@ User.init({
|
||||
updatedAt: 'updated_at',
|
||||
hooks: {
|
||||
beforeCreate: async (user) => {
|
||||
if (user.password) {
|
||||
if (user.password && !user.password.startsWith('$2a$')) {
|
||||
user.password = await bcrypt.hash(user.password, 10);
|
||||
}
|
||||
},
|
||||
beforeUpdate: async (user) => {
|
||||
if (user.changed('password')) {
|
||||
if (user.changed('password') && user.password && !user.password.startsWith('$2a$')) {
|
||||
user.password = await bcrypt.hash(user.password, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ const CompletedSupervision = require('./CompletedSupervision');
|
||||
const LoanApplication = require('./LoanApplication');
|
||||
const AuditRecord = require('./AuditRecord');
|
||||
const LoanContract = require('./LoanContract');
|
||||
const LoanRelease = require('./LoanRelease');
|
||||
const LoanReleaseHistory = require('./LoanReleaseHistory');
|
||||
|
||||
// 定义模型关联关系
|
||||
|
||||
@@ -226,6 +228,54 @@ User.hasMany(AuditRecord, {
|
||||
// 贷款合同暂时不关联用户表,因为当前表结构中没有外键字段
|
||||
// 如果需要关联,需要先添加相应的外键字段到数据库表中
|
||||
|
||||
// 贷款解押与用户关联(处理人)
|
||||
LoanRelease.belongsTo(User, {
|
||||
foreignKey: 'processor_id',
|
||||
as: 'processor',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
User.hasMany(LoanRelease, {
|
||||
foreignKey: 'processor_id',
|
||||
as: 'processedReleases'
|
||||
});
|
||||
|
||||
// 贷款解押与贷款合同关联
|
||||
LoanRelease.belongsTo(LoanContract, {
|
||||
foreignKey: 'contract_id',
|
||||
as: 'contract',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
LoanContract.hasMany(LoanRelease, {
|
||||
foreignKey: 'contract_id',
|
||||
as: 'releases'
|
||||
});
|
||||
|
||||
// 贷款解押历史记录与解押申请关联
|
||||
LoanReleaseHistory.belongsTo(LoanRelease, {
|
||||
foreignKey: 'release_id',
|
||||
as: 'release',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
LoanRelease.hasMany(LoanReleaseHistory, {
|
||||
foreignKey: 'release_id',
|
||||
as: 'histories'
|
||||
});
|
||||
|
||||
// 贷款解押历史记录与用户关联(操作人)
|
||||
LoanReleaseHistory.belongsTo(User, {
|
||||
foreignKey: 'operator_id',
|
||||
as: 'operatorUser',
|
||||
targetKey: 'id'
|
||||
});
|
||||
|
||||
User.hasMany(LoanReleaseHistory, {
|
||||
foreignKey: 'operator_id',
|
||||
as: 'releaseHistories'
|
||||
});
|
||||
|
||||
// 导出所有模型和数据库实例
|
||||
module.exports = {
|
||||
sequelize,
|
||||
@@ -244,5 +294,7 @@ module.exports = {
|
||||
CompletedSupervision,
|
||||
LoanApplication,
|
||||
AuditRecord,
|
||||
LoanContract
|
||||
LoanContract,
|
||||
LoanRelease,
|
||||
LoanReleaseHistory
|
||||
};
|
||||
Reference in New Issue
Block a user