平台端绑定手机号 增加userId

This commit is contained in:
2025-12-29 13:47:13 +08:00
parent 631df78da6
commit f759ac1476
2 changed files with 6 additions and 15 deletions

View File

@@ -903,7 +903,6 @@ async function hasQuota(userId) {
async function getQuota(userId) {
const m = getMutex(userId);
return await m.runExclusive(async () => {
console.log("获取用户对话次数1:", userId, aiChatNum);
console.log("获取用户对话次数:", userId, aiChatNum.get(userId));
return aiChatNum.get(userId);
});
@@ -920,7 +919,6 @@ async function removeQuota(userId) {
// ====================== API ======================
app.post("/refreshAiChatNum", async (req, res) => {
const { userId } = req.body;
console.log(userId,"刷新对话次数");
try {
const [userRemainChatNum] = await pool.query(
"SELECT ai_chat_num from sys_user where user_id= ?",
@@ -941,18 +939,13 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
try
{
const exists = await hasQuota(userId);
console.log(exists,"exists");
if (!exists) {
const [userRemainChatNum] = await pool.query(
"SELECT ai_chat_num from sys_user where user_id= ?",
[userId]
);
console.log(userRemainChatNum,"userRemainChatNum");
if (userRemainChatNum.length > 0) {
const quota = userRemainChatNum[0].ai_chat_num;
console.log(quota,"quota");
console.log(quota <= 0 && quota !== -1,"quota2");
if (quota <= 0 && quota !== -1) {
return res.status(400).json({ error: "对话次数已用完,请完成账号注册" });
}
@@ -1271,12 +1264,9 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
}
finally {
let userChatNum = await getQuota(userId);
console.log(userChatNum,"userChatNum2");
if (userChatNum !== -1 && userChatNum !== undefined) {
userChatNum = Math.max(0, userChatNum - 1); // 防止变成负数
console.log(userChatNum,"userChatNum最终");
await setQuota(userId, userChatNum);
console.log(`用户剩余AI 对话次数: ${userChatNum}`);
// 更新数据库
await pool.query(
"update sys_user set ai_chat_num = ? where user_id= ?",