SetAutoTime.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const API = require("../../lib/API.js")
  2. const db = require('../../plugin/DataBase/db.js')
  3. const { BaseStdResponse } = require("../../BaseStdResponse.js")
  4. class SetAutoTime extends API {
  5. constructor() {
  6. super()
  7. this.noEncrypt()
  8. this.setPath('/Corn/SetAutoTime')
  9. this.setMethod('GET')
  10. }
  11. async onRequest(req, res) {
  12. try {
  13. res.json({
  14. ...BaseStdResponse.OK
  15. })
  16. this.logger.info('开始更换随机乐跑时间段')
  17. const deleteSql = 'UPDATE lepao_account SET today_auto_time = NULL'
  18. const deleteR = await db.query(deleteSql)
  19. if (!deleteR)
  20. this.logger.error('重置随机乐跑时间段失败!')
  21. const sql = `
  22. UPDATE lepao_account
  23. SET today_auto_time = FLOOR(7 + (RAND() * 15))
  24. WHERE auto_time = -1 AND auto_run = 1 AND JSON_CONTAINS(auto_day, CAST(? AS JSON));
  25. `
  26. const day = new Date().getDay()
  27. const r = await db.query(sql, [day])
  28. if (!r)
  29. return this.logger.error('更换随机乐跑时间段失败!')
  30. this.logger.info('更换随机乐跑时间段完成')
  31. } catch (error) {
  32. this.logger.error(error)
  33. }
  34. }
  35. }
  36. module.exports.SetAutoTime = SetAutoTime