优化快手云领取发货校验
This commit is contained in:
@@ -87,6 +87,7 @@ export async function getClaimContext(token: unknown) {
|
||||
|
||||
export function buildClaimDetailPayload({ claimToken, task, order, orderItem }: ClaimContext) {
|
||||
const kuaishouCloudFulfillment = mapClaimKuaishouCloudFulfillment(task, order)
|
||||
const displaySkuName = resolveClaimOrderItemDisplaySkuName(orderItem, kuaishouCloudFulfillment)
|
||||
|
||||
return {
|
||||
tokenStatus: claimToken.status,
|
||||
@@ -119,7 +120,7 @@ export function buildClaimDetailPayload({ claimToken, task, order, orderItem }:
|
||||
orderItem: {
|
||||
orderItemId: orderItem.id,
|
||||
skuCode: orderItem.sku_code,
|
||||
skuName: orderItem.sku_name,
|
||||
skuName: displaySkuName,
|
||||
quantity: orderItem.quantity,
|
||||
},
|
||||
session: null as null,
|
||||
@@ -135,6 +136,33 @@ export function buildClaimDetailPayload({ claimToken, task, order, orderItem }:
|
||||
}
|
||||
}
|
||||
|
||||
function resolveClaimOrderItemDisplaySkuName(
|
||||
orderItem: OrderItemRow,
|
||||
kuaishouCloudFulfillment: JsonObject | null,
|
||||
) {
|
||||
const fulfillment = isPlainObject(kuaishouCloudFulfillment) ? kuaishouCloudFulfillment : {}
|
||||
const binding = isPlainObject(fulfillment.binding) ? fulfillment.binding : {}
|
||||
const ticket = isPlainObject(fulfillment.ticket) ? fulfillment.ticket : {}
|
||||
const skuCode = String(orderItem.sku_code || '').trim()
|
||||
const rawSkuName = String(orderItem.sku_name || '').trim()
|
||||
const candidates = [
|
||||
fulfillment.internalSkuName,
|
||||
binding.skuName,
|
||||
ticket.goodsTitle,
|
||||
rawSkuName,
|
||||
skuCode,
|
||||
]
|
||||
|
||||
for (const value of candidates) {
|
||||
const normalized = String(value || '').trim()
|
||||
if (normalized && !isOrderItemIdentifierName(normalized, skuCode)) {
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
|
||||
return rawSkuName || skuCode
|
||||
}
|
||||
|
||||
export function mapClaimKuaishouCloudFulfillment(task: TaskRow, order: OrderRow) {
|
||||
if (String(task?.executor_key || '').trim() !== 'kuaishou_ct_assisted') {
|
||||
return null
|
||||
@@ -229,6 +257,24 @@ function parseTaskContext(task: TaskRow): JsonObject {
|
||||
return parseTaskContextValue(task)
|
||||
}
|
||||
|
||||
function isOrderItemIdentifierName(value: string, skuCode: string) {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) {
|
||||
return true
|
||||
}
|
||||
|
||||
const normalizedSkuCode = String(skuCode || '').trim()
|
||||
if (normalizedSkuCode && normalized === normalizedSkuCode) {
|
||||
return true
|
||||
}
|
||||
|
||||
return /^\d{8,}$/.test(normalized)
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
|
||||
async function expireClaimContext(claimToken: ClaimTokenRow, task: TaskRow) {
|
||||
const now = nowIso()
|
||||
const nextClaimToken = await updateClaimToken(claimToken.id, {
|
||||
|
||||
Reference in New Issue
Block a user