update refund parse

This commit is contained in:
2026-03-04 14:29:25 +08:00
parent 26e5c6806c
commit a9ec179ead
2 changed files with 35 additions and 8 deletions
+23 -3
View File
@@ -85,17 +85,19 @@ class RefundConsumer extends ConsumerMessage
$raw_data = $data['data'] ?? [];
$entity_map_result = $parse->entityMap($raw_data);
$data_to_upsert = $entity_map_result->all();
$platform_refund_id_to_local_refund_id_map = null;
// 退款信息为空且有父退款,直接返回 ACK
if (empty($data_to_upsert) && $parse->hasParentRefund) {
if (empty($data_to_upsert) && $parse->hasParentRefund()) {
dump('No data to process');
return Result::ACK;
}
// 无父级退款,直接使用平台售后单的情况, 比如 Tmall
if(!$parse->hasParentRefund){
if(!$parse->hasParentRefund()){
goto PROCESS_REFUND_ITEMS;
}
@@ -127,7 +129,15 @@ class RefundConsumer extends ConsumerMessage
->pluck('id', 'platform_refund_id')
->toArray();
dump("ID mapping: " . count($platform_refund_id_to_local_refund_id_map) . " refunds");
if ($parse->hasParentRefund() && empty($platform_refund_id_to_local_refund_id_map)) {
Log::get()->warning('Refund ID mapping is empty after upsert, refund_items.refund_id will not be populated', [
'store_id' => $parse->getStore()->id,
'platform' => $parse->getPlatform()->name ?? '',
]);
}
// @TODO refund type 也需要进一步确定 app/Constants/RefundType.php
// @attention 没有父退款的平台,业务直接跳到此处执行
@@ -139,10 +149,20 @@ class RefundConsumer extends ConsumerMessage
// 4. 处理退款子项
$this->processRefundItems($items);
// 5. Tmall 闪电退款订单重建(从退款数据恢复缺失的 Order/OrderItem
// @TODO 添加平台检查,而不仅限于 Tmall, 其他平台可能存在类似情况
if (method_exists($parse, 'fixInstantRefundOrders')) {
$parse->fixInstantRefundOrders($raw_data);
}
Db::commit();
return Result::ACK;
} catch (Throwable $error) {
dump($error->getMessage());
dump($error->getTraceAsString());
Log::get()->error('Refund consumer processing failed', [
'error' => $error->getMessage(),
'retry_count' => $retry_count,