Browse Source

✨ feat: 增加补充乐跑功能

Pchen. 6 months ago
parent
commit
ef75988039
2 changed files with 65 additions and 0 deletions
  1. 64 0
      apis/Corn/StartLepao.js
  2. 1 0
      apis/User/ChangePassword.js

+ 64 - 0
apis/Corn/StartLepao.js

@@ -0,0 +1,64 @@
+const API = require("../../lib/API");
+const db = require('../../plugin/DataBase/db')
+const Redis = require('../../plugin/DataBase/Redis')
+const lepao = require("../../lib/Lepao/Lepao.js").lepao
+const { BaseStdResponse } = require("../../BaseStdResponse")
+
+// 出现异常情况时补充乐跑
+class StartLepao extends API {
+    constructor() {
+        super();
+
+        this.noEncrypt()
+        this.setPath('/Corn/StartLepao');
+        this.setMethod('GET');
+    }
+
+    async onRequest(req, res) {
+        try {
+            let { time } = req.query
+
+            if ([time].some(value => value === '' || value === null || value === undefined))
+                return res.json({
+                    ...BaseStdResponse.MISSING_PARAMETER
+                })
+
+            res.json({
+                ...BaseStdResponse.OK
+            })
+
+            this.logger.info('开始执行补充乐跑任务')
+            let sql = `
+                        SELECT name, create_user, student_num, token, uid, school_id, state
+                        FROM lepao_account
+                        WHERE auto_run = 1
+                            AND (auto_time = ? OR (auto_time = -1 AND today_auto_time = ?))
+                        `
+            let r = await db.query(sql, [time, time])
+            if (!r)
+                return this.logger.error('获取补充乐跑账号失败!')
+
+            for (const item of r) {
+                const { name, create_user, student_num, token, uid, school_id, state } = item
+                this.logger.info(`${name}(${student_num})开始乐跑`)
+
+                const isSuccess = await Redis.get(`lepaoSuccess:${student_num}`)
+                if (isSuccess) {
+                    this.logger.info(`${name}(${student_num})当天已乐跑成功,不执行补充乐跑`)
+                    continue
+                }
+
+                try {
+                    await lepao.beginLepao(create_user, student_num, token, uid, school_id, state)
+                    this.logger.info(`${name}(${student_num})乐跑完成`)
+                } catch (err) {
+                    this.logger.error(`${name}(${student_num})乐跑失败:${err.message || err}`)
+                }
+            }
+        } catch (error) {
+            this.logger.error(error)
+        }
+    }
+}
+
+module.exports.StartLepao = StartLepao

+ 1 - 0
apis/User/ChangePassword.js

@@ -80,6 +80,7 @@ class ChangePassword extends API {
                 res.json({ ...BaseStdResponse.ERR, endpoint: 7894378, msg: '操作失败!' });
                 res.json({ ...BaseStdResponse.ERR, endpoint: 7894378, msg: '操作失败!' });
             }
             }
         } catch (error) {
         } catch (error) {
+            console.log(error.stack)
             return res.json({
             return res.json({
                 ...BaseStdResponse.ERR,
                 ...BaseStdResponse.ERR,
                 msg: '密码更新失败,请联系客服'
                 msg: '密码更新失败,请联系客服'