Browse Source

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

Pchen. 3 months ago
parent
commit
c50896db5d

+ 16 - 10
apis/Lepao/Account/AddAccount.js

@@ -2,7 +2,7 @@ const API = require("../../../lib/API.js")
 const db = require("../../../plugin/DataBase/db.js")
 const db = require("../../../plugin/DataBase/db.js")
 const { BaseStdResponse } = require("../../../BaseStdResponse.js")
 const { BaseStdResponse } = require("../../../BaseStdResponse.js")
 const AccessControl = require("../../../lib/AccessControl.js")
 const AccessControl = require("../../../lib/AccessControl.js")
-const { lepaoAuth, lepaoUserInfo } =  require('../../../lib/Lepao/lepaoAPI')
+const { lepaoAuth, lepaoUserInfo } = require('../../../lib/Lepao/lepaoAPI')
 
 
 class AddAccount extends API {
 class AddAccount extends API {
     constructor() {
     constructor() {
@@ -15,11 +15,11 @@ class AddAccount extends API {
         this.banEmailList = ['icloud.com']
         this.banEmailList = ['icloud.com']
     }
     }
 
 
-    
+
     async onRequest(req, res) {
     async onRequest(req, res) {
-        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, password, notes } = req.body
+        let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, password, 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({
             return res.json({
                 ...BaseStdResponse.MISSING_PARAMETER
                 ...BaseStdResponse.MISSING_PARAMETER
             })
             })
@@ -45,6 +45,12 @@ class AddAccount extends API {
                 msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
                 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))
         if (!await AccessControl.checkSession(uuid, session))
             return res.status(401).json({
             return res.status(401).json({
                 ...BaseStdResponse.ACCESS_DENIED
                 ...BaseStdResponse.ACCESS_DENIED
@@ -99,17 +105,17 @@ class AddAccount extends API {
             }
             }
 
 
             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 = ?, notes = ?, total_num = ? WHERE id = ?'
-                r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, notes ?? '', userInfo.frequency, 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 = ?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])
             }
             }
             else {
             else {
                 const user_avatar = userInfo.sex === 0 ? 'https://lepao-cloud.xxoo365.top/view.php/aee85ff43fd30d0df03c6a7dd9797d22.png' : 'https://lepao-cloud.xxoo365.top/view.php/fcb54dcc5e6209381e972ef73bdb4a93.png'
                 const 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) 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])
+                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)])
             }
             }
         } else {
         } 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 {
         try {

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

@@ -68,6 +68,7 @@ class GetAccountList extends API {
                     l.auto_time,
                     l.auto_time,
                     l.today_auto_time,
                     l.today_auto_time,
                     l.state,
                     l.state,
+                    l.auto_day,
                     l.notes,
                     l.notes,
                     l.target_count
                     l.target_count
                 FROM 
                 FROM 

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

@@ -59,6 +59,7 @@ class GetAccount extends API {
                     l.auto_run,
                     l.auto_run,
                     l.today_auto_time,
                     l.today_auto_time,
                     l.notes,
                     l.notes,
+                    l.auto_day,
                     l.target_count
                     l.target_count
                 FROM 
                 FROM 
                     lepao_account l
                     lepao_account l