平台端绑定手机号 增加userId
This commit is contained in:
@@ -1620,7 +1620,7 @@
|
|||||||
console.log(params.get("userId"), 644, params.get("nickname"), params.get("headingimg"));
|
console.log(params.get("userId"), 644, params.get("nickname"), params.get("headingimg"));
|
||||||
|
|
||||||
const encodedUserId = params.get("userId");
|
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");
|
const from = params.get("from");
|
||||||
let token = params.get("token");//app的token
|
let token = params.get("token");//app的token
|
||||||
@@ -1726,7 +1726,8 @@
|
|||||||
openId: openId,
|
openId: openId,
|
||||||
phonenumber: document.getElementById('sys-phone').value,
|
phonenumber: document.getElementById('sys-phone').value,
|
||||||
smsCode: document.getElementById('code').value,
|
smsCode: document.getElementById('code').value,
|
||||||
loginPlatForm: 3
|
loginPlatForm: 3,
|
||||||
|
userId: userId
|
||||||
|
|
||||||
}
|
}
|
||||||
retryFetch("https://serviceri.satabot.com/login", {
|
retryFetch("https://serviceri.satabot.com/login", {
|
||||||
|
|||||||
10
server2.js
10
server2.js
@@ -903,7 +903,6 @@ async function hasQuota(userId) {
|
|||||||
async function getQuota(userId) {
|
async function getQuota(userId) {
|
||||||
const m = getMutex(userId);
|
const m = getMutex(userId);
|
||||||
return await m.runExclusive(async () => {
|
return await m.runExclusive(async () => {
|
||||||
console.log("获取用户对话次数1:", userId, aiChatNum);
|
|
||||||
console.log("获取用户对话次数:", userId, aiChatNum.get(userId));
|
console.log("获取用户对话次数:", userId, aiChatNum.get(userId));
|
||||||
return aiChatNum.get(userId);
|
return aiChatNum.get(userId);
|
||||||
});
|
});
|
||||||
@@ -920,7 +919,6 @@ async function removeQuota(userId) {
|
|||||||
// ====================== API ======================
|
// ====================== API ======================
|
||||||
app.post("/refreshAiChatNum", async (req, res) => {
|
app.post("/refreshAiChatNum", async (req, res) => {
|
||||||
const { userId } = req.body;
|
const { userId } = req.body;
|
||||||
console.log(userId,"刷新对话次数");
|
|
||||||
try {
|
try {
|
||||||
const [userRemainChatNum] = await pool.query(
|
const [userRemainChatNum] = await pool.query(
|
||||||
"SELECT ai_chat_num from sys_user where user_id= ?",
|
"SELECT ai_chat_num from sys_user where user_id= ?",
|
||||||
@@ -941,18 +939,13 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const exists = await hasQuota(userId);
|
const exists = await hasQuota(userId);
|
||||||
console.log(exists,"exists");
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
const [userRemainChatNum] = await pool.query(
|
const [userRemainChatNum] = await pool.query(
|
||||||
"SELECT ai_chat_num from sys_user where user_id= ?",
|
"SELECT ai_chat_num from sys_user where user_id= ?",
|
||||||
[userId]
|
[userId]
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(userRemainChatNum,"userRemainChatNum");
|
|
||||||
if (userRemainChatNum.length > 0) {
|
if (userRemainChatNum.length > 0) {
|
||||||
const quota = userRemainChatNum[0].ai_chat_num;
|
const quota = userRemainChatNum[0].ai_chat_num;
|
||||||
console.log(quota,"quota");
|
|
||||||
console.log(quota <= 0 && quota !== -1,"quota2");
|
|
||||||
if (quota <= 0 && quota !== -1) {
|
if (quota <= 0 && quota !== -1) {
|
||||||
return res.status(400).json({ error: "对话次数已用完,请完成账号注册" });
|
return res.status(400).json({ error: "对话次数已用完,请完成账号注册" });
|
||||||
}
|
}
|
||||||
@@ -1271,12 +1264,9 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
let userChatNum = await getQuota(userId);
|
let userChatNum = await getQuota(userId);
|
||||||
console.log(userChatNum,"userChatNum2");
|
|
||||||
if (userChatNum !== -1 && userChatNum !== undefined) {
|
if (userChatNum !== -1 && userChatNum !== undefined) {
|
||||||
userChatNum = Math.max(0, userChatNum - 1); // 防止变成负数
|
userChatNum = Math.max(0, userChatNum - 1); // 防止变成负数
|
||||||
console.log(userChatNum,"userChatNum最终");
|
|
||||||
await setQuota(userId, userChatNum);
|
await setQuota(userId, userChatNum);
|
||||||
console.log(`用户剩余AI 对话次数: ${userChatNum}`);
|
|
||||||
// 更新数据库
|
// 更新数据库
|
||||||
await pool.query(
|
await pool.query(
|
||||||
"update sys_user set ai_chat_num = ? where user_id= ?",
|
"update sys_user set ai_chat_num = ? where user_id= ?",
|
||||||
|
|||||||
Reference in New Issue
Block a user