Ai config

This commit is contained in:
董海洋
2026-05-26 13:37:55 +08:00
parent 55452a2d21
commit 0c7ed3498d
42 changed files with 1264 additions and 767 deletions
+18 -9
View File
@@ -1,4 +1,5 @@
const { query } = require('../config/database')
const { query, transaction } = require('../config/database')
const { paginate } = require('../utils/pagination')
async function getPointsGoods(ctx) {
let sql = 'SELECT * FROM points_goods WHERE 1=1'
@@ -9,6 +10,13 @@ async function getPointsGoods(ctx) {
}
sql += ' ORDER BY points ASC'
if (ctx.query.page) {
const result = await paginate(query, sql, params, ctx.query.page, ctx.query.pageSize)
ctx.body = { code: 200, ...result }
return
}
const goods = await query(sql, params)
ctx.body = {
@@ -115,14 +123,15 @@ async function exchangePointsGoods(ctx) {
return
}
const newPoints = user.points - totalPoints
await query('UPDATE users SET points = ? WHERE id = ?', [newPoints, userId])
await query('UPDATE points_goods SET stock = stock - ? WHERE id = ?', [qty, goodsId])
await query(
'INSERT INTO points_logs (user_id, type, amount, description) VALUES (?, ?, ?, ?)',
[userId, 'spend', totalPoints, `兑换「${goodsItem.name}」x${qty}`]
)
await transaction(async (conn) => {
const newPoints = user.points - totalPoints
await conn.execute('UPDATE users SET points = ? WHERE id = ?', [newPoints, userId])
await conn.execute('UPDATE points_goods SET stock = stock - ? WHERE id = ?', [qty, goodsId])
await conn.execute(
'INSERT INTO points_logs (user_id, type, amount, description) VALUES (?, ?, ?, ?)',
[userId, 'spend', totalPoints, `兑换「${goodsItem.name}」x${qty}`]
)
})
ctx.body = {
code: 200,