平台端绑定手机号 增加userId
This commit is contained in:
11
index.html
11
index.html
@@ -1620,7 +1620,7 @@
|
||||
console.log(params.get("userId"), 644, params.get("nickname"), params.get("headingimg"));
|
||||
|
||||
const encodedUserId = params.get("userId");
|
||||
let openId= params.get("openid")?params.get("openid"):'';
|
||||
let openId = params.get("openid") ? params.get("openid") : '';
|
||||
|
||||
const from = params.get("from");
|
||||
let token = params.get("token");//app的token
|
||||
@@ -1726,7 +1726,8 @@
|
||||
openId: openId,
|
||||
phonenumber: document.getElementById('sys-phone').value,
|
||||
smsCode: document.getElementById('code').value,
|
||||
loginPlatForm: 3
|
||||
loginPlatForm: 3,
|
||||
userId: userId
|
||||
|
||||
}
|
||||
retryFetch("https://serviceri.satabot.com/login", {
|
||||
@@ -1767,7 +1768,7 @@
|
||||
showToast("登录失败,请重试" + err); // 给用户友好提示
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
|
||||
if (document.querySelector('.popbox .loading-box')) {
|
||||
document.querySelector('.popbox .loading-box').classList.add('none');
|
||||
}
|
||||
@@ -2727,7 +2728,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshAiChatNum() {
|
||||
async function refreshAiChatNum() {
|
||||
const data = {
|
||||
userId: userId
|
||||
}
|
||||
@@ -2737,7 +2738,7 @@
|
||||
body: JSON.stringify(data) // ✅ 加上 signal
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function showpop() {
|
||||
let html = `<div class='popbox'>
|
||||
|
||||
|
||||
10
server2.js
10
server2.js
@@ -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= ?",
|
||||
|
||||
Reference in New Issue
Block a user