|
|
@@ -49,6 +49,26 @@ class Lepao {
|
|
|
return randomPath.id
|
|
|
}
|
|
|
|
|
|
+ // 获取跑步次数
|
|
|
+ async getRecord(uid, token, school_id, student_id) {
|
|
|
+ try {
|
|
|
+ const reqData = { uid, token, school_id, student_id }
|
|
|
+ const recordUrl = this.runpy + '/get_record'
|
|
|
+ const recordRes = await axios.post(recordUrl, reqData)
|
|
|
+ const { recordData } = recordRes
|
|
|
+ if (!recordData || recordData.status !== 1 || !recordData.data) {
|
|
|
+ this.logger.info('获取剩余跑步次数失败!')
|
|
|
+ console.log(recordData)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return recordRes.data
|
|
|
+ } catch (error) {
|
|
|
+ this.logger.error('获取跑步次数失败!')
|
|
|
+ console.log(error.stack)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 乐跑入口函数
|
|
|
async beginLepao(uuid, account, token, uid, school_id, state) {
|
|
|
try {
|
|
|
@@ -109,9 +129,6 @@ class Lepao {
|
|
|
let hour = new Date().getHours()
|
|
|
if (hour >= 22) run_end_time -= 18000
|
|
|
|
|
|
- // 0点过后无法上传
|
|
|
- // else if (hour < 6) run_end_time -= 43920
|
|
|
-
|
|
|
const lepaoData = {
|
|
|
uid,
|
|
|
token,
|
|
|
@@ -139,7 +156,21 @@ class Lepao {
|
|
|
|
|
|
await this.addRecord(account, data.data)
|
|
|
if (data.data.record_failed_reason === '') {
|
|
|
- await this.sendSuccessEmail(account, data.data)
|
|
|
+ // 获取剩余跑步次数
|
|
|
+ const recordData = await this.getRecord(uid, token, school_id, account)
|
|
|
+
|
|
|
+ // await this.sendSuccessEmail(account, data.data)
|
|
|
+ let term_num = 0, total_num = 0
|
|
|
+ if (recordData) {
|
|
|
+ term_num = recordData.term_num
|
|
|
+ total_num = recordData.total_num
|
|
|
+ if (!recordRows || recordRows.affectedRows !== 1)
|
|
|
+ this.logger.info('更新乐跑次数失败!')
|
|
|
+ }
|
|
|
+ await this.sendSuccessEmail(account, data.data, term_num, total_num)
|
|
|
+
|
|
|
+ let recordSql = 'UPDATE lepao_accounts SET term_num = ?, total_num = ? WHERE student_num = ?'
|
|
|
+ let recordRows = await db.query(recordSql, [term_num, total_num, account])
|
|
|
} else {
|
|
|
await this.sendFailEmail(account, data.data.record_failed_reason)
|
|
|
await this.lepaoFail(uuid)
|
|
|
@@ -165,7 +196,7 @@ class Lepao {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async sendSuccessEmail(account, lepaoData) {
|
|
|
+ async sendSuccessEmail(account, lepaoData, term_num, total_num) {
|
|
|
try {
|
|
|
const emailSql = 'SELECT name, email FROM lepao_account WHERE student_num = ?'
|
|
|
const rows = await db.query(emailSql, [account])
|
|
|
@@ -175,6 +206,8 @@ class Lepao {
|
|
|
|
|
|
const data = {
|
|
|
...lepaoData,
|
|
|
+ term_num,
|
|
|
+ total_num,
|
|
|
name: rows[0].name,
|
|
|
account
|
|
|
}
|