diff --git a/app/Http/Controllers/Admin/PlatformBatchController.php b/app/Http/Controllers/Admin/PlatformBatchController.php index 5b11242..991a109 100644 --- a/app/Http/Controllers/Admin/PlatformBatchController.php +++ b/app/Http/Controllers/Admin/PlatformBatchController.php @@ -93,7 +93,7 @@ class PlatformBatchController extends Controller ]; } - // 治理入口:全部/失败/按Top原因/可重试 + // 治理入口:全部/成功/失败/按Top原因/可重试 $governanceLinks = []; if ($type === 'bas') { @@ -101,6 +101,11 @@ class PlatformBatchController extends Controller 'batch_activation_run_id' => $runId, ]), $safeBackForLinks, 'filters'); + $governanceLinks['success'] = BackUrl::withBackAndFragment('/admin/platform-orders?' . \Illuminate\Support\Arr::query([ + 'batch_activation_run_id' => $runId, + 'sync_status' => 'synced', + ]), $safeBackForLinks, 'filters'); + $governanceLinks['failed'] = BackUrl::withBackAndFragment('/admin/platform-orders?' . \Illuminate\Support\Arr::query([ 'batch_activation_run_id' => $runId, 'sync_status' => 'failed', @@ -129,6 +134,11 @@ class PlatformBatchController extends Controller 'batch_bmpa_run_id' => $runId, ]), $safeBackForLinks, 'filters'); + $governanceLinks['success'] = BackUrl::withBackAndFragment('/admin/platform-orders?' . \Illuminate\Support\Arr::query([ + 'batch_bmpa_run_id' => $runId, + 'bmpa_success_only' => '1', + ]), $safeBackForLinks, 'filters'); + $governanceLinks['failed'] = BackUrl::withBackAndFragment('/admin/platform-orders?' . \Illuminate\Support\Arr::query([ 'batch_bmpa_run_id' => $runId, 'bmpa_failed_only' => '1', diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 15c7d34..1e28f09 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -248,6 +248,8 @@ class PlatformOrderController extends Controller 'fail_only' => (string) $request->query('fail_only', ''), // 只看批量“标记支付并生效”失败:meta.batch_mark_paid_and_activate_error.message 存在 'bmpa_failed_only' => (string) $request->query('bmpa_failed_only', ''), + // 只看批量“标记支付并生效”成功:存在 run_id 且 error.message 为空 + 'bmpa_success_only' => (string) $request->query('bmpa_success_only', ''), 'synced_only' => (string) $request->query('synced_only', ''), 'sync_status' => trim((string) $request->query('sync_status', '')), 'keyword' => trim((string) $request->query('keyword', '')), @@ -1315,6 +1317,8 @@ class PlatformOrderController extends Controller 'fail_only' => (string) $request->query('fail_only', ''), // 只看批量“标记支付并生效”失败:meta.batch_mark_paid_and_activate_error.message 存在 'bmpa_failed_only' => (string) $request->query('bmpa_failed_only', ''), + // 只看批量“标记支付并生效”成功:存在 run_id 且 error.message 为空 + 'bmpa_success_only' => (string) $request->query('bmpa_success_only', ''), 'synced_only' => (string) $request->query('synced_only', ''), 'sync_status' => trim((string) $request->query('sync_status', '')), 'keyword' => trim((string) $request->query('keyword', '')), @@ -2316,6 +2320,12 @@ class PlatformOrderController extends Controller // 只看批量“标记支付并生效”失败:meta.batch_mark_paid_and_activate_error.message 存在即视为失败 $builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NOT NULL"); }) + ->when(($filters['bmpa_success_only'] ?? '') === '1', function (Builder $builder) { + // 只看批量“标记支付并生效”成功:存在 run_id 且 error.message 为空。 + // 用途:从批次复盘页快速进入“本批次成功集合”(便于 spot-check 与抽样复核)。 + $builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate.run_id') IS NOT NULL") + ->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NULL"); + }) ->when(($filters['synced_only'] ?? '') !== '', function (Builder $builder) { // 只看已同步:meta.subscription_activation.subscription_id 存在即视为已同步 $builder->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NOT NULL"); diff --git a/resources/views/admin/platform_batches/show.blade.php b/resources/views/admin/platform_batches/show.blade.php index c2a001c..37ce5a1 100644 --- a/resources/views/admin/platform_batches/show.blade.php +++ b/resources/views/admin/platform_batches/show.blade.php @@ -84,10 +84,14 @@

成功 / 失败

+
提示:点击数字可进入对应集合(成功=可抽样复核)。
@if($hasSummary) - @if(($governanceLinks['all'] ?? '') !== '') - {{ $success }} + @php + $successLink = (string) ($governanceLinks['success'] ?? ($governanceLinks['all'] ?? '')); + @endphp + @if($successLink !== '') + {{ $success }} @else {{ $success }} @endif diff --git a/tests/Feature/AdminPlatformBatchShowPageSuccessCountsShouldPreferSuccessGovernanceLinkTest.php b/tests/Feature/AdminPlatformBatchShowPageSuccessCountsShouldPreferSuccessGovernanceLinkTest.php new file mode 100644 index 0000000..751fd27 --- /dev/null +++ b/tests/Feature/AdminPlatformBatchShowPageSuccessCountsShouldPreferSuccessGovernanceLinkTest.php @@ -0,0 +1,84 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_show_page_success_count_link_should_prefer_success_governance_link_when_present(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'plan_batch_success_link_0001', + 'name' => '批次页成功集合链接优先级测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $runId = 'BMPA_SUCCESS_LINK_0001'; + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BMPA_SUCCESS_LINK_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now()->subMinutes(10), + 'paid_at' => now()->subMinutes(9), + 'activated_at' => now()->subMinutes(8), + 'meta' => [ + 'batch_mark_paid_and_activate' => [ + 'run_id' => $runId, + 'last_result' => [ + 'run_id' => $runId, + 'success' => 7, + 'failed' => 3, + 'matched' => 10, + 'processed' => 10, + 'top_reasons' => [], + 'at' => now()->toDateTimeString(), + ], + ], + ], + ]); + + $html = $this->get('/admin/platform-batches/show?type=bmpa&run_id=' . $runId) + ->assertOk() + ->getContent(); + + // 成功数字链接:应优先指向 success 集合(bmpa_success_only=1),而不是 all。 + $this->assertStringContainsString('data-role="batch-success-count-link"', $html); + $this->assertStringContainsString('batch_bmpa_run_id=' . $runId, $html); + $this->assertStringContainsString('bmpa_success_only=1', $html); + } +}