This commit is contained in:
董海洋
2026-05-24 17:05:26 +08:00
parent 0404d1770c
commit f6c88e5dd2
2 changed files with 28 additions and 11 deletions
+19 -2
View File
@@ -18,11 +18,28 @@ async function getGoods(ctx) {
}
if (ctx.query.keyword) {
sql += ' AND name LIKE ?'
params.push(`%${ctx.query.keyword}%`)
sql += ' AND (name LIKE ? OR barcode LIKE ?)'
params.push(`%${ctx.query.keyword}%`, `%${ctx.query.keyword}%`)
}
if (ctx.query.inStock === '1') {
sql += ' AND stock > 0'
}
const sortField = ctx.query.sortBy || 'id'
const sortOrder = ctx.query.sortOrder === 'asc' ? 'ASC' : 'DESC'
const validSortFields = ['id', 'price', 'sales', 'stock', 'created_at']
if (validSortFields.includes(sortField)) {
sql += ` ORDER BY ${sortField} ${sortOrder}`
} else {
sql += ' ORDER BY id DESC'
}
if (ctx.query.limit) {
sql += ' LIMIT ?'
params.push(parseInt(ctx.query.limit))
}
const goods = await query(sql, params)
+1 -1
View File
@@ -39,7 +39,7 @@ router.post('/', upload.single('file'), async (ctx) => {
const fileUrl = `https://donghy.top/img/${ctx.file.filename}`
ctx.body = {
code: 200,
message: '上传成功**',
message: '上传成功',
url: fileUrl
}
})