From 6973e5af219f4a1744e168dabba5f74cc0f5e96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 18 Mar 2026 12:17:45 +0800 Subject: [PATCH] feat: platform order index sync failed reason link prefer batch run --- .../admin/platform_orders/index.blade.php | 48 +++++++++++- ...kShouldPreferBatchRunIdWhenPresentTest.php | 78 +++++++++++++++++++ 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderIndexSyncFailedReasonLinkShouldPreferBatchRunIdWhenPresentTest.php diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 1422377..7252493 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -1477,14 +1477,58 @@ - @else @if($syncErrMsg !== '') + @php + // 同步失败:默认落到“可执行集合”(优先同批次) + $basRunIdRow = (string) (data_get($order->meta, 'batch_activation.last_result.run_id') ?? ''); + if ($basRunIdRow === '') { + $basRunIdRow = (string) (data_get($order->meta, 'batch_activation.run_id') ?? ''); + } + + $syncGoFailedUrl = $buildQuickFilterUrl([ + 'sync_status' => 'failed', + 'page' => null, + ]); + + $syncGoBatchFailedUrl = ''; + $syncGoBatchReasonUrl = ''; + if ($basRunIdRow !== '') { + $syncGoBatchFailedUrl = $buildQuickFilterUrl([ + 'batch_activation_run_id' => $basRunIdRow, + 'sync_status' => 'failed', + 'page' => null, + ]); + + if (! $syncErrTooLong) { + $syncGoBatchReasonUrl = $buildQuickFilterUrl([ + 'batch_activation_run_id' => $basRunIdRow, + 'sync_status' => 'failed', + 'sync_error_keyword' => $syncErrMsg, + 'page' => null, + ]); + } + } + + $syncGoReasonUrl = $buildQuickFilterUrl([ + 'sync_error_keyword' => $syncErrMsg, + 'sync_status' => 'failed', + 'page' => null, + ]); + + $syncErrorLinkUrl = $syncGoBatchReasonUrl !== '' ? $syncGoBatchReasonUrl : $syncGoReasonUrl; + @endphp
同步: @if($syncErrTooLong) {{ mb_substr($syncErrMsg, 0, $SYNC_FAILED_REASON_TRUNCATE_LEN) }}
原因过长,请复制到筛选框
- 进入同步失败集合 + + @if($syncGoBatchFailedUrl !== '') + + @else + + @endif @else - {{ mb_substr($syncErrMsg, 0, $SYNC_FAILED_REASON_TRUNCATE_LEN) }} + {{ mb_substr($syncErrMsg, 0, $SYNC_FAILED_REASON_TRUNCATE_LEN) }} @endif
@endif diff --git a/tests/Feature/AdminPlatformOrderIndexSyncFailedReasonLinkShouldPreferBatchRunIdWhenPresentTest.php b/tests/Feature/AdminPlatformOrderIndexSyncFailedReasonLinkShouldPreferBatchRunIdWhenPresentTest.php new file mode 100644 index 0000000..9878c71 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexSyncFailedReasonLinkShouldPreferBatchRunIdWhenPresentTest.php @@ -0,0 +1,78 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_order_index_sync_failed_reason_link_should_prefer_batch_run_id_when_present(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id'); + + $plan = Plan::query()->create([ + 'code' => 'po_index_sync_failed_link_plan', + 'name' => '平台订单列表 同步失败原因链接优先批次测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'site_subscription_id' => null, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_INDEX_SYNC_FAILED_LINK_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => 'SYNC_FAILED_KEYWORD_DEMO', + ], + 'batch_activation' => [ + 'last_result' => [ + 'run_id' => 'BAS_RUN_ID_0001', + ], + ], + ], + ]); + + $res = $this->get('/admin/platform-orders'); + $res->assertOk(); + + $res->assertSee('PO_INDEX_SYNC_FAILED_LINK_0001'); + + // 行内“同步失败原因”应优先落到“本批次按原因筛选”(而不是全局原因筛选),减少噪音并提升可执行性 + $res->assertSee('batch_activation_run_id=BAS_RUN_ID_0001', false); + $res->assertSee('sync_status=failed', false); + $res->assertSee('sync_error_keyword=SYNC_FAILED_KEYWORD_DEMO', false); + } +}