优化兑换流程, 优化浏览器分辨率
This commit is contained in:
@@ -696,15 +696,39 @@ function buildClaimDetailPayload({ claimToken, task, order, orderItem, session }
|
||||
}
|
||||
|
||||
async function redeemClaimTaskWithInventoryFallback(context, initialInventoryItem) {
|
||||
return redeemClaimTaskWithInventoryFallbackWithDeps(context, initialInventoryItem)
|
||||
}
|
||||
|
||||
export async function redeemClaimTaskWithInventoryFallbackWithDeps(
|
||||
context,
|
||||
initialInventoryItem,
|
||||
{
|
||||
reloadTencentBrowserSession: reloadRedeemSession = reloadTencentBrowserSession,
|
||||
redeemTencentBrowserSession: redeemSession = redeemTencentBrowserSession,
|
||||
classifyTencentRedeemResult: classifyRedeemResult = classifyTencentRedeemResult,
|
||||
markInventoryItemConsumed: markConsumedInventoryItem = markInventoryItemConsumed,
|
||||
createTaskEvent: createRedeemTaskEvent = createTaskEvent,
|
||||
invalidateReservedInventoryItem: invalidateReservedItem = invalidateReservedInventoryItem,
|
||||
reserveInventoryForTask: reserveReplacementInventory = reserveInventoryForTask,
|
||||
nowIso: getNowIso = nowIso,
|
||||
redeemReplacementLimit = REDEEM_REPLACEMENT_LIMIT,
|
||||
} = {},
|
||||
) {
|
||||
const attempts = []
|
||||
let currentInventoryItem = initialInventoryItem
|
||||
let shouldReloadBeforeNextAttempt = false
|
||||
|
||||
for (let attemptIndex = 1; attemptIndex <= REDEEM_REPLACEMENT_LIMIT; attemptIndex += 1) {
|
||||
const session = await redeemTencentBrowserSession(context.task.browser_session_id, {
|
||||
for (let attemptIndex = 1; attemptIndex <= redeemReplacementLimit; attemptIndex += 1) {
|
||||
if (shouldReloadBeforeNextAttempt) {
|
||||
await reloadRedeemSession(context.task.browser_session_id)
|
||||
shouldReloadBeforeNextAttempt = false
|
||||
}
|
||||
|
||||
const session = await redeemSession(context.task.browser_session_id, {
|
||||
code: currentInventoryItem.display_value,
|
||||
})
|
||||
const finalRedeem = session.redeem?.final?.redeem || null
|
||||
const classification = classifyTencentRedeemResult(finalRedeem)
|
||||
const classification = classifyRedeemResult(finalRedeem)
|
||||
const attemptSummary = {
|
||||
attempt: attemptIndex,
|
||||
inventoryItemId: currentInventoryItem.id,
|
||||
@@ -727,18 +751,18 @@ async function redeemClaimTaskWithInventoryFallback(context, initialInventoryIte
|
||||
}
|
||||
|
||||
if (classification.outcome === 'code_used') {
|
||||
const updatedAt = nowIso()
|
||||
await markInventoryItemConsumed(currentInventoryItem.id, classification.message, updatedAt)
|
||||
await createTaskEvent(context.task.id, 'claim_redeem_code_used', {
|
||||
const updatedAt = getNowIso()
|
||||
await markConsumedInventoryItem(currentInventoryItem.id, classification.message, updatedAt)
|
||||
await createRedeemTaskEvent(context.task.id, 'claim_redeem_code_used', {
|
||||
inventoryItemId: currentInventoryItem.id,
|
||||
codeMasked: attemptSummary.codeMasked,
|
||||
resultCode: attemptSummary.resultCode,
|
||||
resultMessage: classification.message,
|
||||
}, updatedAt)
|
||||
} else if (classification.outcome === 'code_invalid') {
|
||||
const updatedAt = nowIso()
|
||||
await invalidateReservedInventoryItem(currentInventoryItem.id, classification.message, updatedAt)
|
||||
await createTaskEvent(context.task.id, 'claim_redeem_code_invalid', {
|
||||
const updatedAt = getNowIso()
|
||||
await invalidateReservedItem(currentInventoryItem.id, classification.message, updatedAt)
|
||||
await createRedeemTaskEvent(context.task.id, 'claim_redeem_code_invalid', {
|
||||
inventoryItemId: currentInventoryItem.id,
|
||||
codeMasked: attemptSummary.codeMasked,
|
||||
resultCode: attemptSummary.resultCode,
|
||||
@@ -755,7 +779,7 @@ async function redeemClaimTaskWithInventoryFallback(context, initialInventoryIte
|
||||
})
|
||||
}
|
||||
|
||||
if (attemptIndex >= REDEEM_REPLACEMENT_LIMIT) {
|
||||
if (attemptIndex >= redeemReplacementLimit) {
|
||||
throw createRedeemTaskStateError('连续更换兑换码后仍未成功,请联系人工处理', {
|
||||
errorCode: 'claim_redeem_replacement_limit_reached',
|
||||
taskStatus: 'retry_pending',
|
||||
@@ -766,7 +790,7 @@ async function redeemClaimTaskWithInventoryFallback(context, initialInventoryIte
|
||||
})
|
||||
}
|
||||
|
||||
const replacement = await reserveInventoryForTask({
|
||||
const replacement = await reserveReplacementInventory({
|
||||
skuCode: context.orderItem.sku_code,
|
||||
taskId: context.task.id,
|
||||
credentialType: currentInventoryItem.credential_type || 'tencent_code',
|
||||
@@ -788,8 +812,8 @@ async function redeemClaimTaskWithInventoryFallback(context, initialInventoryIte
|
||||
})
|
||||
}
|
||||
|
||||
const replacedAt = nowIso()
|
||||
await createTaskEvent(context.task.id, 'claim_redeem_inventory_replaced', {
|
||||
const replacedAt = getNowIso()
|
||||
await createRedeemTaskEvent(context.task.id, 'claim_redeem_inventory_replaced', {
|
||||
previousInventoryItemId: currentInventoryItem.id,
|
||||
previousCodeMasked: attemptSummary.codeMasked,
|
||||
previousOutcome: classification.outcome,
|
||||
@@ -798,6 +822,7 @@ async function redeemClaimTaskWithInventoryFallback(context, initialInventoryIte
|
||||
credentialType: String(replacement.credential_type || currentInventoryItem.credential_type || ''),
|
||||
}, replacedAt)
|
||||
currentInventoryItem = replacement
|
||||
shouldReloadBeforeNextAttempt = true
|
||||
}
|
||||
|
||||
throw createRedeemTaskStateError('兑换失败,请稍后重试', {
|
||||
|
||||
Reference in New Issue
Block a user