|
@@ -289,8 +289,8 @@ class Worker {
|
|
|
let deductedKm = 0
|
|
let deductedKm = 0
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const isSuccess = await Redis.get(jkesRedisKeys.lepaoSuccess(req.account))
|
|
|
|
|
- if (isSuccess) throw new Error('该账号当天已乐跑成功!请勿重复乐跑')
|
|
|
|
|
|
|
+ // const isSuccess = await Redis.get(jkesRedisKeys.lepaoSuccess(req.account))
|
|
|
|
|
+ // if (isSuccess) throw new Error('该账号当天已乐跑成功!请勿重复乐跑')
|
|
|
|
|
|
|
|
userData = await this.handlers['lepao.getUserData'](req, ctx)
|
|
userData = await this.handlers['lepao.getUserData'](req, ctx)
|
|
|
|
|
|
|
@@ -308,9 +308,9 @@ class Worker {
|
|
|
await Redis.set(progressKey, req.account, { EX: 1800 })
|
|
await Redis.set(progressKey, req.account, { EX: 1800 })
|
|
|
|
|
|
|
|
const hour = new Date().getHours()
|
|
const hour = new Date().getHours()
|
|
|
- if (hour < 7) {
|
|
|
|
|
- throw new Error('当前不在有效乐跑时间范围内。RunForge支持乐跑时间段为7:00~24:00')
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // if (hour < 7) {
|
|
|
|
|
+ // throw new Error('当前不在有效乐跑时间范围内。RunForge支持乐跑时间段为7:00~24:00')
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
const { runJkesRecord } = require('../../plugin/jkes/runRecord')
|
|
const { runJkesRecord } = require('../../plugin/jkes/runRecord')
|
|
|
const { getJkesSettings } = require('../../plugin/jkes/jkesSettings')
|
|
const { getJkesSettings } = require('../../plugin/jkes/jkesSettings')
|
|
@@ -407,18 +407,26 @@ class Worker {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const info = jkesEnd.endJson?.data?.info
|
|
const info = jkesEnd.endJson?.data?.info
|
|
|
|
|
+ const infoWithMeta = info
|
|
|
|
|
+ ? {
|
|
|
|
|
+ ...info,
|
|
|
|
|
+ planned_km: targetKm,
|
|
|
|
|
+ deducted_km: deductedKm,
|
|
|
|
|
+ pace_sec_per_km: pace
|
|
|
|
|
+ }
|
|
|
|
|
+ : null
|
|
|
if (!recordDbId) {
|
|
if (!recordDbId) {
|
|
|
recordDbId = await this.createLepaoRecord({
|
|
recordDbId = await this.createLepaoRecord({
|
|
|
uuid: userData?.create_user,
|
|
uuid: userData?.create_user,
|
|
|
account: req.account,
|
|
account: req.account,
|
|
|
pathId: jkesPathId,
|
|
pathId: jkesPathId,
|
|
|
pathData: jkesEnd.uploadedPayloadPoints || [],
|
|
pathData: jkesEnd.uploadedPayloadPoints || [],
|
|
|
- result: info || jkesEnd.endJson?.data || {},
|
|
|
|
|
|
|
+ result: infoWithMeta || jkesEnd.endJson?.data || {},
|
|
|
state: 1
|
|
state: 1
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
await this.updateLepaoRecord(recordDbId, {
|
|
await this.updateLepaoRecord(recordDbId, {
|
|
|
- result: info || jkesEnd.endJson?.data || {},
|
|
|
|
|
|
|
+ result: infoWithMeta || jkesEnd.endJson?.data || {},
|
|
|
pathData: jkesEnd.uploadedPayloadPoints || [],
|
|
pathData: jkesEnd.uploadedPayloadPoints || [],
|
|
|
state: 1
|
|
state: 1
|
|
|
})
|
|
})
|
|
@@ -592,12 +600,43 @@ class Worker {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
await this.updateLepaoRecord(recordDbId, {
|
|
await this.updateLepaoRecord(recordDbId, {
|
|
|
- result: latest,
|
|
|
|
|
|
|
+ result: {
|
|
|
|
|
+ ...(latest || {}),
|
|
|
|
|
+ planned_km: this.roundKm(targetKm || 0),
|
|
|
|
|
+ deducted_km: preDeduct,
|
|
|
|
|
+ official_km: officialKm,
|
|
|
|
|
+ refunded_km: refundKm
|
|
|
|
|
+ },
|
|
|
state: 2
|
|
state: 2
|
|
|
})
|
|
})
|
|
|
await recordSuccess(account, officialKm, { autoDoubleSlot: officialKm >= 2 && !!autoDoubleSlot })
|
|
await recordSuccess(account, officialKm, { autoDoubleSlot: officialKm >= 2 && !!autoDoubleSlot })
|
|
|
await this.syncRunCount({ account, student_id: account, token })
|
|
await this.syncRunCount({ account, student_id: account, token })
|
|
|
|
|
|
|
|
|
|
+ // 达成本月预设目标后:关闭自动乐跑并发送目标完成邮件(target_count=0 表示不限制)
|
|
|
|
|
+ try {
|
|
|
|
|
+ const accRows = await db.query(
|
|
|
|
|
+ 'SELECT name, email, notice_type, auto_run, target_count, term_num, total_num FROM lepao_account WHERE student_num = ?',
|
|
|
|
|
+ [account]
|
|
|
|
|
+ )
|
|
|
|
|
+ if (accRows && accRows.length) {
|
|
|
|
|
+ const acc = accRows[0]
|
|
|
|
|
+ const targetKm = Number(acc.target_count) || 0
|
|
|
|
|
+ const monthKm = Number(acc.term_num) || 0
|
|
|
|
|
+ if (acc.auto_run === 1 && targetKm !== 0 && monthKm >= targetKm) {
|
|
|
|
|
+ await db.query('UPDATE lepao_account SET auto_run = 0 WHERE student_num = ?', [account])
|
|
|
|
|
+
|
|
|
|
|
+ if (acc.notice_type === 'email' && acc.email) {
|
|
|
|
|
+ await EmailTemplate.lepaoOver(acc.email, {
|
|
|
|
|
+ name: acc.name || account,
|
|
|
|
|
+ month_km: monthKm
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.logger.warn(`[${traceId}] 目标达成处理失败:${e.message || e}`)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (ctx.channel) {
|
|
if (ctx.channel) {
|
|
|
await this.enqueueTask(ctx.channel, 'lepao.sendNotice', {
|
|
await this.enqueueTask(ctx.channel, 'lepao.sendNotice', {
|
|
|
account,
|
|
account,
|
|
@@ -626,6 +665,8 @@ class Worker {
|
|
|
a.name,
|
|
a.name,
|
|
|
a.email,
|
|
a.email,
|
|
|
a.target_count,
|
|
a.target_count,
|
|
|
|
|
+ a.term_num,
|
|
|
|
|
+ a.total_num,
|
|
|
a.notice_type,
|
|
a.notice_type,
|
|
|
e.bot_umo
|
|
e.bot_umo
|
|
|
FROM
|
|
FROM
|
|
@@ -645,12 +686,35 @@ class Worker {
|
|
|
const user = rows[0]
|
|
const user = rows[0]
|
|
|
const noticeType = user.notice_type || 'none'
|
|
const noticeType = user.notice_type || 'none'
|
|
|
|
|
|
|
|
|
|
+ let runZoneName = data?.run_zone_name
|
|
|
|
|
+ if (!runZoneName && success) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const z = await db.query(
|
|
|
|
|
+ `
|
|
|
|
|
+ SELECT p.run_zone_name
|
|
|
|
|
+ FROM lepao_record r
|
|
|
|
|
+ LEFT JOIN path_data p ON r.path_id = p.id
|
|
|
|
|
+ WHERE r.lepao_account = ?
|
|
|
|
|
+ ORDER BY r.id DESC
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ `,
|
|
|
|
|
+ [account]
|
|
|
|
|
+ )
|
|
|
|
|
+ runZoneName = z?.length ? z[0].run_zone_name : null
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.logger.warn(`[${traceId}] 查询跑区失败:${e.message || e}`)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const payload = success
|
|
const payload = success
|
|
|
? {
|
|
? {
|
|
|
...(data && typeof data === 'object' ? data : {}),
|
|
...(data && typeof data === 'object' ? data : {}),
|
|
|
type: 'lepao_success',
|
|
type: 'lepao_success',
|
|
|
umo: user.bot_umo,
|
|
umo: user.bot_umo,
|
|
|
- term_num: user.target_count ?? 0,
|
|
|
|
|
|
|
+ run_zone_name: runZoneName,
|
|
|
|
|
+ month_km: Number(user.term_num) || 0,
|
|
|
|
|
+ total_km: Number(user.total_num) || 0,
|
|
|
|
|
+ target_km: Number(user.target_count) || 0,
|
|
|
name: user.name,
|
|
name: user.name,
|
|
|
account,
|
|
account,
|
|
|
traceId
|
|
traceId
|