Browse Source

✨ feat: 随机更换乐跑时间段增加对星期的支持

Pchen. 3 months ago
parent
commit
e15c1f3635
1 changed files with 11 additions and 3 deletions
  1. 11 3
      apis/Corn/SetAutoTime.js

+ 11 - 3
apis/Corn/SetAutoTime.js

@@ -18,12 +18,20 @@ class SetAutoTime extends API {
             })
 
             this.logger.info('开始更换随机乐跑时间段')
-            let sql = `
+
+            const deleteSql = 'UPDATE lepao_account SET today_auto_time = NULL'
+            const deleteR = await db.query(deleteSql)
+            if (!deleteR)
+                this.logger.error('重置随机乐跑时间段失败!')
+
+            const sql = `
                         UPDATE lepao_account
                         SET today_auto_time = FLOOR(7 + (RAND() * 15))
-                        WHERE auto_time = -1 AND auto_run = 1;
+                        WHERE auto_time = -1 AND auto_run = 1 AND JSON_CONTAINS(auto_day, CAST(? AS JSON));
                     `
-            let r = await db.query(sql)
+
+            const day = new Date().getDay()
+            const r = await db.query(sql, [day])
             if (!r)
                 return this.logger.error('更换随机乐跑时间段失败!')
             this.logger.info('更换随机乐跑时间段完成')