修改后端接口

This commit is contained in:
2025-09-25 17:43:54 +08:00
parent 5b6b7e0a96
commit 76b5393182
31 changed files with 2155 additions and 468 deletions

View File

@@ -46,7 +46,7 @@ const getEmployees = async (req, res) => {
where,
limit,
offset,
order: [['createdAt', 'DESC']],
order: [['created_at', 'DESC']],
attributes: {
exclude: ['password'] // 不返回密码
}

View File

@@ -35,6 +35,9 @@ const getApplications = async (req, res) => {
where.customer_phone = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'customerIdCard') {
where.customer_id_card = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'applicationNumber') {
// 数据库中实际没有applicationNumber字段使用id作为替代
where.id = { [Op.like]: `%${searchValue}%` };
}
}
@@ -47,8 +50,17 @@ const getApplications = async (req, res) => {
const offset = (parseInt(page) - 1) * parseInt(pageSize);
const limit = parseInt(pageSize);
// 排序参数
const order = [[sortField, sortOrder.toUpperCase()]];
// 排序参数 - 映射字段名
const fieldMapping = {
'createdAt': 'created_at',
'updatedAt': 'updated_at',
'applicationDate': 'application_date',
'loanAmount': 'loan_amount',
'loanTerm': 'loan_term',
'interestRate': 'interest_rate'
};
const dbSortField = fieldMapping[sortField] || sortField;
const order = [[dbSortField, sortOrder.toUpperCase()]];
// 查询数据
const { count, rows } = await LoanApplication.findAndCountAll({

View File

@@ -37,6 +37,9 @@ const getContracts = async (req, res) => {
where.customer_phone = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'customerIdCard') {
where.customer_id_card = { [Op.like]: `%${searchValue}%` };
} else if (searchField === 'applicationNumber') {
// 数据库中实际没有applicationNumber字段使用id作为替代
where.id = { [Op.like]: `%${searchValue}%` };
}
}
@@ -49,8 +52,17 @@ const getContracts = async (req, res) => {
const offset = (parseInt(page) - 1) * parseInt(pageSize);
const limit = parseInt(pageSize);
// 排序参数
const order = [[sortField, sortOrder.toUpperCase()]];
// 排序参数 - 映射字段名
const fieldMapping = {
'createdAt': 'created_at',
'updatedAt': 'updated_at',
'contractDate': 'contract_date',
'loanAmount': 'loan_amount',
'loanTerm': 'loan_term',
'interestRate': 'interest_rate'
};
const dbSortField = fieldMapping[sortField] || sortField;
const order = [[dbSortField, sortOrder.toUpperCase()]];
// 查询数据
const { count, rows } = await LoanContract.findAndCountAll({

View File

@@ -200,6 +200,14 @@ const createLoanProduct = async (req, res) => {
});
}
// 检查用户信息
if (!req.user || !req.user.id) {
return res.status(401).json({
success: false,
message: '用户信息无效'
});
}
const product = await LoanProduct.create({
productName,
loanAmount,