API 报错
This commit is contained in:
+42
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user