API 报错

This commit is contained in:
董海洋
2026-06-04 08:20:49 +08:00
parent 21d0277a77
commit 5300551e21
7 changed files with 332 additions and 9 deletions
+42 -1
View File
@@ -139,8 +139,49 @@ async function getStockByGoodsId(ctx) {
}
}
// 获取库存变动日志
async function getStockLogs(ctx) {
const goodsId = ctx.query.goods_id
const page = parseInt(ctx.query.page) || 1
const pageSize = parseInt(ctx.query.pageSize) || 20
await ensureStockLogTable()
let sql = `
SELECT
sl.id,
sl.goods_id,
g.name as goods_name,
sl.change_type,
sl.delta,
sl.quantity_after,
sl.operator_id,
sl.remark,
sl.created_at
FROM stock_logs sl
LEFT JOIN goods g ON sl.goods_id = g.id
WHERE 1=1
`
const params = []
if (goodsId) {
sql += ' AND sl.goods_id = ?'
params.push(goodsId)
}
sql += ' ORDER BY sl.created_at DESC'
const result = await paginate(query, sql, params, page, pageSize)
ctx.body = {
code: 200,
...result
}
}
module.exports = {
getStockList,
adjustStock,
getStockByGoodsId
getStockByGoodsId,
getStockLogs
}