|
|
|
@ -1965,9 +1965,14 @@ app.get('/api/admin/stats/supplies', async (req, res) => { |
|
|
|
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); |
|
|
|
timeCondition = `AND created_at >= '${weekAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'month') { |
|
|
|
// 本月
|
|
|
|
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); |
|
|
|
timeCondition = `AND created_at >= '${monthAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
// 本月(从本月1日到当前日期)
|
|
|
|
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1); |
|
|
|
timeCondition = `AND created_at >= '${monthStart.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'lastMonth') { |
|
|
|
// 上个月(从上月1日到上月最后一天)
|
|
|
|
const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1); |
|
|
|
const lastMonthEnd = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999); |
|
|
|
timeCondition = `AND created_at >= '${lastMonthStart.toISOString().slice(0, 19).replace('T', ' ')}' AND created_at <= '${lastMonthEnd.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'custom') { |
|
|
|
// 自定义时间范围
|
|
|
|
const { startDate, endDate } = req.query; |
|
|
|
@ -2012,12 +2017,6 @@ app.get('/api/admin/stats/supplies', async (req, res) => { |
|
|
|
|
|
|
|
connection.release(); |
|
|
|
|
|
|
|
// 调试日志:检查API返回数据结构
|
|
|
|
console.log('stats API返回的chartData:', chartData); |
|
|
|
console.log('stats API返回的totalSupplies:', totalSupplies); |
|
|
|
console.log('stats API返回的totalUsers:', totalUsers); |
|
|
|
console.log('stats API返回的avgPerUser:', avgPerUser); |
|
|
|
|
|
|
|
sendResponse(res, true, { |
|
|
|
chartData, |
|
|
|
stats: { |
|
|
|
@ -2064,9 +2063,14 @@ app.get('/api/admin/supplies', async (req, res) => { |
|
|
|
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); |
|
|
|
timeCondition = `AND created_at >= '${weekAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'month') { |
|
|
|
// 本月
|
|
|
|
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); |
|
|
|
timeCondition = `AND created_at >= '${monthAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
// 本月(从本月1日到当前日期)
|
|
|
|
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1); |
|
|
|
timeCondition = `AND created_at >= '${monthStart.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'lastMonth') { |
|
|
|
// 上个月(从上月1日到上月最后一天)
|
|
|
|
const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1); |
|
|
|
const lastMonthEnd = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999); |
|
|
|
timeCondition = `AND created_at >= '${lastMonthStart.toISOString().slice(0, 19).replace('T', ' ')}' AND created_at <= '${lastMonthEnd.toISOString().slice(0, 19).replace('T', ' ')}'`; |
|
|
|
} else if (filter === 'custom') { |
|
|
|
// 自定义时间范围
|
|
|
|
const { startDate, endDate } = req.query; |
|
|
|
@ -2107,23 +2111,6 @@ app.get('/api/admin/supplies', async (req, res) => { |
|
|
|
|
|
|
|
connection.release(); |
|
|
|
|
|
|
|
// 调试日志:检查查询结果中是否包含product_log字段
|
|
|
|
console.log('查询到的货源数量:', supplies.length); |
|
|
|
if (supplies.length > 0) { |
|
|
|
console.log('第一个货源的所有字段和值:', JSON.stringify(supplies[0], null, 2)); |
|
|
|
console.log('第一个货源的字段:', Object.keys(supplies[0])); |
|
|
|
console.log('第一个货源是否包含product_log字段:', 'product_log' in supplies[0]); |
|
|
|
if ('product_log' in supplies[0]) { |
|
|
|
console.log('第一个货源的product_log值:', supplies[0].product_log); |
|
|
|
console.log('第一个货源的product_log类型:', typeof supplies[0].product_log); |
|
|
|
} else { |
|
|
|
console.log('第一个货源不包含product_log字段,可能的原因:'); |
|
|
|
console.log('1. 数据库中products表可能没有product_log字段'); |
|
|
|
console.log('2. 字段名称可能拼写错误'); |
|
|
|
console.log('3. 查询语句可能有问题'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sendResponse(res, true, { supplies }, '获取货源列表成功'); |
|
|
|
} catch (error) { |
|
|
|
console.error('获取货源列表失败:', error.message); |
|
|
|
@ -2159,9 +2146,6 @@ app.post('/api/supplies/log', async (req, res) => { |
|
|
|
); |
|
|
|
userLoginConnection.release(); |
|
|
|
|
|
|
|
// 打印查询结果,查看是否包含company和organization字段
|
|
|
|
console.log('查询到的personnel信息:', personnelResult[0]); |
|
|
|
|
|
|
|
// 自动计算变更字段
|
|
|
|
let calculatedChangedFields = changedFields; |
|
|
|
if (operationEvent.includes('编辑') && originalData && modifiedData && !changedFields) { |
|
|
|
@ -2199,9 +2183,6 @@ app.post('/api/supplies/log', async (req, res) => { |
|
|
|
// 如果找到了员工信息,使用真实的员工数据
|
|
|
|
if (personnelResult.length > 0) { |
|
|
|
const personnelInfo = personnelResult[0]; |
|
|
|
// 检查personnelInfo中的字段名,确保使用正确的字段名
|
|
|
|
console.log('personnelInfo的所有字段:', Object.keys(personnelInfo)); |
|
|
|
|
|
|
|
// 使用正确的字段名:managercompany(公司)、managerdepartment(部门)、organization(组织)
|
|
|
|
logData.tracompany = personnelInfo.managercompany || personnelInfo.managerCompany || personnelInfo.MANAGERCOMPANY || ''; |
|
|
|
logData.tradepartment = personnelInfo.managerdepartment || personnelInfo.managerDepartment || personnelInfo.MANAGERDEPARTMENT || ''; |
|
|
|
|