图片
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
# 依赖目录
|
||||
node_modules
|
||||
|
||||
public
|
||||
# 日志
|
||||
logs/
|
||||
*.log
|
||||
@@ -18,4 +18,4 @@ logs/
|
||||
|
||||
# 系统文件
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
Thumbs.db
|
||||
|
||||
+20
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user