修复名字显示bug
This commit is contained in:
@@ -7,6 +7,7 @@ import { formatFenToAmount, normalizeFen } from '../../utils/money.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'
|
||||||
import { buildClaimUrl } from './claim-service.js'
|
import { buildClaimUrl } from './claim-service.js'
|
||||||
|
import { getKuaishouCloudFulfillmentConfig } from '../order/kuaishou-cloud-fulfillment-config-service.js'
|
||||||
import type { ClaimTokenRow, OrderItemRow, OrderRow, TaskRow } from '../../types/repository/rows.js'
|
import type { ClaimTokenRow, OrderItemRow, OrderRow, TaskRow } from '../../types/repository/rows.js'
|
||||||
|
|
||||||
export const CLAIM_TERMINAL_STATUSES = new Set(['expired', 'closed'])
|
export const CLAIM_TERMINAL_STATUSES = new Set(['expired', 'closed'])
|
||||||
@@ -143,9 +144,13 @@ function resolveClaimOrderItemDisplaySkuName(
|
|||||||
const fulfillment = isPlainObject(kuaishouCloudFulfillment) ? kuaishouCloudFulfillment : {}
|
const fulfillment = isPlainObject(kuaishouCloudFulfillment) ? kuaishouCloudFulfillment : {}
|
||||||
const binding = isPlainObject(fulfillment.binding) ? fulfillment.binding : {}
|
const binding = isPlainObject(fulfillment.binding) ? fulfillment.binding : {}
|
||||||
const ticket = isPlainObject(fulfillment.ticket) ? fulfillment.ticket : {}
|
const ticket = isPlainObject(fulfillment.ticket) ? fulfillment.ticket : {}
|
||||||
|
const matchedConfigItem = resolveClaimFulfillmentConfigItem(orderItem, fulfillment, binding)
|
||||||
const skuCode = String(orderItem.sku_code || '').trim()
|
const skuCode = String(orderItem.sku_code || '').trim()
|
||||||
const rawSkuName = String(orderItem.sku_name || '').trim()
|
const rawSkuName = String(orderItem.sku_name || '').trim()
|
||||||
const candidates = [
|
const candidates = [
|
||||||
|
matchedConfigItem?.internalSkuName,
|
||||||
|
matchedConfigItem?.cloudSkuName,
|
||||||
|
matchedConfigItem?.resolvedSkuName,
|
||||||
fulfillment.internalSkuName,
|
fulfillment.internalSkuName,
|
||||||
binding.skuName,
|
binding.skuName,
|
||||||
ticket.goodsTitle,
|
ticket.goodsTitle,
|
||||||
@@ -163,6 +168,40 @@ function resolveClaimOrderItemDisplaySkuName(
|
|||||||
return rawSkuName || skuCode
|
return rawSkuName || skuCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveClaimFulfillmentConfigItem(
|
||||||
|
orderItem: OrderItemRow,
|
||||||
|
fulfillment: JsonObject,
|
||||||
|
binding: JsonObject,
|
||||||
|
) {
|
||||||
|
const config = getKuaishouCloudFulfillmentConfig()
|
||||||
|
const rawItems: unknown[] = Array.isArray(config.items) ? config.items : []
|
||||||
|
const items = rawItems.filter(isPlainObject)
|
||||||
|
const configId = String(fulfillment.configId || '').trim()
|
||||||
|
const skuCode = String(orderItem.sku_code || '').trim()
|
||||||
|
const skuName = String(orderItem.sku_name || '').trim()
|
||||||
|
const cloudSkuId = Number(binding.skuId || 0) || 0
|
||||||
|
|
||||||
|
return items.find((item) => {
|
||||||
|
if (configId && String(item.id || '').trim() === configId) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cloudSkuId > 0 && Number(item.cloudSkuId || 0) === cloudSkuId) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
item.internalSkuCode,
|
||||||
|
item.externalSkuCode,
|
||||||
|
item.externalItemId,
|
||||||
|
item.externalSkuName,
|
||||||
|
].some((value) => {
|
||||||
|
const normalized = String(value || '').trim()
|
||||||
|
return normalized && (normalized === skuCode || normalized === skuName)
|
||||||
|
})
|
||||||
|
}) || null
|
||||||
|
}
|
||||||
|
|
||||||
export function mapClaimKuaishouCloudFulfillment(task: TaskRow, order: OrderRow) {
|
export function mapClaimKuaishouCloudFulfillment(task: TaskRow, order: OrderRow) {
|
||||||
if (String(task?.executor_key || '').trim() !== 'kuaishou_ct_assisted') {
|
if (String(task?.executor_key || '').trim() !== 'kuaishou_ct_assisted') {
|
||||||
return null
|
return null
|
||||||
@@ -263,6 +302,10 @@ function isOrderItemIdentifierName(value: string, skuCode: string) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isClaimPlaceholderSkuName(normalized)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const normalizedSkuCode = String(skuCode || '').trim()
|
const normalizedSkuCode = String(skuCode || '').trim()
|
||||||
if (normalizedSkuCode && normalized === normalizedSkuCode) {
|
if (normalizedSkuCode && normalized === normalizedSkuCode) {
|
||||||
return true
|
return true
|
||||||
@@ -275,6 +318,10 @@ function isPlainObject(value: unknown): value is JsonObject {
|
|||||||
return Object.prototype.toString.call(value) === '[object Object]'
|
return Object.prototype.toString.call(value) === '[object Object]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isClaimPlaceholderSkuName(value: string) {
|
||||||
|
return ['测试链接专用', '商品领取', '测试商品'].includes(String(value || '').trim())
|
||||||
|
}
|
||||||
|
|
||||||
async function expireClaimContext(claimToken: ClaimTokenRow, task: TaskRow) {
|
async function expireClaimContext(claimToken: ClaimTokenRow, task: TaskRow) {
|
||||||
const now = nowIso()
|
const now = nowIso()
|
||||||
const nextClaimToken = await updateClaimToken(claimToken.id, {
|
const nextClaimToken = await updateClaimToken(claimToken.id, {
|
||||||
|
|||||||
Reference in New Issue
Block a user