Browse Source

🐞 fix: 修复部分bug

Pchen. 1 month ago
parent
commit
66b8c9291e

+ 39 - 20
apis/Lepao/Account/AddAccount.js

@@ -36,7 +36,7 @@ class AddAccount extends API {
     }
     }
 
 
     async onRequest(req, res) {
     async onRequest(req, res) {
-        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notes } = req.body
+        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notice_type, notes } = req.body
 
 
         if ([uuid, session, student_num, email, auto_time, target_count, auto_day].some(value => value === '' || value === null || value === undefined))
         if ([uuid, session, student_num, email, auto_time, target_count, auto_day].some(value => value === '' || value === null || value === undefined))
             return res.json({
             return res.json({
@@ -50,19 +50,21 @@ class AddAccount extends API {
             })
             })
         }
         }
 
 
-        if (!this.emailRegex.test(email)) {
-            return res.json({
-                ...BaseStdResponse.ERR,
-                msg: '请检查邮箱格式是否正确'
-            })
-        }
+        if (notice_type === 'email') {
+            if (!this.emailRegex.test(email)) {
+                return res.json({
+                    ...BaseStdResponse.ERR,
+                    msg: '请检查邮箱格式是否正确'
+                })
+            }
 
 
-        const emailDomain = email.split('@')[1].toLowerCase()
-        if (this.banEmailList.includes(emailDomain))
-            return res.json({
-                ...BaseStdResponse.ERR,
-                msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
-            })
+            const emailDomain = email.split('@')[1].toLowerCase()
+            if (this.banEmailList.includes(emailDomain))
+                return res.json({
+                    ...BaseStdResponse.ERR,
+                    msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
+                })
+        }
 
 
         if (auto_run === 1 && (!Array.isArray(auto_day) || !auto_day.every(v => Number.isInteger(v) && v >= 0 && v <= 6)))
         if (auto_run === 1 && (!Array.isArray(auto_day) || !auto_day.every(v => Number.isInteger(v) && v >= 0 && v <= 6)))
             return res.json({
             return res.json({
@@ -76,6 +78,18 @@ class AddAccount extends API {
             })
             })
 
 
         let countSql = 'SELECT id, create_user, total_num FROM lepao_account WHERE student_num = ?'
         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])
         let countRows = await db.query(countSql, [student_num])
 
 
         if (!countRows)
         if (!countRows)
@@ -101,14 +115,14 @@ class AddAccount extends API {
 
 
         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 = ? WHERE id = ?'
-                r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, time, notes ?? '', JSON.stringify(auto_day), countRows[0].id])
+                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, target_count, 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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
-                r = await db.query(sql, [student_num, email, area, auto_time, auto_run, target_count, uuid, time, notes ?? '', JSON.stringify(auto_day)])
+                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, target_count, 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])
@@ -116,15 +130,20 @@ class AddAccount extends API {
                     return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
                     return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
             }
             }
         } else {
         } else {
-            sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ?, auto_day = ?, update_time = ? WHERE id = ?'
-            r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), time, id])
+            sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ?, auto_day = ?, update_time = ?, notice_type = ? WHERE id = ?'
+            r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), time, notice_type, id])
         }
         }
 
 
         try {
         try {
             if (r && r.affectedRows > 0) {
             if (r && r.affectedRows > 0) {
                 res.json({
                 res.json({
                     ...BaseStdResponse.OK,
                     ...BaseStdResponse.OK,
-                    id: r.insertId
+                    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
+                    }
                 })
                 })
             } else {
             } else {
                 return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
                 return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })

+ 2 - 0
apis/Lepao/Account/GetAccount.js

@@ -64,7 +64,9 @@ class GetAccount extends API {
                     l.notes,
                     l.notes,
                     l.target_count,
                     l.target_count,
                     l.auto_day,
                     l.auto_day,
+                    l.notice_type,
                     f.bind_code,
                     f.bind_code,
+                    f.bot_account,
                     f.create_time AS face_time,
                     f.create_time AS face_time,
                     f.state AS face_state
                     f.state AS face_state
                 FROM 
                 FROM 

+ 2 - 2
apis/Lepao/Account/UpdateAccount/UpdateAccount.js

@@ -60,7 +60,7 @@ class UpdateAccount extends API {
 
 
             let findSql = `
             let findSql = `
                 SELECT 
                 SELECT 
-                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.umo
+                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.bot_umo
                 FROM
                 FROM
                     lepao_account a
                     lepao_account a
                 LEFT JOIN
                 LEFT JOIN
@@ -108,7 +108,7 @@ class UpdateAccount extends API {
                 let emailData = {
                 let emailData = {
                     name,
                     name,
                     type: 'lepao_update',
                     type: 'lepao_update',
-                    umo: findRows[0].umo,
+                    umo: findRows[0].bot_umo,
                     account: student_num,
                     account: student_num,
                     academy_name,
                     academy_name,
                     grade_id,
                     grade_id,

+ 2 - 2
apis/Lepao/Account/UpdateAccount/UpdateAccountAndroidApp.js

@@ -60,7 +60,7 @@ class UpdateAccountAndroidApp extends API {
 
 
             let findSql = `
             let findSql = `
                 SELECT 
                 SELECT 
-                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.umo
+                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.bot_umo
                 FROM
                 FROM
                     lepao_account a
                     lepao_account a
                 LEFT JOIN
                 LEFT JOIN
@@ -110,7 +110,7 @@ class UpdateAccountAndroidApp extends API {
                 let emailData = {
                 let emailData = {
                     name,
                     name,
                     type: 'lepao_update',
                     type: 'lepao_update',
-                    umo: findRows[0].umo,
+                    umo: findRows[0].bot_umo,
                     account: student_num,
                     account: student_num,
                     academy_name,
                     academy_name,
                     grade_id,
                     grade_id,

+ 2 - 2
apis/Lepao/Account/UpdateAccount/UpdateAccountiPhone.js

@@ -61,7 +61,7 @@ class UpdateAccountiPhone extends API {
 
 
             let findSql = `
             let findSql = `
                 SELECT 
                 SELECT 
-                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.umo
+                    a.email, a.create_user, a.auto_run, a.auto_day, a.notice_type, e.bot_umo
                 FROM
                 FROM
                     lepao_account a
                     lepao_account a
                 LEFT JOIN
                 LEFT JOIN
@@ -112,7 +112,7 @@ class UpdateAccountiPhone extends API {
                 let emailData = {
                 let emailData = {
                     name,
                     name,
                     type: 'lepao_update',
                     type: 'lepao_update',
-                    umo: findRows[0].umo,
+                    umo: findRows[0].bot_umo,
                     account: student_num,
                     account: student_num,
                     academy_name,
                     academy_name,
                     grade_id,
                     grade_id,