增加忽略商品
This commit is contained in:
@@ -4,6 +4,7 @@ import { runtimeConfig } from '../../config/runtime.js'
|
||||
import { createWebhookEvent, updateWebhookEvent } from '../../repositories/webhook-event-repo.js'
|
||||
import { enrichAgisoXianyuTradeOrder } from '../platforms/agiso/xianyu/order-detail-service.js'
|
||||
import { upsertOrderFromWebhook } from './order-service.js'
|
||||
import { hasConfiguredOrderItems } from './product-match-service.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { parseJsonObject } from '../../utils/json.js'
|
||||
import { logWebhook } from '../../utils/logger.js'
|
||||
@@ -89,6 +90,52 @@ async function executeAgisoTradeWebhook(parsed, webhookEventId, { requestId = ''
|
||||
})
|
||||
}
|
||||
|
||||
const shouldProcess = await hasConfiguredOrderItems({
|
||||
provider: parsed.provider,
|
||||
platform: parsed.platform,
|
||||
shopId: parsed.shopId,
|
||||
items: parsed.items,
|
||||
})
|
||||
|
||||
if (!shouldProcess) {
|
||||
await updateWebhookEvent(webhookEventId, {
|
||||
processed: true,
|
||||
process_error: 'ignored_unconfigured_product',
|
||||
related_order_id: null,
|
||||
})
|
||||
|
||||
logWebhook('[webhook-service/agiso]', 'Webhook 已忽略:未命中任何已配置履约商品', {
|
||||
requestId,
|
||||
webhookEventId,
|
||||
provider: parsed.provider,
|
||||
platform: parsed.platform,
|
||||
shopId: parsed.shopId,
|
||||
shopName: parsed.shopName,
|
||||
platformOrderId: parsed.platformOrderId,
|
||||
rawItemCount: Array.isArray(parsed.items) ? parsed.items.length : 0,
|
||||
})
|
||||
|
||||
return {
|
||||
accepted: true,
|
||||
ignored: true,
|
||||
ignoreReason: 'unconfigured_product',
|
||||
provider: parsed.provider,
|
||||
platform: parsed.platform,
|
||||
shopId: parsed.shopId,
|
||||
shopName: parsed.shopName,
|
||||
platformRaw: parsed.platformRaw,
|
||||
eventType: parsed.eventType,
|
||||
platformOrderId: parsed.platformOrderId,
|
||||
orderId: null,
|
||||
totalAmountFen: Number(parsed.totalAmount || 0),
|
||||
enriched: false,
|
||||
enrichReason: 'skipped_unconfigured_product',
|
||||
taskCount: 0,
|
||||
messageDeliveries: [],
|
||||
tasks: [],
|
||||
}
|
||||
}
|
||||
|
||||
const enriched = await enrichTradeBeforeUpsert(parsed, {
|
||||
requestId,
|
||||
webhookEventId,
|
||||
@@ -96,8 +143,8 @@ async function executeAgisoTradeWebhook(parsed, webhookEventId, { requestId = ''
|
||||
const result = await upsertOrderFromWebhook(enriched.parsed)
|
||||
await updateWebhookEvent(webhookEventId, {
|
||||
processed: true,
|
||||
process_error: '',
|
||||
related_order_id: result.order.id,
|
||||
process_error: result.ignored ? 'ignored_unconfigured_product' : '',
|
||||
related_order_id: result.order?.id || null,
|
||||
})
|
||||
|
||||
logWebhook('[webhook-service/agiso]', 'Webhook 业务处理成功', {
|
||||
@@ -110,7 +157,9 @@ async function executeAgisoTradeWebhook(parsed, webhookEventId, { requestId = ''
|
||||
eventKey: parsed.eventKey,
|
||||
eventType: parsed.eventType,
|
||||
platformOrderId: enriched.parsed.platformOrderId,
|
||||
orderId: result.order.id,
|
||||
orderId: result.order?.id || null,
|
||||
ignored: Boolean(result.ignored),
|
||||
ignoreReason: String(result.ignoreReason || ''),
|
||||
enriched: enriched.enriched,
|
||||
enrichReason: enriched.reason || '',
|
||||
totalAmountFen: Number(enriched.parsed.totalAmount || 0),
|
||||
@@ -127,8 +176,10 @@ async function executeAgisoTradeWebhook(parsed, webhookEventId, { requestId = ''
|
||||
platformRaw: enriched.parsed.platformRaw,
|
||||
eventType: enriched.parsed.eventType,
|
||||
platformOrderId: enriched.parsed.platformOrderId,
|
||||
orderId: result.order.id,
|
||||
orderId: result.order?.id || null,
|
||||
totalAmountFen: Number(enriched.parsed.totalAmount || 0),
|
||||
ignored: Boolean(result.ignored),
|
||||
ignoreReason: String(result.ignoreReason || ''),
|
||||
enriched: enriched.enriched,
|
||||
enrichReason: enriched.reason || '',
|
||||
taskCount: result.tasks.length,
|
||||
|
||||
Reference in New Issue
Block a user