备份:大改造前的完整版本 - 修复合同细节/付款节点/文件上传/施工管理/项目保存等BUG

This commit is contained in:
root
2026-05-15 12:02:24 +08:00
parent 1cad1e438d
commit fad28741bd
6157 changed files with 5147 additions and 877912 deletions
+39 -37
View File
@@ -38,14 +38,17 @@ router.get('/', async (req, res) => {
const paymentInfos = paymentInfosResult.rows.map(payment => ({
id: payment.id,
account_name: payment.account_name,
bank_account: payment.account_number,
bank_account: payment.bank_account,
bank_name: payment.bank_name,
qr_code: payment.qr_code,
is_primary: payment.is_default === 1
is_primary: payment.is_default === true
}));
return {
...supplier,
supply_category: supplier.product_category,
country: supplier.supplier_source,
remark: supplier.remark || '',
contacts: contacts.length > 0 ? contacts : [],
payment_infos: paymentInfos.length > 0 ? paymentInfos : []
};
@@ -62,7 +65,7 @@ router.get('/', async (req, res) => {
res.status(500).json({
success: false,
message: '获取供应商失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -74,7 +77,7 @@ router.get('/:id', async (req, res) => {
// 获取供应商基本信息
const supplierResult = await db.query(`
SELECT * FROM suppliers
WHERE id = ?
WHERE id = $1
`, [id]);
if (supplierResult.rows.length > 0) {
@@ -83,7 +86,7 @@ router.get('/:id', async (req, res) => {
// 获取供应商的所有联系人
const contactsResult = await db.query(`
SELECT * FROM contacts
WHERE entity_id = ? AND entity_type = 'supplier'
WHERE entity_id = $1 AND entity_type = 'supplier'
ORDER BY is_primary DESC
`, [id]);
@@ -92,13 +95,13 @@ router.get('/:id', async (req, res) => {
name: contact.name || '未命名',
position: contact.position || '',
phone: contact.phone || '',
is_primary: contact.is_primary === 1
is_primary: contact.is_primary === true
}));
// 获取供应商的所有收款信息
const paymentInfosResult = await db.query(`
SELECT * FROM supplier_payment_infos
WHERE supplier_id = ?
WHERE supplier_id = $1
ORDER BY is_default DESC
`, [id]);
@@ -106,10 +109,10 @@ router.get('/:id', async (req, res) => {
const paymentInfos = paymentInfosResult.rows.map(payment => ({
id: payment.id,
account_name: payment.account_name,
bank_account: payment.account_number,
bank_account: payment.bank_account,
bank_name: payment.bank_name,
qr_code: payment.qr_code,
is_primary: payment.is_default === 1
is_primary: payment.is_default === true
}));
const ledger = await LedgerService.getSupplierLedger(id);
@@ -118,8 +121,8 @@ router.get('/:id', async (req, res) => {
id: supplier.id,
code: `S${String(supplier.id).padStart(4, '0')}`,
name: supplier.name || '未命名',
supply_category: supplier.supply_category || '电力设备',
country: supplier.country || 'Laos',
supply_category: supplier.product_category || '电力设备',
country: supplier.supplier_source || 'Laos',
contacts: contacts.length > 0 ? contacts : [],
payment_infos: paymentInfos.length > 0 ? paymentInfos : [],
remark: supplier.remark || '',
@@ -147,7 +150,7 @@ router.get('/:id', async (req, res) => {
res.status(500).json({
success: false,
message: '获取供应商详情失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -158,27 +161,27 @@ router.post('/', async (req, res) => {
// 从contacts中获取主联系人信息
const primaryContact = contacts?.find(c => c.is_primary) || contacts?.[0];
const contact = primaryContact?.name || '';
const position = primaryContact?.position || '';
const contact_person = primaryContact?.name || '';
const phone = primaryContact?.phone || '';
const email = ''; // 前端没有email字段
const address = ''; // 前端没有address字段
const result = await db.query(
`INSERT INTO suppliers (name, address, contact, position, phone, email, supply_category, country, remark, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[name, address, contact, position, phone, email, supply_category, country, remark]
`INSERT INTO suppliers (name, address, contact_person, phone, email, product_category, supplier_source, remark, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
RETURNING id`,
[name, address, contact_person, phone, email, supply_category, country, remark || '']
);
const supplierId = (result.rows[0]?.id || result.rows?.[0]?.id);
const supplierId = result.rows[0]?.id;
// 插入联系人数据
if (contacts && contacts.length > 0) {
for (const contactItem of contacts) {
await db.query(
`INSERT INTO contacts (entity_id, entity_type, name, position, phone, is_primary, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[supplierId, 'supplier', contactItem.name, contactItem.position, contactItem.phone, contactItem.is_primary ? 1 : 0]
VALUES ($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[supplierId, 'supplier', contactItem.name, contactItem.position, contactItem.phone, contactItem.is_primary ? true : false]
);
}
}
@@ -188,8 +191,8 @@ router.post('/', async (req, res) => {
for (const paymentInfo of payment_infos) {
await db.query(
`INSERT INTO supplier_payment_infos (supplier_id, account_name, bank_account, bank_name, qr_code, is_primary, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[supplierId, paymentInfo.account_name, paymentInfo.bank_account, paymentInfo.bank_name, paymentInfo.qr_code, paymentInfo.is_primary ? 1 : 0]
VALUES ($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[supplierId, paymentInfo.account_name, paymentInfo.bank_account, paymentInfo.bank_name, paymentInfo.qr_code, paymentInfo.is_primary ? true : false]
);
}
}
@@ -217,7 +220,7 @@ router.post('/', async (req, res) => {
res.status(500).json({
success: false,
message: '创建供应商失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -229,17 +232,16 @@ router.put('/:id', async (req, res) => {
// 从contacts中获取主联系人信息
const primaryContact = contacts?.find(c => c.is_primary) || contacts?.[0];
const contact = primaryContact?.name || '';
const position = primaryContact?.position || '';
const contact_person = primaryContact?.name || '';
const phone = primaryContact?.phone || '';
const email = ''; // 前端没有email字段
const address = ''; // 前端没有address字段
await db.query(
`UPDATE suppliers
SET name = ?, address = ?, contact = ?, position = ?, phone = ?, email = ?, supply_category = ?, country = ?, remark = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = ?`,
[name, address, contact, position, phone, email, supply_category, country, remark, id]
SET name = $1, address = $2, contact_person = $3, phone = $4, email = $5, product_category = $6, supplier_source = $7, remark = $8, updated_at = CURRENT_TIMESTAMP
WHERE id = $9`,
[name, address, contact_person, phone, email, supply_category, country, remark || '', id]
);
// 删除旧的联系人数据
@@ -250,8 +252,8 @@ router.put('/:id', async (req, res) => {
for (const contactItem of contacts) {
await db.query(
`INSERT INTO contacts (entity_id, entity_type, name, position, phone, is_primary, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[id, 'supplier', contactItem.name, contactItem.position, contactItem.phone, contactItem.is_primary ? 1 : 0]
VALUES ($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[id, 'supplier', contactItem.name, contactItem.position, contactItem.phone, contactItem.is_primary ? true : false]
);
}
}
@@ -264,8 +266,8 @@ router.put('/:id', async (req, res) => {
for (const paymentInfo of payment_infos) {
await db.query(
`INSERT INTO supplier_payment_infos (supplier_id, account_name, bank_account, bank_name, qr_code, is_primary, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[id, paymentInfo.account_name, paymentInfo.bank_account, paymentInfo.bank_name, paymentInfo.qr_code, paymentInfo.is_primary ? 1 : 0]
VALUES ($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[id, paymentInfo.account_name, paymentInfo.bank_account, paymentInfo.bank_name, paymentInfo.qr_code, paymentInfo.is_primary ? true : false]
);
}
}
@@ -293,7 +295,7 @@ router.put('/:id', async (req, res) => {
res.status(500).json({
success: false,
message: '更新供应商失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -308,7 +310,7 @@ router.delete('/:id', async (req, res) => {
// 再删除供应商数据
const result = await db.query(`DELETE FROM suppliers WHERE id = $1`, [id]);
if (result.changes > 0) {
if (result.rowCount > 0) {
res.json({
success: true,
message: '供应商删除成功'
@@ -324,7 +326,7 @@ router.delete('/:id', async (req, res) => {
res.status(500).json({
success: false,
message: '删除供应商失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -361,7 +363,7 @@ router.get('/:id/orders', async (req, res) => {
res.status(500).json({
success: false,
message: '获取供应商订单列表失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});
@@ -422,7 +424,7 @@ router.get('/:id/ledger', async (req, res) => {
res.status(500).json({
success: false,
message: '获取供应商台账失败',
error: error.message
error: process.env.NODE_ENV === 'development' ? error.message : '操作失败'
});
}
});