|
@@ -46,7 +46,8 @@ class Lepao {
|
|
|
return randomPath.id
|
|
return randomPath.id
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async beginLepao(uuid, account, token, uid, school_id) {
|
|
|
|
|
|
|
+ // 乐跑入口函数
|
|
|
|
|
+ async beginLepao(uuid, account, token, uid, school_id, state) {
|
|
|
try {
|
|
try {
|
|
|
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])
|
|
@@ -55,12 +56,32 @@ class Lepao {
|
|
|
if (userPermissionData[0].lepao_count < 1)
|
|
if (userPermissionData[0].lepao_count < 1)
|
|
|
throw new Error('用户乐跑次数不足,请购买乐跑套餐!')
|
|
throw new Error('用户乐跑次数不足,请购买乐跑套餐!')
|
|
|
|
|
|
|
|
|
|
+ if(state !== 1) {
|
|
|
|
|
+ return this.sendFailEmail(account, '登录已过期,请尝试使用登录器重新登录')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 获取路径 ID
|
|
// 获取路径 ID
|
|
|
const path_id = await this.getPath(account, userPermissionData[0].vip)
|
|
const path_id = await this.getPath(account, userPermissionData[0].vip)
|
|
|
|
|
|
|
|
|
|
+ // 更换跑区
|
|
|
|
|
+ const zoneUrl = this.runpy + '/set_zone'
|
|
|
|
|
+ const ossData = { uid, token, school_id, student_id: account, random_id: path_id }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const zoneRes = await axios.post(zoneUrl, ossData)
|
|
|
|
|
+ const { data } = zoneRes
|
|
|
|
|
+
|
|
|
|
|
+ if (!data || data.status !== 1 || !data.data) {
|
|
|
|
|
+ this.setStatusFail(account)
|
|
|
|
|
+ throw new Error(data?.info || '未知错误,请尝试重新登录')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ throw error
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 上传 OSS
|
|
// 上传 OSS
|
|
|
const ossUrl = this.runpy + '/upload_oss_file'
|
|
const ossUrl = this.runpy + '/upload_oss_file'
|
|
|
- const ossData = { uid, token, school_id, student_id: account, random_id: path_id }
|
|
|
|
|
let oss_path
|
|
let oss_path
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -71,6 +92,7 @@ class Lepao {
|
|
|
}
|
|
}
|
|
|
oss_path = data.oss_path
|
|
oss_path = data.oss_path
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
|
+ this.setStatusFail(account)
|
|
|
this.logger.error(`上传OSS记录失败,请检查登录是否过期。${error.stack || error.message}`)
|
|
this.logger.error(`上传OSS记录失败,请检查登录是否过期。${error.stack || error.message}`)
|
|
|
throw new Error('请检查登录是否过期')
|
|
throw new Error('请检查登录是否过期')
|
|
|
}
|
|
}
|
|
@@ -95,6 +117,7 @@ class Lepao {
|
|
|
|
|
|
|
|
console.log(lepaoData)
|
|
console.log(lepaoData)
|
|
|
|
|
|
|
|
|
|
+ // 绑定乐跑数据
|
|
|
const lepaoUrl = this.runpy + '/bind_data'
|
|
const lepaoUrl = this.runpy + '/bind_data'
|
|
|
try {
|
|
try {
|
|
|
const lepaoRes = await axios.post(lepaoUrl, lepaoData)
|
|
const lepaoRes = await axios.post(lepaoUrl, lepaoData)
|
|
@@ -103,12 +126,13 @@ class Lepao {
|
|
|
console.log(data)
|
|
console.log(data)
|
|
|
|
|
|
|
|
if (!data || data.status !== 1 || !data.data) {
|
|
if (!data || data.status !== 1 || !data.data) {
|
|
|
- throw new Error(data.info || '未知错误,请尝试重新登录')
|
|
|
|
|
|
|
+ this.setStatusFail(account)
|
|
|
|
|
+ throw new Error(data?.info || '未知错误,请尝试重新登录')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
await this.addRecord(account, data.data)
|
|
await this.addRecord(account, data.data)
|
|
|
if (data.data.record_failed_reason === '') {
|
|
if (data.data.record_failed_reason === '') {
|
|
|
- await this.sendSuccessEmail(account, data)
|
|
|
|
|
|
|
+ await this.sendSuccessEmail(account, data.data)
|
|
|
} else {
|
|
} else {
|
|
|
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)
|
|
@@ -116,7 +140,6 @@ class Lepao {
|
|
|
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
await this.lepaoFail(uuid)
|
|
await this.lepaoFail(uuid)
|
|
|
-
|
|
|
|
|
throw error
|
|
throw error
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -183,6 +206,15 @@ class Lepao {
|
|
|
this.logger.error(`返还用户 ${uuid} 乐跑次数时出错: ${error.stack || error.message}`)
|
|
this.logger.error(`返还用户 ${uuid} 乐跑次数时出错: ${error.stack || error.message}`)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ async setStatusFail(account) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const sql = 'UPDATE lepao_account SET state = 0 WHERE student_num = ?'
|
|
|
|
|
+ await db.query(sql, [account])
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.logger.error(`设置用户 ${account} state时出错: ${error.stack || error.message}`)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const lepao = new Lepao()
|
|
const lepao = new Lepao()
|