This commit is contained in:
董海洋
2026-05-24 21:58:51 +08:00
parent c550f175b5
commit 295eac7925
2 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# 依赖目录
node_modules
public
# 日志
logs/
*.log
+20 -1
View File
@@ -1,5 +1,7 @@
const Router = require('koa-router');
const fetch = require('node-fetch');
const { query } = require('../config/database');
const { toRelativeUrl } = require('../utils/image-url');
const router = new Router();
@@ -262,10 +264,27 @@ router.post('/recognize-product', async (ctx) => {
return;
}
// 用 AI 识别的商品名去数据库模糊匹配
const keyword = productInfo.name || '';
let matchedGoods = [];
if (keyword) {
const dbResult = await query(
'SELECT id, name, price, unit, category_id, images, stock, pricing_type, is_hot, is_new, description, goods_no, barcode FROM goods WHERE name LIKE ? LIMIT 20',
[`%${keyword}%`]
);
matchedGoods = dbResult;
}
// 处理图片 URL
matchedGoods = processGoodsImages(matchedGoods);
ctx.body = {
code: 200,
message: '识别成功',
data: productInfo
data: {
aiInfo: productInfo,
matchedGoods: matchedGoods
}
};
} catch (error) {