From cb0a7ee68da5d84cc835282f868846f609946c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Mon, 9 Feb 2026 13:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0goods=5Froot=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=92=8C/api/goods/root=E7=AB=AF=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-example/server-mysql.js | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index 0c577ee..09b4020 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -2116,6 +2116,31 @@ Cover.init({ timestamps: false }); +// goods_root模型 - 用于存储小品种和大贸易的创建者 +class GoodsRoot extends Model { } +GoodsRoot.init({ + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + name: { + type: DataTypes.STRING(100), + allowNull: false, + comment: '创建者姓名' + }, + root: { + type: DataTypes.STRING(50), + allowNull: false, + comment: '分类:小品种或大贸易' + } +}, { + sequelize, + modelName: 'GoodsRoot', + tableName: 'goods_root', + timestamps: false +}); + // 简道云销售订单主表模型(新添加) class JdSalesMain extends Model { } JdSalesMain.init({ @@ -3156,6 +3181,43 @@ app.post('/api/user/get', async (req, res) => { } }); +// 获取goods_root数据 +app.post('/api/goods/root', async (req, res) => { + try { + console.log('===== 获取goods_root数据请求 ====='); + console.log('1. 收到请求体:', JSON.stringify(req.body, null, 2)); + + // 从数据库获取goods_root表中的所有数据 + const roots = await GoodsRoot.findAll(); + console.log('2. 数据库查询结果数量:', roots.length); + console.log('3. 数据库查询结果:', roots); + + // 格式化响应数据 + const formattedRoots = roots.map(root => ({ + id: root.id, + name: root.name, + root: root.root + })); + + console.log('4. 格式化后的结果:', formattedRoots); + + res.json({ + success: true, + code: 200, + message: '获取goods_root数据成功', + roots: formattedRoots + }); + } catch (error) { + console.error('获取goods_root数据失败:', error); + res.status(500).json({ + success: false, + code: 500, + message: '获取goods_root数据失败', + error: error.message + }); + } +}); + // 添加用户踪迹记录 app.post('/api/user-trace/add', async (req, res) => { try {