图片
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# 依赖目录
|
# 依赖目录
|
||||||
node_modules
|
node_modules
|
||||||
|
public
|
||||||
# 日志
|
# 日志
|
||||||
logs/
|
logs/
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
+20
-1
@@ -1,5 +1,7 @@
|
|||||||
const Router = require('koa-router');
|
const Router = require('koa-router');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const { query } = require('../config/database');
|
||||||
|
const { toRelativeUrl } = require('../utils/image-url');
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
@@ -262,10 +264,27 @@ router.post('/recognize-product', async (ctx) => {
|
|||||||
return;
|
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 = {
|
ctx.body = {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: '识别成功',
|
message: '识别成功',
|
||||||
data: productInfo
|
data: {
|
||||||
|
aiInfo: productInfo,
|
||||||
|
matchedGoods: matchedGoods
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user