Browse Source

✨ feat: 加入对自动乐跑星期的支持

Pchen. 3 months ago
parent
commit
6b322aa3b7

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

@@ -36,9 +36,9 @@ class AddAccount extends API {
     }
 
     async onRequest(req, res) {
-        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, notes } = req.body
+        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notes } = req.body
 
-        if ([uuid, session, student_num, email, auto_time, target_count].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({
                 ...BaseStdResponse.MISSING_PARAMETER
             })
@@ -64,6 +64,12 @@ class AddAccount extends API {
                 msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
             })
 
+        if (auto_run === 1 && (!Array.isArray(auto_day) || !auto_day.every(v => Number.isInteger(v) && v >= 0 && v <= 6)))
+            return res.json({
+                ...BaseStdResponse.ERR,
+                msg: '自动乐跑日期格式不合法'
+            })
+
         if (!await AccessControl.checkSession(uuid, session))
             return res.status(401).json({
                 ...BaseStdResponse.ACCESS_DENIED
@@ -95,14 +101,14 @@ class AddAccount extends API {
 
         if (!id) {
             if (countRows.length !== 0) {
-                sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, notes = ? WHERE id = ?'
-                r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, notes ?? '', countRows[0].id])
+                sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, notes = ?, auto_day = ? WHERE id = ?'
+                r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, notes ?? '', JSON.stringify(auto_day), countRows[0].id])
             }
             else {
                 const face_code = await this.generateCode()
 
-                sql = 'INSERT INTO lepao_account (student_num, email, area, auto_time, auto_run, target_count, create_user, create_time, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'
-                r = await db.query(sql, [student_num, email, area, auto_time, auto_run, target_count, uuid, time, notes ?? ''])
+                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)])
 
                 let faceSql = 'INSERT INTO lepao_face (student_num, face_code) VALUES (?, ?)'
                 let faceRows = await db.query(faceSql, [student_num, face_code])
@@ -110,8 +116,8 @@ class AddAccount extends API {
                     return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
             }
         } else {
-            sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ? WHERE id = ?'
-            r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', id])
+            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])
         }
 
         try {

+ 1 - 0
apis/Lepao/Account/Admin/GetAccountList.js

@@ -71,6 +71,7 @@ class GetAccountList extends API {
                     l.auto_time,
                     l.today_auto_time,
                     l.state,
+                    l.auto_day,
                     l.notes,
                     l.target_count,
                     f.face_code,

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

@@ -63,6 +63,7 @@ class GetAccount extends API {
                     l.today_auto_time,
                     l.notes,
                     l.target_count,
+                    l.auto_day,
                     f.face_code,
                     f.create_time AS face_time,
                     f.state AS face_state