diff --git a/scoreManager.js b/scoreManager.js new file mode 100644 index 0000000..5aebd1c --- /dev/null +++ b/scoreManager.js @@ -0,0 +1,22 @@ +const pool = require('../db'); + +async function updateScore(req, res) { + const { student_id, points } = req.body; //假设前端发送的数据是这两部分 + + try { + const connection = await pool.getConnection(); + const [result] = await connection.query('UPDATE students SET score = score + ?, call_count = call_count + 1 WHERE student_id = ?', [points, student_id]); + + if (result.affectedRows > 0) { + res.send({ message: '积分已更新' }); + } else { + res.status(404).send({ message: '学生不存在' }); + } + + connection.release(); + } catch (error) { + res.status(500).send({ error: '更新积分失败' }); + } +} + +module.exports = { updateScore };