修复 affiliate-dash 提交成功(delivered)后结果页数秒后才显示成功
- syncAffiliateDashTaskStatus 新增 snapshotOnly:submit 拿到 delivered 后直接用本地快照收敛任务为 REDEEMED,不等平台回调(此前要等 delivered notify 落地,约 9 秒) - 新增终态保护:已 REDEEMED/MANUAL_REVIEW/CLOSED/FAILED 的任务,非 delivered 状态不再降级(轮询时平台详情短暂返回 paid/delivering 会把成功任务打回 REDEEMING) - submitAffiliateDashClaim:result.status=delivered 时重新读任务并 snapshotOnly 收敛
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { createTaskEvent } from '../../repositories/task-event-repo.js'
|
import { createTaskEvent } from '../../repositories/task-event-repo.js'
|
||||||
import { updateTask } from '../../repositories/task-repo.js'
|
import { getTaskById, updateTask } from '../../repositories/task-repo.js'
|
||||||
import { createHttpError } from '../../utils/http.js'
|
import { createHttpError } from '../../utils/http.js'
|
||||||
import { parseTaskContext as parseTaskContextValue } from '../../utils/task-json.js'
|
import { parseTaskContext as parseTaskContextValue } from '../../utils/task-json.js'
|
||||||
import { nowIso } from '../../utils/time.js'
|
import { nowIso } from '../../utils/time.js'
|
||||||
@@ -456,6 +456,15 @@ export async function submitAffiliateDashClaim(
|
|||||||
now,
|
now,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 平台已返回 delivered:立即用本地快照收敛任务为成功,不等平台回调(避免结果页等数秒)。
|
||||||
|
// delivered 回调到达时 sync 幂等短路(已 REDEEMED 且 delivered 仍会刷新,无副作用)。
|
||||||
|
if (result.status === 'delivered') {
|
||||||
|
const refreshedTask = await getTaskById(task.id)
|
||||||
|
if (refreshedTask) {
|
||||||
|
await syncAffiliateDashTaskStatus(refreshedTask, { snapshotOnly: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return getKuaishouCloudClaimDetail(token)
|
return getKuaishouCloudClaimDetail(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,10 @@ export async function prepareAffiliateDashTask(task: TaskRow) {
|
|||||||
* delivered → 核销行业电子凭证 → redeemed / manual_review;
|
* delivered → 核销行业电子凭证 → redeemed / manual_review;
|
||||||
* ship_failed → retry_pending;cancelled → closed。
|
* ship_failed → retry_pending;cancelled → closed。
|
||||||
*/
|
*/
|
||||||
export async function syncAffiliateDashTaskStatus(task: TaskRow) {
|
export async function syncAffiliateDashTaskStatus(
|
||||||
|
task: TaskRow,
|
||||||
|
options: { snapshotOnly?: boolean } = {},
|
||||||
|
) {
|
||||||
if (!isAffiliateDashTask(task)) {
|
if (!isAffiliateDashTask(task)) {
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
@@ -166,8 +169,10 @@ export async function syncAffiliateDashTaskStatus(task: TaskRow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = nowIso()
|
const now = nowIso()
|
||||||
// dev-mock 任务:不请求 affiliate-dash 平台,直接用本地快照(flow 自身)收敛状态
|
// dev-mock 任务或 snapshotOnly(如 submit 已拿到 delivered)不请求 affiliate-dash 平台,
|
||||||
const order = flow.mock?.enabled
|
// 直接用本地快照(flow 自身)收敛状态。
|
||||||
|
const useSnapshot = Boolean(flow.mock?.enabled) || options.snapshotOnly
|
||||||
|
const order = useSnapshot
|
||||||
? ({
|
? ({
|
||||||
orderNo: flow.orderNo,
|
orderNo: flow.orderNo,
|
||||||
orderStatus: flow.orderStatus,
|
orderStatus: flow.orderStatus,
|
||||||
@@ -249,6 +254,16 @@ export async function syncAffiliateDashTaskStatus(task: TaskRow) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAlreadyTerminal = (
|
||||||
|
[TASK_STATUS.REDEEMED, TASK_STATUS.MANUAL_REVIEW, TASK_STATUS.CLOSED, TASK_STATUS.FAILED] as string[]
|
||||||
|
).includes(task.task_status)
|
||||||
|
// 终态保护:已收敛成功的任务,非 delivered 状态不允许降级(如轮询时平台详情短暂返回
|
||||||
|
// delivering/paid 会把 REDEEMED 打回 REDEEMING,导致结果页闪烁/倒退)。
|
||||||
|
const shouldApply = !isAlreadyTerminal || order.orderStatus === 'delivered'
|
||||||
|
if (!shouldApply) {
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
|
||||||
const updatedTask = await updateTask(task.id, {
|
const updatedTask = await updateTask(task.id, {
|
||||||
task_status: nextTaskStatus,
|
task_status: nextTaskStatus,
|
||||||
delivery_status: deliveryStatus,
|
delivery_status: deliveryStatus,
|
||||||
|
|||||||
Reference in New Issue
Block a user