Browse Source

🎈 perf: 优化部分细节

Pchen. 2 months ago
parent
commit
6ed158ecd4
1 changed files with 14 additions and 15 deletions
  1. 14 15
      apis/Lepao/Account/AddAccount.js

+ 14 - 15
apis/Lepao/Account/AddAccount.js

@@ -90,12 +90,21 @@ class AddAccount extends API {
 
         if (countRows.length !== 0) {
             if (auto_run && countRows[0].total_num >= target_count && target_count !== 0)
-                return res.json({ ...BaseStdResponse.ERR, msg: '该账号累计跑步次数已达到目标次数,请尝试修改目标次数' })
+                return res.json({ ...BaseStdResponse.ERR, msg: `该账号累计跑步次数(${countRows[0].total_num})已达到目标次数,请尝试修改目标次数` })
         }
 
         const time = new Date().getTime()
 
-        let sql, r, userInfo, user_avatar
+        let sql, r, user_avatar
+
+        let userInfo = await lepaoUserInfo(student_num)
+
+        try {
+            if (auto_run && userInfo.frequency >= target_count && target_count !== 0)
+                return res.json({ ...BaseStdResponse.ERR, msg: `该账号累计跑步次数(${userInfo.frequency})已达到目标次数,请尝试修改目标次数` })
+        } catch (error) {
+            return res.json({ ...BaseStdResponse.ERR, msg: '获取用户信息失败,请联系客服或稍后再试' })
+        }
 
         // 生成用户头像
         if (email.split('@')[1].toLowerCase() === 'qq.com' && this.isQQ(email.split('@')[0])) {
@@ -105,16 +114,6 @@ class AddAccount extends API {
         }
 
         if (!id) {
-            // 获取用户信息
-            try {
-                userInfo = await lepaoUserInfo(student_num)
-
-                if (auto_run && userInfo.frequency >= target_count && target_count !== 0)
-                    return res.json({ ...BaseStdResponse.ERR, msg: `该账号累计跑步次数(${userInfo.frequency})已达到目标次数,请尝试修改目标次数` })
-            } catch (error) {
-                return res.json({ ...BaseStdResponse.ERR, msg: '获取用户信息失败,请联系客服或稍后再试' })
-            }
-
             if (countRows.length !== 0) {
                 sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, notes = ?, total_num = ?, auto_day = ?, user_avatar = ? WHERE id = ?'
                 r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, notes ?? '', userInfo.frequency, JSON.stringify(auto_day), user_avatar, countRows[0].id])
@@ -124,8 +123,8 @@ class AddAccount extends API {
                 r = await db.query(sql, [student_num, userInfo.nickName, user_avatar, userInfo.department, userInfo.id, userInfo.sex, userInfo.frequency, email, area, auto_time, auto_run, target_count, uuid, time, notes ?? '', password ?? '', JSON.stringify(auto_day)])
             }
         } else {
-            sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ?, auto_day = ?, user_avatar = ? WHERE id = ?'
-            r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), user_avatar, id])
+            sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, total_num = ?, auto_run = ?, notes = ?, auto_day = ?, user_avatar = ? WHERE id = ?'
+            r = await db.query(sql, [student_num, email, area, auto_time, target_count, userInfo.frequency, auto_run, notes ?? '', JSON.stringify(auto_day), user_avatar, id])
         }
 
         try {
@@ -142,7 +141,7 @@ class AddAccount extends API {
             res.json({
                 ...BaseStdResponse.ERR,
                 msg: "添加乐跑账号失败!",
-            });
+            })
         }
     }
 }