添加后端接口修改前端及小程序

This commit is contained in:
2025-09-29 17:58:42 +08:00
parent 488cbe4056
commit 4af8368097
50 changed files with 4558 additions and 333 deletions

View File

@@ -139,20 +139,7 @@ const getContractById = async (req, res) => {
try {
const { id } = req.params;
const contract = await LoanContract.findByPk(id, {
include: [
{
model: User,
as: 'creator',
attributes: ['id', 'username', 'real_name', 'email', 'phone']
},
{
model: User,
as: 'updater',
attributes: ['id', 'username', 'real_name']
}
]
});
const contract = await LoanContract.findByPk(id);
if (!contract) {
return res.status(404).json({
@@ -161,34 +148,32 @@ const getContractById = async (req, res) => {
});
}
// 格式化数据
// 格式化数据 - 使用数据库实际字段名
const formattedContract = {
id: contract.id,
contractNumber: contract.contractNumber,
applicationNumber: contract.applicationNumber,
productName: contract.productName,
farmerName: contract.farmerName,
borrowerName: contract.borrowerName,
borrowerIdNumber: contract.borrowerIdNumber,
assetType: contract.assetType,
applicationQuantity: contract.applicationQuantity,
amount: parseFloat(contract.amount),
paidAmount: parseFloat(contract.paidAmount),
contractNumber: contract.contract_number,
applicationNumber: contract.application_number || '',
productName: contract.product_name || '',
farmerName: contract.farmer_name || contract.customer_name,
borrowerName: contract.borrower_name || contract.customer_name,
borrowerIdNumber: contract.borrower_id_number || contract.customer_id_card,
assetType: contract.asset_type || '',
applicationQuantity: contract.application_quantity || '',
amount: parseFloat(contract.loan_amount),
paidAmount: parseFloat(contract.paid_amount || 0),
status: contract.status,
type: contract.type,
term: contract.term,
interestRate: parseFloat(contract.interestRate),
phone: contract.phone,
purpose: contract.purpose,
remark: contract.remark,
contractTime: contract.contractTime,
disbursementTime: contract.disbursementTime,
maturityTime: contract.maturityTime,
completedTime: contract.completedTime,
remainingAmount: parseFloat(contract.amount - contract.paidAmount),
repaymentProgress: contract.getRepaymentProgress(),
creator: contract.creator,
updater: contract.updater
type: contract.type || 'personal',
term: contract.loan_term,
interestRate: parseFloat(contract.interest_rate),
phone: contract.customer_phone,
purpose: contract.purpose || '',
remark: contract.remark || '',
contractTime: contract.contract_date,
disbursementTime: contract.disbursement_time,
maturityTime: contract.maturity_time,
completedTime: contract.completed_time,
remainingAmount: parseFloat(contract.loan_amount - (contract.paid_amount || 0)),
repaymentProgress: contract.getRepaymentProgress ? contract.getRepaymentProgress() : 0
};
res.json({
@@ -197,9 +182,15 @@ const getContractById = async (req, res) => {
});
} catch (error) {
console.error('获取贷款合同详情失败:', error);
console.error('错误详情:', {
message: error.message,
stack: error.stack,
name: error.name
});
res.status(500).json({
success: false,
message: '获取贷款合同详情失败'
message: '获取贷款合同详情失败',
error: process.env.NODE_ENV === 'development' ? error.message : undefined
});
}
};

View File

@@ -92,12 +92,12 @@ const getProjectById = async (req, res) => {
{
model: User,
as: 'creator',
attributes: ['id', 'username', 'name']
attributes: ['id', 'username', 'real_name']
},
{
model: User,
as: 'updater',
attributes: ['id', 'username', 'name']
attributes: ['id', 'username', 'real_name']
}
]
});