|
@@ -1,4 +1,5 @@
|
|
|
const axios = require('axios')
|
|
const axios = require('axios')
|
|
|
|
|
+const Redis = require('../../plugin/DataBase/Redis')
|
|
|
const db = require('../../plugin/DataBase/db')
|
|
const db = require('../../plugin/DataBase/db')
|
|
|
const Logger = require('../Logger')
|
|
const Logger = require('../Logger')
|
|
|
const path = require('path')
|
|
const path = require('path')
|
|
@@ -74,9 +75,33 @@ class Lepao {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async writeRedis(account) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 计算至明日0时过期的秒数
|
|
|
|
|
+ const now = new Date()
|
|
|
|
|
+ const tomorrow = new Date().setHours(24, 0, 0, 0)
|
|
|
|
|
+ const exp = Math.floor((tomorrow - now) / 1000)
|
|
|
|
|
+
|
|
|
|
|
+ await Redis.set(`lepaoSuccess:${account}`, account, {
|
|
|
|
|
+ EX: exp
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.logger.error(`redis缓存乐跑记录失败: ${error.stack || '未知错误'}`)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async beginLepao(uuid, account, token, uid, school_id, state) {
|
|
async beginLepao(uuid, account, token, uid, school_id, state) {
|
|
|
try {
|
|
try {
|
|
|
this.logger.info(`${account}开始执行乐跑流程`)
|
|
this.logger.info(`${account}开始执行乐跑流程`)
|
|
|
|
|
+
|
|
|
|
|
+ // 检查redis是否存在当天乐跑成功记录
|
|
|
|
|
+ const isSuccess = await Redis.get(`lepaoSuccess:${account}`)
|
|
|
|
|
+ if (isSuccess)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '该账号当天已存在成功乐跑记录'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
const userPermissionSql = 'SELECT vip, lepao_count FROM users WHERE uuid = ?'
|
|
const userPermissionSql = 'SELECT vip, lepao_count FROM users WHERE uuid = ?'
|
|
|
const userPermissionData = await db.query(userPermissionSql, [uuid])
|
|
const userPermissionData = await db.query(userPermissionSql, [uuid])
|
|
|
if (!userPermissionData || userPermissionData.length !== 1) {
|
|
if (!userPermissionData || userPermissionData.length !== 1) {
|
|
@@ -193,9 +218,16 @@ class Lepao {
|
|
|
let total_num = recordData?.total_num || 30
|
|
let total_num = recordData?.total_num || 30
|
|
|
|
|
|
|
|
if (data.data.record_failed_reason === '自动确认有效') {
|
|
if (data.data.record_failed_reason === '自动确认有效') {
|
|
|
|
|
+ // 成功记录存入Redis
|
|
|
|
|
+ await this.writeRedis(account)
|
|
|
await this.sendSuccessEmail(account, data.data, term_num, total_num)
|
|
await this.sendSuccessEmail(account, data.data, term_num, total_num)
|
|
|
} else {
|
|
} else {
|
|
|
this.logger.warn(`${account}乐跑失败,原因: ${data.data.record_failed_reason}`)
|
|
this.logger.warn(`${account}乐跑失败,原因: ${data.data.record_failed_reason}`)
|
|
|
|
|
+
|
|
|
|
|
+ // 已存在记录也存redis
|
|
|
|
|
+ if(data.data.record_failed_reason === '当天关联成绩次数已达到上限')
|
|
|
|
|
+ await this.writeRedis(account)
|
|
|
|
|
+
|
|
|
await this.sendFailEmail(account, data.data.record_failed_reason)
|
|
await this.sendFailEmail(account, data.data.record_failed_reason)
|
|
|
await this.lepaoFail(uuid)
|
|
await this.lepaoFail(uuid)
|
|
|
}
|
|
}
|