Browse Source

✨ feat: 更新用户头像生成方式

Pchen. 2 months ago
parent
commit
b4bf9a3b89
1 changed files with 13 additions and 12 deletions
  1. 13 12
      apis/Lepao/Account/AddAccount.js

+ 13 - 12
apis/Lepao/Account/AddAccount.js

@@ -95,7 +95,14 @@ class AddAccount extends API {
 
         const time = new Date().getTime()
 
-        let sql, r, userInfo
+        let sql, r, userInfo, user_avatar
+
+        // 生成用户头像
+        if (email.split('@')[1].toLowerCase() === 'qq.com' && this.isQQ(email.split('@')[0])) {
+            user_avatar = `https://q2.qlogo.cn/headimg_dl?dst_uin=${email}&spec=640`
+        } else {
+            user_avatar = userInfo.sex === 0 ? 'https://lepao-cloud.xxoo365.top/view.php/aee85ff43fd30d0df03c6a7dd9797d22.png' : 'https://lepao-cloud.xxoo365.top/view.php/fcb54dcc5e6209381e972ef73bdb4a93.png'
+        }
 
         if (!id) {
             // 获取用户信息
@@ -109,22 +116,16 @@ class AddAccount extends API {
             }
 
             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 = ?WHERE id = ?'
-                r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, notes ?? '', userInfo.frequency, JSON.stringify(auto_day), countRows[0].id])
+                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])
             }
             else {
-                let user_avatar = ''
-                if (email.split('@')[1].toLowerCase() === 'qq.com' && this.isQQ(email.split('@')[0])) {
-                    user_avatar = `https://q2.qlogo.cn/headimg_dl?dst_uin=${email}&spec=640`
-                } else {
-                    user_avatar = userInfo.sex === 0 ? 'https://lepao-cloud.xxoo365.top/view.php/aee85ff43fd30d0df03c6a7dd9797d22.png' : 'https://lepao-cloud.xxoo365.top/view.php/fcb54dcc5e6209381e972ef73bdb4a93.png'
-                }
                 sql = 'INSERT INTO lepao_account (student_num, name, user_avatar,  grade_id, uid, sex, total_num, email, area, auto_time, auto_run, target_count, create_user, create_time, notes, password, auto_day) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
-                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)])
+                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 = ? WHERE id = ?'
-            r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), id])
+            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])
         }
 
         try {