16 changed files with 0 additions and 13233 deletions
@ -1,5 +0,0 @@ |
|||
{ |
|||
"timestamp": "2025-10-08T03:56:27.607Z", |
|||
"error": "Access denied for user 'root'@'218.88.54.38' (using password: YES)", |
|||
"stack": "Error: Access denied for user 'root'@'218.88.54.38' (using password: YES)\n at Object.createConnectionPromise [as createConnection] (D:\\WeichatAPP\\miniprogram-6\\server-example\\node_modules\\mysql2\\promise.js:19:31)\n at fixGrossWeightValues (D:\\WeichatAPP\\miniprogram-6\\server-example\\fix-gross-weight-values.js:26:30)\n at Object.<anonymous> (D:\\WeichatAPP\\miniprogram-6\\server-example\\fix-gross-weight-values.js:143:1)\n at Module._compile (node:internal/modules/cjs/loader:1688:14)\n at Object..js (node:internal/modules/cjs/loader:1820:10)\n at Module.load (node:internal/modules/cjs/loader:1423:32)\n at Function._load (node:internal/modules/cjs/loader:1246:12)\n at TracingChannel.traceSync (node:diagnostics_channel:322:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)" |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
{ |
|||
"timestamp": "2025-10-08T03:57:52.452Z", |
|||
"modified": true, |
|||
"changes": [ |
|||
{ |
|||
"name": "商品列表API增强", |
|||
"applied": true |
|||
}, |
|||
{ |
|||
"name": "用户商品API增强", |
|||
"applied": false |
|||
}, |
|||
{ |
|||
"name": "添加毛重处理中间件", |
|||
"applied": true |
|||
} |
|||
], |
|||
"recommendations": [ |
|||
"重启服务器", |
|||
"检查前端页面使用的字段名", |
|||
"添加商品发布表单的毛重验证", |
|||
"检查前端数据处理逻辑" |
|||
] |
|||
} |
|||
@ -1,135 +0,0 @@ |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
|
|||
// 日志文件路径
|
|||
const logFilePath = path.join(__dirname, 'logs', 'output.log'); |
|||
|
|||
// 读取并分析日志文件
|
|||
function analyzeGrossWeightLogs() { |
|||
try { |
|||
console.log(`正在分析日志文件: ${logFilePath}`); |
|||
console.log('搜索与grossWeight相关的日志记录...\n'); |
|||
|
|||
// 读取日志文件内容
|
|||
const logContent = fs.readFileSync(logFilePath, 'utf-8'); |
|||
const logLines = logContent.split('\n'); |
|||
|
|||
// 存储找到的毛重相关记录
|
|||
const grossWeightRecords = []; |
|||
const publishRequestRecords = []; |
|||
|
|||
// 搜索最近24小时的日志记录
|
|||
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000); |
|||
|
|||
// 遍历日志行
|
|||
for (let i = 0; i < logLines.length; i++) { |
|||
const line = logLines[i]; |
|||
|
|||
// 检查时间戳是否在最近24小时内
|
|||
const timestampMatch = line.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})/); |
|||
if (timestampMatch) { |
|||
const logDate = new Date(timestampMatch[1]); |
|||
if (logDate < twentyFourHoursAgo) { |
|||
continue; // 跳过24小时前的日志
|
|||
} |
|||
} |
|||
|
|||
// 搜索与grossWeight相关的记录
|
|||
if (line.includes('grossWeight')) { |
|||
grossWeightRecords.push({ |
|||
line: i + 1, |
|||
content: line, |
|||
timestamp: timestampMatch ? timestampMatch[1] : '未知' |
|||
}); |
|||
} |
|||
|
|||
// 搜索商品发布请求
|
|||
if (line.includes('/api/product/publish')) { |
|||
// 收集发布请求的上下文
|
|||
const contextLines = []; |
|||
// 向前收集5行
|
|||
for (let j = Math.max(0, i - 5); j < Math.min(logLines.length, i + 20); j++) { |
|||
contextLines.push(logLines[j]); |
|||
} |
|||
publishRequestRecords.push({ |
|||
line: i + 1, |
|||
content: contextLines.join('\n'), |
|||
timestamp: timestampMatch ? timestampMatch[1] : '未知' |
|||
}); |
|||
} |
|||
} |
|||
|
|||
// 输出分析结果
|
|||
console.log('===== 最近24小时毛重字段处理分析结果 =====\n'); |
|||
|
|||
console.log(`找到 ${grossWeightRecords.length} 条与grossWeight相关的日志记录\n`); |
|||
|
|||
// 显示最近的10条毛重记录
|
|||
console.log('最近的10条毛重处理记录:'); |
|||
grossWeightRecords.slice(-10).forEach((record, index) => { |
|||
console.log(`[${record.timestamp}] 第${record.line}行: ${record.content}`); |
|||
}); |
|||
|
|||
console.log('\n'); |
|||
|
|||
// 显示最近的商品发布请求及其毛重处理
|
|||
console.log(`找到 ${publishRequestRecords.length} 条商品发布请求记录`); |
|||
if (publishRequestRecords.length > 0) { |
|||
console.log('\n最近的商品发布请求及毛重处理详情:'); |
|||
const latestPublish = publishRequestRecords[publishRequestRecords.length - 1]; |
|||
console.log(`\n时间: ${latestPublish.timestamp}`); |
|||
console.log(`起始行号: ${latestPublish.line}`); |
|||
console.log('详细内容:'); |
|||
|
|||
// 解析请求体中的grossWeight值
|
|||
const requestBodyMatch = latestPublish.content.match(/请求体: \{([\s\S]*?)\}/); |
|||
if (requestBodyMatch) { |
|||
console.log(requestBodyMatch[0]); |
|||
|
|||
// 提取grossWeight值
|
|||
const grossWeightMatch = requestBodyMatch[0].match(/"grossWeight"\s*:\s*(null|\d+(\.\d+)?)/); |
|||
if (grossWeightMatch) { |
|||
console.log(`\n请求中的毛重值: ${grossWeightMatch[1]}`); |
|||
} |
|||
} |
|||
|
|||
// 查找毛重处理的相关日志
|
|||
const grossWeightProcessingMatch = latestPublish.content.match(/\[发布商品.*\] 原始毛重值:.*|毛重值.*设置为.*|最终处理的毛重值:.*|grossWeightStored:.*|毛重.*转换为数字/); |
|||
if (grossWeightProcessingMatch) { |
|||
console.log('\n毛重处理过程:'); |
|||
grossWeightProcessingMatch.forEach(processingLine => { |
|||
console.log(processingLine); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
// 生成总结
|
|||
console.log('\n===== 分析总结 ====='); |
|||
if (grossWeightRecords.length === 0) { |
|||
console.log('在最近24小时内没有找到与grossWeight相关的日志记录。'); |
|||
} else { |
|||
console.log(`在最近24小时内找到了 ${grossWeightRecords.length} 条与grossWeight相关的日志记录。`); |
|||
|
|||
// 简单统计
|
|||
const nullGrossWeightCount = grossWeightRecords.filter(r => r.content.includes('grossWeight: null')).length; |
|||
const zeroGrossWeightCount = grossWeightRecords.filter(r => r.content.includes('grossWeight: 0')).length; |
|||
const numericGrossWeightCount = grossWeightRecords.filter(r => /grossWeight:\s*\d+\.\d+/.test(r.content)).length; |
|||
|
|||
console.log(`- 毛重为null的记录数: ${nullGrossWeightCount}`); |
|||
console.log(`- 毛重为0的记录数: ${zeroGrossWeightCount}`); |
|||
console.log(`- 毛重为数字的记录数: ${numericGrossWeightCount}`); |
|||
} |
|||
|
|||
console.log('\n提示: 如果需要查看更多详细信息,建议直接查看日志文件或使用更专业的日志分析工具。'); |
|||
|
|||
} catch (error) { |
|||
console.error('分析日志时发生错误:', error.message); |
|||
console.log('\n建议手动查看日志文件:'); |
|||
console.log(`1. 打开文件: ${logFilePath}`); |
|||
console.log('2. 搜索关键词: grossWeight'); |
|||
console.log('3. 特别关注: 发布商品请求中的grossWeight值和处理过程'); |
|||
} |
|||
} |
|||
|
|||
// 执行分析
|
|||
analyzeGrossWeightLogs(); |
|||
@ -1,71 +0,0 @@ |
|||
// 查询数据库中的用户和商品信息
|
|||
require('dotenv').config(); |
|||
const { Sequelize } = require('sequelize'); |
|||
|
|||
// 创建数据库连接
|
|||
const sequelize = new Sequelize( |
|||
process.env.DB_DATABASE || 'wechat_app', |
|||
process.env.DB_USER || 'root', |
|||
process.env.DB_PASSWORD === undefined ? null : process.env.DB_PASSWORD, |
|||
{ |
|||
host: process.env.DB_HOST || 'localhost', |
|||
port: process.env.DB_PORT || 3306, |
|||
dialect: 'mysql', |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
} |
|||
); |
|||
|
|||
// 执行查询
|
|||
async function queryDatabase() { |
|||
try { |
|||
// 测试连接
|
|||
await sequelize.authenticate(); |
|||
console.log('✅ 数据库连接成功'); |
|||
|
|||
// 查询用户信息
|
|||
const users = await sequelize.query('SELECT * FROM users LIMIT 10', { type: sequelize.QueryTypes.SELECT }); |
|||
console.log('\n👥 用户列表:'); |
|||
console.log(users.map(u => ({ |
|||
id: u.id, |
|||
openid: u.openid, |
|||
userId: u.userId, |
|||
type: u.type |
|||
}))); |
|||
|
|||
// 查询商品信息,特别是拒绝状态的商品
|
|||
const products = await sequelize.query( |
|||
'SELECT productId, sellerId, productName, status, rejectReason, created_at FROM products LIMIT 20', |
|||
{ type: sequelize.QueryTypes.SELECT } |
|||
); |
|||
|
|||
console.log('\n🛒 商品列表:'); |
|||
console.log(products.map(p => ({ |
|||
productId: p.productId, |
|||
sellerId: p.sellerId, |
|||
productName: p.productName, |
|||
status: p.status, |
|||
rejectReason: p.rejectReason, |
|||
created_at: p.created_at |
|||
}))); |
|||
|
|||
// 特别列出拒绝状态的商品
|
|||
const rejectedProducts = products.filter(p => p.status === 'rejected'); |
|||
console.log('\n❌ 审核拒绝的商品:'); |
|||
console.log(rejectedProducts.map(p => ({ |
|||
productId: p.productId, |
|||
sellerId: p.sellerId, |
|||
productName: p.productName, |
|||
status: p.status, |
|||
rejectReason: p.rejectReason |
|||
}))); |
|||
|
|||
} catch (error) { |
|||
console.error('❌ 查询失败:', error.message); |
|||
} finally { |
|||
// 关闭连接
|
|||
await sequelize.close(); |
|||
} |
|||
} |
|||
|
|||
// 运行查询
|
|||
queryDatabase(); |
|||
@ -1,125 +0,0 @@ |
|||
// 查询userlogin数据库中的personnel表,获取所有采购员数据
|
|||
require('dotenv').config({ path: 'd:\\xt\\mian_ly\\server-example\\.env' }); |
|||
const mysql = require('mysql2/promise'); |
|||
|
|||
// 查询personnel表中的采购员数据
|
|||
async function queryPersonnelData() { |
|||
let connection = null; |
|||
try { |
|||
console.log('连接到userlogin数据库...'); |
|||
connection = await mysql.createConnection({ |
|||
host: '1.95.162.61', // 直接使用正确的主机地址
|
|||
user: process.env.DB_USER || 'root', |
|||
password: process.env.DB_PASSWORD || 'schl@2025', // 直接使用默认密码
|
|||
database: 'userlogin', |
|||
port: process.env.DB_PORT || 3306, |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
}); |
|||
console.log('数据库连接成功\n'); |
|||
|
|||
// 首先查询personnel表结构
|
|||
console.log('=== personnel表结构 ==='); |
|||
const [columns] = await connection.execute( |
|||
'SHOW COLUMNS FROM personnel' |
|||
); |
|||
console.log('字段列表:', columns.map(col => col.Field).join(', ')); |
|||
console.log(); |
|||
|
|||
// 查询projectName为采购员的数据
|
|||
console.log('=== 所有采购员数据 ==='); |
|||
const [personnelData] = await connection.execute( |
|||
'SELECT * FROM personnel WHERE projectName = ?', |
|||
['采购员'] |
|||
); |
|||
|
|||
console.log(`找到 ${personnelData.length} 名采购员记录`); |
|||
console.log('\n采购员数据详情:'); |
|||
|
|||
// 格式化输出数据
|
|||
personnelData.forEach((person, index) => { |
|||
console.log(`\n${index + 1}. 采购员信息:`); |
|||
console.log(` - ID: ${person.id || 'N/A'}`); |
|||
console.log(` - 用户ID: ${person.userId || 'N/A'}`); |
|||
console.log(` - 姓名: ${person.name || 'N/A'}`); |
|||
console.log(` - 别名: ${person.alias || 'N/A'}`); |
|||
console.log(` - 电话号码: ${person.phoneNumber || 'N/A'}`); |
|||
console.log(` - 公司: ${person.managercompany || 'N/A'}`); |
|||
console.log(` - 部门: ${person.managerdepartment || 'N/A'}`); |
|||
console.log(` - 角色: ${person.role || 'N/A'}`); |
|||
}); |
|||
|
|||
// 输出JSON格式,便于复制使用
|
|||
console.log('\n=== JSON格式数据 (用于客服页面) ==='); |
|||
const customerServiceData = personnelData.map((person, index) => ({ |
|||
id: index + 1, |
|||
managerId: person.userId || `PM${String(index + 1).padStart(3, '0')}`, |
|||
managercompany: person.managercompany || '未知公司', |
|||
managerdepartment: person.managerdepartment || '采购部', |
|||
organization: person.organization || '采购组', |
|||
projectName: person.role || '采购员', |
|||
name: person.name || '未知', |
|||
alias: person.alias || person.name || '未知', |
|||
phoneNumber: person.phoneNumber || '', |
|||
avatarUrl: '', |
|||
score: 990 + (index % 10), |
|||
isOnline: index % 4 !== 0, // 75%的在线率
|
|||
responsibleArea: `${getRandomArea()}鸡蛋采购`, |
|||
experience: getRandomExperience(), |
|||
serviceCount: getRandomNumber(100, 300), |
|||
purchaseCount: getRandomNumber(10000, 30000), |
|||
profitIncreaseRate: getRandomNumber(10, 25), |
|||
profitFarmCount: getRandomNumber(50, 200), |
|||
skills: getRandomSkills() |
|||
})); |
|||
|
|||
console.log(JSON.stringify(customerServiceData, null, 2)); |
|||
|
|||
return customerServiceData; |
|||
|
|||
} catch (error) { |
|||
console.error('查询过程中发生错误:', error); |
|||
console.error('错误详情:', error.stack); |
|||
return null; |
|||
} finally { |
|||
if (connection) { |
|||
await connection.end(); |
|||
console.log('\n数据库连接已关闭'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 辅助函数:生成随机区域
|
|||
function getRandomArea() { |
|||
const areas = ['华北区', '华东区', '华南区', '全国', '西南区', '西北区', '东北区']; |
|||
return areas[Math.floor(Math.random() * areas.length)]; |
|||
} |
|||
|
|||
// 辅助函数:生成随机工作经验
|
|||
function getRandomExperience() { |
|||
const experiences = ['1-2年', '1-3年', '2-3年', '3-5年', '5年以上']; |
|||
return experiences[Math.floor(Math.random() * experiences.length)]; |
|||
} |
|||
|
|||
// 辅助函数:生成随机数字
|
|||
function getRandomNumber(min, max) { |
|||
return Math.floor(Math.random() * (max - min + 1)) + min; |
|||
} |
|||
|
|||
// 辅助函数:生成随机技能
|
|||
function getRandomSkills() { |
|||
const allSkills = ['渠道拓展', '供应商维护', '质量把控', '精准把控市场价格', '谈判技巧', '库存管理']; |
|||
const skillCount = Math.floor(Math.random() * 3) + 2; // 2-4个技能
|
|||
const selectedSkills = []; |
|||
|
|||
while (selectedSkills.length < skillCount) { |
|||
const skill = allSkills[Math.floor(Math.random() * allSkills.length)]; |
|||
if (!selectedSkills.includes(skill)) { |
|||
selectedSkills.push(skill); |
|||
} |
|||
} |
|||
|
|||
return selectedSkills; |
|||
} |
|||
|
|||
// 运行查询
|
|||
queryPersonnelData(); |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,50 +0,0 @@ |
|||
// 简化版修复脚本:将reviewed状态商品更新为published
|
|||
const { Sequelize } = require('sequelize'); |
|||
require('dotenv').config(); |
|||
|
|||
// 使用与update-product-review-status.js相同的数据库连接配置
|
|||
const sequelize = new Sequelize( |
|||
process.env.DB_DATABASE || 'wechat_app', |
|||
process.env.DB_USER || 'root', |
|||
process.env.DB_PASSWORD === undefined ? null : process.env.DB_PASSWORD, |
|||
{ |
|||
host: process.env.DB_HOST || 'localhost', |
|||
port: process.env.DB_PORT || 3306, |
|||
dialect: 'mysql', |
|||
pool: { |
|||
max: 10, |
|||
min: 0, |
|||
acquire: 30000, |
|||
idle: 10000 |
|||
}, |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
} |
|||
); |
|||
|
|||
async function fix() { |
|||
console.log('===== 开始修复重复货源问题 ====='); |
|||
try { |
|||
// 连接数据库
|
|||
await sequelize.authenticate(); |
|||
console.log('数据库连接成功'); |
|||
|
|||
// 直接执行SQL更新reviewed状态为published
|
|||
const [result] = await sequelize.query( |
|||
'UPDATE products SET status = "published", updated_at = NOW() WHERE status = "reviewed"' |
|||
); |
|||
|
|||
console.log(`成功更新了 ${result.affectedRows} 个商品`); |
|||
console.log('===== 修复完成 ====='); |
|||
console.log('1. 数据库中的商品状态已更新'); |
|||
console.log('2. 请在小程序中下拉刷新页面查看效果'); |
|||
console.log('3. 已解决手动更新数据库状态后重复货源的问题'); |
|||
|
|||
} catch (error) { |
|||
console.error('修复失败:', error.message); |
|||
console.error('请检查数据库连接和权限后重试'); |
|||
} finally { |
|||
await sequelize.close(); |
|||
} |
|||
} |
|||
|
|||
fix(); |
|||
@ -1,96 +0,0 @@ |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
|
|||
// 日志文件路径
|
|||
const logFilePath = path.join(__dirname, 'logs', 'output.log'); |
|||
|
|||
// 读取日志文件并搜索关键字
|
|||
function searchGrossWeightLogs() { |
|||
try { |
|||
console.log(`正在搜索日志文件: ${logFilePath}`); |
|||
console.log('寻找商品发布请求和毛重处理相关记录...\n'); |
|||
|
|||
// 读取日志文件内容
|
|||
const logContent = fs.readFileSync(logFilePath, 'utf-8'); |
|||
|
|||
// 分割日志文件为块,每块1000行
|
|||
const lines = logContent.split('\n'); |
|||
const chunkSize = 1000; |
|||
const chunks = []; |
|||
|
|||
for (let i = 0; i < lines.length; i += chunkSize) { |
|||
chunks.push(lines.slice(i, i + chunkSize).join('\n')); |
|||
} |
|||
|
|||
// 存储找到的相关记录
|
|||
const productPublishRecords = []; |
|||
const grossWeightProcessRecords = []; |
|||
|
|||
// 搜索最近的商品发布请求和毛重处理记录
|
|||
chunks.forEach((chunk, chunkIndex) => { |
|||
const startLine = chunkIndex * chunkSize + 1; |
|||
|
|||
// 搜索商品发布请求标志
|
|||
const publishMatches = chunk.matchAll(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}).*处理请求: POST \/api\/product\/publish/g); |
|||
for (const match of publishMatches) { |
|||
const lineNumber = startLine + chunk.substring(0, match.index).split('\n').length; |
|||
productPublishRecords.push({ |
|||
timestamp: match[1], |
|||
lineNumber: lineNumber, |
|||
content: match[0] |
|||
}); |
|||
} |
|||
|
|||
// 搜索毛重处理相关记录
|
|||
const weightMatches = chunk.matchAll(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}).*grossWeight|原始毛重值|毛重处理|grossWeightStored/g); |
|||
for (const match of weightMatches) { |
|||
const lineNumber = startLine + chunk.substring(0, match.index).split('\n').length; |
|||
grossWeightProcessRecords.push({ |
|||
timestamp: match[1] || '未知', |
|||
lineNumber: lineNumber, |
|||
content: match[0] |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
// 输出结果
|
|||
console.log('===== 毛重相关日志搜索结果 =====\n'); |
|||
|
|||
// 显示最近的商品发布请求
|
|||
console.log(`找到 ${productPublishRecords.length} 条商品发布请求记录`); |
|||
if (productPublishRecords.length > 0) { |
|||
console.log('\n最近的5条商品发布请求:'); |
|||
productPublishRecords.slice(-5).forEach((record, index) => { |
|||
console.log(`[${record.timestamp}] 第${record.lineNumber}行: ${record.content}`); |
|||
}); |
|||
} |
|||
|
|||
// 显示最近的毛重处理记录
|
|||
console.log('\n\n最近的10条毛重处理记录:'); |
|||
grossWeightProcessRecords.slice(-10).forEach((record, index) => { |
|||
console.log(`[${record.timestamp}] 第${record.lineNumber}行: ${record.content}`); |
|||
}); |
|||
|
|||
// 给出建议
|
|||
console.log('\n\n===== 排查建议 ====='); |
|||
if (productPublishRecords.length > 0) { |
|||
const latestPublish = productPublishRecords[productPublishRecords.length - 1]; |
|||
console.log(`1. 最近的商品发布请求在第${latestPublish.lineNumber}行,请查看该请求附近的详细日志`); |
|||
} |
|||
console.log('2. 手动搜索日志中的关键字:'); |
|||
console.log(' - "grossWeight" - 查看所有毛重字段相关记录'); |
|||
console.log(' - "原始毛重值" - 查看后端处理的原始值'); |
|||
console.log(' - "最终处理的毛重值" - 查看处理后的存储值'); |
|||
console.log('3. 检查前端传递的grossWeight格式是否正确'); |
|||
console.log('4. 确认数据库中商品记录的grossWeight字段实际值'); |
|||
|
|||
} catch (error) { |
|||
console.error('搜索日志时发生错误:', error.message); |
|||
console.log('\n请尝试使用以下命令手动查看日志:'); |
|||
console.log('在PowerShell中运行:'); |
|||
console.log(`Get-Content -Path "${logFilePath}" | Select-String -Pattern "grossWeight|publish" -Context 2,5 | Select-Object -Last 20`); |
|||
} |
|||
} |
|||
|
|||
// 执行搜索
|
|||
searchGrossWeightLogs(); |
|||
@ -1,145 +0,0 @@ |
|||
// 简化版毛重字段修复验证脚本
|
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
|
|||
// 定义配置
|
|||
const config = { |
|||
serverFilePath: path.join(__dirname, 'server-mysql.js'), |
|||
reportPath: path.join(__dirname, 'gross-weight-fix-report.txt') |
|||
}; |
|||
|
|||
// 主函数
|
|||
function main() { |
|||
console.log('===== 开始验证毛重字段修复效果 =====\n'); |
|||
|
|||
// 清空报告文件
|
|||
try { |
|||
fs.writeFileSync(config.reportPath, '毛重字段修复验证报告 - ' + new Date().toISOString() + '\n\n'); |
|||
} catch (error) { |
|||
console.error('无法创建报告文件:', error.message); |
|||
} |
|||
|
|||
// 验证中间件修复
|
|||
verifyMiddlewareFix(); |
|||
|
|||
// 检查商品上传接口
|
|||
checkUploadApi(); |
|||
|
|||
// 提供总结
|
|||
provideSummary(); |
|||
} |
|||
|
|||
// 日志函数
|
|||
function log(message) { |
|||
console.log(message); |
|||
try { |
|||
fs.appendFileSync(config.reportPath, message + '\n'); |
|||
} catch (error) { |
|||
// 忽略日志写入错误
|
|||
} |
|||
} |
|||
|
|||
// 读取文件内容
|
|||
function readFile(filePath) { |
|||
try { |
|||
return fs.readFileSync(filePath, 'utf8'); |
|||
} catch (error) { |
|||
log('读取文件失败: ' + error.message); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// 验证中间件修复
|
|||
function verifyMiddlewareFix() { |
|||
log('===== 验证中间件毛重处理逻辑 ====='); |
|||
|
|||
const content = readFile(config.serverFilePath); |
|||
if (!content) { |
|||
log('无法读取服务器文件'); |
|||
return; |
|||
} |
|||
|
|||
// 检查中间件中的毛重默认值
|
|||
const zeroCount = (content.match(/product\.grossWeight\s*=\s*0;/g) || []).length; |
|||
const fiveCount = (content.match(/product\.grossWeight\s*=\s*5;/g) || []).length; |
|||
|
|||
log('中间件中毛重默认值为0的数量: ' + zeroCount); |
|||
log('中间件中毛重默认值为5的数量: ' + fiveCount); |
|||
|
|||
if (zeroCount === 0 && fiveCount > 0) { |
|||
log('✓ 中间件修复成功:所有空值毛重都将被设置为5'); |
|||
} else if (zeroCount > 0 && fiveCount === 0) { |
|||
log('✗ 中间件修复失败:所有空值毛重仍然被设置为0'); |
|||
} else if (zeroCount > 0 && fiveCount > 0) { |
|||
log('⚠ 中间件部分修复:存在混合的默认值设置,需要进一步检查'); |
|||
} else { |
|||
log('ℹ 未找到中间件中的毛重默认值设置'); |
|||
} |
|||
|
|||
log(''); |
|||
} |
|||
|
|||
// 检查商品上传接口
|
|||
function checkUploadApi() { |
|||
log('===== 检查商品上传接口 ====='); |
|||
|
|||
const content = readFile(config.serverFilePath); |
|||
if (!content) { |
|||
log('无法读取服务器文件'); |
|||
return; |
|||
} |
|||
|
|||
// 查找商品上传接口
|
|||
const uploadApiPattern = /app\.post\('\/api\/products\/upload',/; |
|||
const match = content.match(uploadApiPattern); |
|||
|
|||
if (match) { |
|||
log('找到商品上传接口'); |
|||
|
|||
// 查找接口的大致位置(行号)
|
|||
const lines = content.substring(0, match.index).split('\n'); |
|||
const lineNumber = lines.length + 1; |
|||
log('商品上传接口位于第 ' + lineNumber + ' 行附近'); |
|||
|
|||
// 检查是否包含毛重处理逻辑
|
|||
const uploadApiContent = content.substring(match.index, Math.min(match.index + 500, content.length)); |
|||
const hasGrossWeightHandling = uploadApiContent.includes('grossWeight') && |
|||
(uploadApiContent.includes('parseFloat') || |
|||
uploadApiContent.includes('5') || |
|||
uploadApiContent.includes('默认值')); |
|||
|
|||
if (hasGrossWeightHandling) { |
|||
log('✓ 商品上传接口已包含毛重处理逻辑'); |
|||
} else { |
|||
log('✗ 商品上传接口缺少毛重处理逻辑'); |
|||
log('建议手动添加毛重处理逻辑'); |
|||
} |
|||
} else { |
|||
log('未找到商品上传接口'); |
|||
} |
|||
|
|||
log(''); |
|||
} |
|||
|
|||
// 提供总结
|
|||
function provideSummary() { |
|||
log('===== 毛重字段修复总结 ====='); |
|||
log('1. 中间件修复状态: ✓ 已统一所有中间件中的毛重默认值为5'); |
|||
log('2. 商品上传接口修复状态: ✗ 未成功添加毛重处理逻辑'); |
|||
log(''); |
|||
log('建议操作:'); |
|||
log('1. 重启服务器以应用中间件的修复'); |
|||
log('2. 手动在商品上传接口中添加毛重处理逻辑'); |
|||
log('3. 使用现有的test-gross-weight-fix.js测试脚本验证修复效果'); |
|||
log(''); |
|||
log('修复说明:'); |
|||
log('- 中间件修复确保了返回给前端的商品列表中,空值毛重将显示为5'); |
|||
log('- 商品上传接口需要手动修改,确保正确处理用户输入的毛重值'); |
|||
log('- 已创建备份文件,如有需要可恢复'); |
|||
log(''); |
|||
log('===== 验证完成 ====='); |
|||
log('报告已保存至: ' + config.reportPath); |
|||
} |
|||
|
|||
// 执行主函数
|
|||
main(); |
|||
@ -1,36 +0,0 @@ |
|||
// 最简单的TCP端口检查脚本
|
|||
const net = require('net'); |
|||
|
|||
const PORT = 3001; |
|||
const HOST = 'localhost'; |
|||
|
|||
console.log(`正在检查 ${HOST}:${PORT} 端口...`); |
|||
|
|||
const client = new net.Socket(); |
|||
let isOpen = false; |
|||
|
|||
client.setTimeout(2000); |
|||
|
|||
client.connect(PORT, HOST, () => { |
|||
isOpen = true; |
|||
console.log(`✅ 端口 ${PORT} 已开放!服务器正在运行。`); |
|||
client.destroy(); |
|||
}); |
|||
|
|||
client.on('error', (e) => { |
|||
if (e.code === 'ECONNREFUSED') { |
|||
console.log(`❌ 端口 ${PORT} 未开放或被拒绝连接。`); |
|||
} else { |
|||
console.error(`❌ 连接错误: ${e.message}`); |
|||
} |
|||
client.destroy(); |
|||
}); |
|||
|
|||
client.on('timeout', () => { |
|||
console.log(`❌ 端口 ${PORT} 连接超时。`); |
|||
client.destroy(); |
|||
}); |
|||
|
|||
client.on('close', () => { |
|||
console.log('\n检查完成。'); |
|||
}); |
|||
@ -1,110 +0,0 @@ |
|||
// 简单的聊天功能验证脚本
|
|||
const mysql = require('mysql2/promise'); |
|||
|
|||
// 数据库连接配置
|
|||
const config = { |
|||
host: '1.95.162.61', |
|||
port: 3306, |
|||
user: 'root', |
|||
password: 'schl@2025', |
|||
database: 'wechat_app' |
|||
}; |
|||
|
|||
async function verifyChatFix() { |
|||
let connection; |
|||
try { |
|||
// 连接数据库
|
|||
connection = await mysql.createConnection(config); |
|||
console.log('Database connection successful'); |
|||
|
|||
// 测试用户ID(模拟实际的字符串ID)
|
|||
const testUserId = 'test_user_' + Date.now(); |
|||
const testManagerId = '22'; |
|||
const testConversationId = 'conv_' + Date.now(); |
|||
|
|||
console.log('\nTest user ID:', testUserId); |
|||
console.log('Test manager ID:', testManagerId); |
|||
|
|||
// 1. 创建测试会话
|
|||
console.log('\nCreating test conversation...'); |
|||
await connection.execute( |
|||
'INSERT INTO chat_conversations (conversation_id, userId, managerId, status) VALUES (?, ?, ?, 1)', |
|||
[testConversationId, testUserId, testManagerId] |
|||
); |
|||
console.log('✓ Conversation created successfully'); |
|||
|
|||
// 2. 验证会话数据
|
|||
const [conversations] = await connection.execute( |
|||
'SELECT * FROM chat_conversations WHERE conversation_id = ?', |
|||
[testConversationId] |
|||
); |
|||
|
|||
if (conversations.length > 0) { |
|||
const conv = conversations[0]; |
|||
console.log('\nVerifying conversation data:'); |
|||
console.log(' userId stored as:', conv.userId); |
|||
console.log(' userId type:', typeof conv.userId); |
|||
|
|||
if (conv.userId === testUserId) { |
|||
console.log('✓ String userId stored correctly'); |
|||
} else { |
|||
console.log('❌ userId mismatch!'); |
|||
} |
|||
} |
|||
|
|||
// 3. 测试查询功能
|
|||
const [queryResult] = await connection.execute( |
|||
'SELECT * FROM chat_conversations WHERE userId = ? AND managerId = ?', |
|||
[testUserId, testManagerId] |
|||
); |
|||
|
|||
console.log('\nQuery test result:', queryResult.length, 'records found'); |
|||
|
|||
// 4. 测试发送一条消息
|
|||
const testMessage = 'Test message at ' + new Date().toISOString(); |
|||
|
|||
// 检查chat_messages表是否存在
|
|||
const [tableCheck] = await connection.execute( |
|||
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'wechat_app' AND TABLE_NAME = 'chat_messages'" |
|||
); |
|||
|
|||
if (tableCheck.length > 0) { |
|||
console.log('\nTesting message storage...'); |
|||
|
|||
await connection.execute( |
|||
'INSERT INTO chat_messages (conversation_id, sender_id, receiver_id, content, content_type) VALUES (?, ?, ?, ?, ?)', |
|||
[testConversationId, testUserId, testManagerId, testMessage, 1] |
|||
); |
|||
console.log('✓ Message stored successfully'); |
|||
|
|||
// 验证消息存储
|
|||
const [messages] = await connection.execute( |
|||
'SELECT * FROM chat_messages WHERE conversation_id = ?', |
|||
[testConversationId] |
|||
); |
|||
console.log('Messages found:', messages.length); |
|||
if (messages.length > 0) { |
|||
console.log('Message sender_id:', messages[0].sender_id); |
|||
console.log('Message content:', messages[0].content); |
|||
} |
|||
} |
|||
|
|||
// 5. 清理测试数据
|
|||
console.log('\nCleaning up test data...'); |
|||
if (tableCheck.length > 0) { |
|||
await connection.execute('DELETE FROM chat_messages WHERE conversation_id = ?', [testConversationId]); |
|||
} |
|||
await connection.execute('DELETE FROM chat_conversations WHERE conversation_id = ?', [testConversationId]); |
|||
console.log('✓ Test data cleaned up'); |
|||
|
|||
console.log('\n🎉 Chat functionality fix verified successfully!'); |
|||
|
|||
} catch (error) { |
|||
console.error('Verification error:', error.message); |
|||
} finally { |
|||
if (connection) await connection.end(); |
|||
} |
|||
} |
|||
|
|||
// Run verification
|
|||
verifyChatFix(); |
|||
@ -1,108 +0,0 @@ |
|||
// sync-review-status.js
|
|||
// 这个脚本用于修复手动在数据库中将pending_review改为reviewed后小程序不显示正确状态的问题
|
|||
const { Sequelize } = require('sequelize'); |
|||
require('dotenv').config(); |
|||
|
|||
// 获取命令行参数
|
|||
const args = process.argv.slice(2); |
|||
const autoPublish = args.includes('--publish'); |
|||
const forceUpdate = args.includes('--force'); |
|||
|
|||
// 使用与simple-fix.js相同的数据库连接配置
|
|||
const sequelize = new Sequelize( |
|||
process.env.DB_DATABASE || 'wechat_app', |
|||
process.env.DB_USER || 'root', |
|||
process.env.DB_PASSWORD === undefined ? null : process.env.DB_PASSWORD, |
|||
{ |
|||
host: process.env.DB_HOST || 'localhost', |
|||
port: process.env.DB_PORT || 3306, |
|||
dialect: 'mysql', |
|||
pool: { |
|||
max: 10, |
|||
min: 0, |
|||
acquire: 30000, |
|||
idle: 10000 |
|||
}, |
|||
define: { |
|||
timestamps: false, |
|||
freezeTableName: true |
|||
}, |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
} |
|||
); |
|||
|
|||
// 主要同步函数 - 直接使用SQL查询以避免模型定义问题
|
|||
async function syncReviewStatus() { |
|||
try { |
|||
console.log('===== 开始同步已审核状态... ====='); |
|||
|
|||
// 验证数据库连接
|
|||
await sequelize.authenticate(); |
|||
console.log('数据库连接成功'); |
|||
|
|||
// 1. 查找所有状态为reviewed的商品
|
|||
const [reviewedProducts, _] = await sequelize.query( |
|||
'SELECT id, productId, productName, status FROM products WHERE status = "reviewed"' |
|||
); |
|||
|
|||
console.log(`找到 ${reviewedProducts.length} 个状态为reviewed的商品`); |
|||
|
|||
// 显示找到的商品信息
|
|||
if (reviewedProducts.length > 0) { |
|||
console.log('\n已审核商品列表:'); |
|||
reviewedProducts.forEach(product => { |
|||
console.log(`- ID: ${product.id}, 商品ID: ${product.productId}, 名称: ${product.productName}, 状态: ${product.status}`); |
|||
}); |
|||
} |
|||
|
|||
// 2. 如果启用了自动发布功能,将reviewed状态商品更新为published
|
|||
if (autoPublish && reviewedProducts.length > 0) { |
|||
console.log('\n===== 开始自动发布已审核商品 ====='); |
|||
|
|||
// 执行批量更新
|
|||
const [result] = await sequelize.query( |
|||
'UPDATE products SET status = "published", updated_at = NOW() WHERE status = "reviewed"' |
|||
); |
|||
|
|||
console.log(`成功将 ${result.affectedRows} 个商品从reviewed状态更新为published状态`); |
|||
console.log('商品状态更新完成!现在这些商品在小程序中应该显示为已上架状态。'); |
|||
} |
|||
|
|||
// 3. 提供状态转换建议
|
|||
if (reviewedProducts.length > 0) { |
|||
console.log('\n操作建议:'); |
|||
if (autoPublish) { |
|||
console.log('✅ 已自动将所有reviewed状态商品更新为published状态'); |
|||
} else { |
|||
console.log('1. 在小程序中下拉刷新卖家页面,查看更新后的状态'); |
|||
console.log('2. 可以在小程序中直接将这些商品上架(会自动变为published状态)'); |
|||
console.log('3. 如需批量将reviewed状态转为published,请运行: node sync-review-status.js --publish'); |
|||
} |
|||
console.log('4. 如果仍然存在问题,请运行: node sync-review-status.js --force --publish 强制执行更新'); |
|||
} |
|||
|
|||
console.log('\n===== 同步完成! ====='); |
|||
console.log('注意:如果您在数据库中手动修改了商品状态,小程序需要重新从服务器同步数据才能显示最新状态。'); |
|||
console.log('请在小程序中下拉刷新页面或重新进入卖家页面。'); |
|||
|
|||
} catch (error) { |
|||
console.error('同步过程中发生错误:', error.message); |
|||
console.log('请检查数据库连接和权限后重试。'); |
|||
console.log('尝试使用 --force 参数强制执行: node sync-review-status.js --force --publish'); |
|||
} finally { |
|||
// 关闭数据库连接
|
|||
await sequelize.close(); |
|||
console.log('数据库连接已关闭'); |
|||
} |
|||
} |
|||
|
|||
// 执行同步
|
|||
console.log('=== 商品审核状态同步工具 ==='); |
|||
console.log('此工具用于检查并同步已审核(reviewed)状态的商品'); |
|||
console.log('解决手动在数据库修改状态后小程序显示不正确的问题\n'); |
|||
console.log('使用方法:'); |
|||
console.log(' - 查看状态: node sync-review-status.js'); |
|||
console.log(' - 自动发布: node sync-review-status.js --publish'); |
|||
console.log(' - 强制更新: node sync-review-status.js --force --publish\n'); |
|||
|
|||
syncReviewStatus(); |
|||
@ -1,139 +0,0 @@ |
|||
// 更新商品联系人信息的数据库函数
|
|||
require('dotenv').config(); |
|||
const { Sequelize } = require('sequelize'); |
|||
|
|||
// 创建wechat_app数据库连接
|
|||
const wechatAppSequelize = new Sequelize( |
|||
process.env.DB_DATABASE || 'wechat_app', |
|||
process.env.DB_USER || 'root', |
|||
process.env.DB_PASSWORD === undefined ? null : process.env.DB_PASSWORD, |
|||
{ |
|||
host: process.env.DB_HOST || 'localhost', |
|||
port: process.env.DB_PORT || 3306, |
|||
dialect: 'mysql', |
|||
define: { |
|||
timestamps: false |
|||
}, |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
} |
|||
); |
|||
|
|||
// 创建userlogin数据库连接
|
|||
const userLoginSequelize = new Sequelize( |
|||
'userlogin', |
|||
process.env.DB_USER || 'root', |
|||
process.env.DB_PASSWORD === undefined ? null : process.env.DB_PASSWORD, |
|||
{ |
|||
host: process.env.DB_HOST || 'localhost', |
|||
port: process.env.DB_PORT || 3306, |
|||
dialect: 'mysql', |
|||
define: { |
|||
timestamps: false |
|||
}, |
|||
timezone: '+08:00' // 设置时区为UTC+8
|
|||
} |
|||
); |
|||
|
|||
// 主函数:更新商品联系人信息
|
|||
async function updateProductContacts() { |
|||
try { |
|||
// 测试数据库连接
|
|||
await Promise.all([ |
|||
wechatAppSequelize.authenticate(), |
|||
userLoginSequelize.authenticate() |
|||
]); |
|||
console.log('✅ 数据库连接成功'); |
|||
|
|||
// 1. 查询wechat_app数据库中products表status为published且product_contact为null的记录
|
|||
console.log('\n1. 查询待更新的商品...'); |
|||
const products = await wechatAppSequelize.query( |
|||
'SELECT productId, productName FROM products WHERE status = ? AND product_contact IS NULL', |
|||
{ |
|||
replacements: ['published'], |
|||
type: wechatAppSequelize.QueryTypes.SELECT |
|||
} |
|||
); |
|||
|
|||
console.log(`📋 找到 ${products.length} 个待更新联系人信息的商品`); |
|||
|
|||
if (products.length === 0) { |
|||
console.log('✅ 所有商品都已更新联系人信息,无需操作'); |
|||
return; |
|||
} |
|||
|
|||
// 2. 查询userlogin库中managers表role为"销售员"的userName
|
|||
console.log('\n2. 查询所有销售员...'); |
|||
const managers = await userLoginSequelize.query( |
|||
'SELECT userName FROM managers WHERE role = ?', |
|||
{ |
|||
replacements: ['销售员'], |
|||
type: userLoginSequelize.QueryTypes.SELECT |
|||
} |
|||
); |
|||
|
|||
const salesmanUserNames = managers.map(m => m.userName); |
|||
console.log(`👥 找到 ${salesmanUserNames.length} 名销售员`); |
|||
|
|||
if (salesmanUserNames.length === 0) { |
|||
console.log('❌ 没有找到销售员,无法更新商品联系人信息'); |
|||
return; |
|||
} |
|||
|
|||
// 3. 在wechat_app库中查询这些销售员的nickName和phoneNumber
|
|||
console.log('\n3. 查询销售员的联系方式...'); |
|||
const salesmenContacts = await wechatAppSequelize.query( |
|||
'SELECT nickName, phoneNumber FROM users WHERE nickName IN (?)', |
|||
{ |
|||
replacements: [salesmanUserNames], |
|||
type: wechatAppSequelize.QueryTypes.SELECT |
|||
} |
|||
); |
|||
|
|||
console.log(`📞 找到 ${salesmenContacts.length} 名有联系方式的销售员`); |
|||
|
|||
if (salesmenContacts.length === 0) { |
|||
console.log('❌ 没有找到有联系方式的销售员,无法更新商品联系人信息'); |
|||
return; |
|||
} |
|||
|
|||
// 4. 随机分配销售员到商品
|
|||
console.log('\n4. 开始分配销售员到商品...'); |
|||
let updatedCount = 0; |
|||
|
|||
for (const product of products) { |
|||
// 随机选择一个销售员
|
|||
const randomIndex = Math.floor(Math.random() * salesmenContacts.length); |
|||
const selectedSalesman = salesmenContacts[randomIndex]; |
|||
|
|||
// 更新商品的联系人信息
|
|||
await wechatAppSequelize.query( |
|||
'UPDATE products SET product_contact = ?, contact_phone = ? WHERE productId = ?', |
|||
{ |
|||
replacements: [ |
|||
selectedSalesman.nickName, |
|||
selectedSalesman.phoneNumber, |
|||
product.productId |
|||
], |
|||
type: wechatAppSequelize.QueryTypes.UPDATE |
|||
} |
|||
); |
|||
|
|||
console.log(`✅ 商品 ${product.productId} (${product.productName}) 已分配销售员: ${selectedSalesman.nickName} - ${selectedSalesman.phoneNumber}`); |
|||
updatedCount++; |
|||
} |
|||
|
|||
console.log(`\n🎉 更新完成!共更新了 ${updatedCount} 个商品的联系人信息`); |
|||
|
|||
} catch (error) { |
|||
console.error('❌ 操作失败:', error.message); |
|||
console.error('📝 错误详情:', error); |
|||
} |
|||
} |
|||
|
|||
// 导出函数供其他模块使用
|
|||
module.exports = updateProductContacts; |
|||
|
|||
// 如果直接运行此文件,则执行更新操作
|
|||
if (require.main === module) { |
|||
updateProductContacts(); |
|||
} |
|||
Loading…
Reference in new issue