Browse Source

✨ feat: 添加用户时用自动识别用户QQ头像

Pchen. 1 month ago
parent
commit
9d922da800
1 changed files with 11 additions and 5 deletions
  1. 11 5
      apis/Lepao/Account/AddAccount.js

+ 11 - 5
apis/Lepao/Account/AddAccount.js

@@ -102,19 +102,25 @@ class AddAccount extends API {
         }
         }
 
 
         const time = new Date().getTime()
         const time = new Date().getTime()
+        let sql, r, user_avatar
 
 
-        let sql, r
+        // 生成用户头像
+        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) {
         if (!id) {
             if (countRows.length !== 0) {
             if (countRows.length !== 0) {
-                sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, update_time = ?, notes = ?, auto_day = ?, notice_type = ? WHERE id = ?'
-                r = await db.query(sql, [uuid, email ?? '', area, auto_time, auto_run, targetKm, time, time, notes ?? '', JSON.stringify(auto_day), notice_type, countRows[0].id])
+                sql = 'UPDATE lepao_account SET create_user = ?, email = ?, user_avatar = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, update_time = ?, notes = ?, auto_day = ?, notice_type = ? WHERE id = ?'
+                r = await db.query(sql, [uuid, email ?? '', user_avatar ?? '', area, auto_time, auto_run, targetKm, time, time, notes ?? '', JSON.stringify(auto_day), notice_type, countRows[0].id])
             }
             }
             else {
             else {
                 const bind_code = await this.generateCode()
                 const bind_code = await this.generateCode()
 
 
-                sql = 'INSERT INTO lepao_account (student_num, email, area, auto_time, auto_run, target_count, create_user, create_time, notes, auto_day, notice_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
-                r = await db.query(sql, [student_num, email ?? '', area, auto_time, auto_run, targetKm, uuid, time, notes ?? '', JSON.stringify(auto_day), notice_type])
+                sql = 'INSERT INTO lepao_account (student_num, email, user_avatar, area, auto_time, auto_run, target_count, create_user, create_time, notes, auto_day, notice_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
+                r = await db.query(sql, [student_num, email ?? '', user_avatar ?? '', area, auto_time, auto_run, targetKm, uuid, time, notes ?? '', JSON.stringify(auto_day), notice_type])
 
 
                 let faceSql = 'INSERT INTO lepao_extra (student_num, bind_code) VALUES (?, ?)'
                 let faceSql = 'INSERT INTO lepao_extra (student_num, bind_code) VALUES (?, ?)'
                 let faceRows = await db.query(faceSql, [student_num, bind_code])
                 let faceRows = await db.query(faceSql, [student_num, bind_code])