Pchen. 1 month ago
parent
commit
ddd210551b
1 changed files with 18 additions and 14 deletions
  1. 18 14
      apis/Lepao/Account/AddAccount.js

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

@@ -78,18 +78,6 @@ class AddAccount extends API {
             })
 
         let countSql = 'SELECT id, create_user, total_num FROM lepao_account WHERE student_num = ?'
-        countSql = `
-            SELECT 
-                a.id, a.create_user, a.total_num, e.bind_code, e.bot_account
-            FROM
-                lepao_account a
-            LEFT JOIN  
-                lepao_extra e
-            ON
-                a.student_num = e.student_num
-            WHERE 
-                a.student_num = ?
-        `
         let countRows = await db.query(countSql, [student_num])
 
         if (!countRows)
@@ -136,13 +124,29 @@ class AddAccount extends API {
 
         try {
             if (r && r.affectedRows > 0) {
+                const selectSql = `
+                                    SELECT 
+                                        a.id, a.create_user, a.total_num, e.bind_code, e.bot_account
+                                    FROM
+                                        lepao_account a
+                                    LEFT JOIN  
+                                        lepao_extra e
+                                    ON
+                                        a.student_num = e.student_num
+                                    WHERE 
+                                        a.student_num = ?
+                                `
+                const selectRows = await db.query(selectSql, [student_num])
+                if (!selectRows)
+                    return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
+
                 res.json({
                     ...BaseStdResponse.OK,
                     id: r.insertId,
                     data: {
                         student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notice_type, notes,
-                        bind_code: countRows.length !== 0 ? countRows[0].bind_code : undefined,
-                        bot_account: countRows.length !== 0 ? countRows[0].bot_account : undefined
+                        bind_code: selectRows.length !== 0 ? selectRows[0].bind_code : undefined,
+                        bot_account: selectRows.length !== 0 ? selectRows[0].bot_account : undefined
                     }
                 })
             } else {