From ab02e5ca6b36f59b7c25883746f104bcd6d33bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 13:10:46 +0800 Subject: [PATCH] feat(platform-orders): filter batch activation by run_id --- .../Admin/PlatformOrderController.php | 21 ++++ .../admin/platform_orders/index.blade.php | 1 + ...tchActivationRunIdFilterShouldWorkTest.php | 100 ++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderIndexBatchActivationRunIdFilterShouldWorkTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 2b78228..9e50106 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -260,6 +260,8 @@ class PlatformOrderController extends Controller 'renewal_missing_subscription' => (string) $request->query('renewal_missing_subscription', ''), // 只看最近 24 小时批量同步过的订单(可治理追踪) 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''), + // 批次号筛选:用于队列批量同步 run_id 追溯 + 'batch_activation_run_id' => trim((string) $request->query('batch_activation_run_id', '')), // 只看最近 24 小时批量“标记支付并生效(BMPA)”过的订单(可治理追踪) 'batch_mark_paid_and_activate_24h' => (string) $request->query('batch_mark_paid_and_activate_24h', ''), // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) @@ -1292,6 +1294,8 @@ class PlatformOrderController extends Controller 'renewal_missing_subscription' => (string) $request->query('renewal_missing_subscription', ''), // 只看最近 24 小时批量同步过的订单(可治理追踪) 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''), + // 批次号筛选:用于队列批量同步 run_id 追溯 + 'batch_activation_run_id' => trim((string) $request->query('batch_activation_run_id', '')), // 只看最近 24 小时批量“标记支付并生效(BMPA)”过的订单(可治理追踪) 'batch_mark_paid_and_activate_24h' => (string) $request->query('batch_mark_paid_and_activate_24h', ''), // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) @@ -1476,6 +1480,7 @@ class PlatformOrderController extends Controller 'syncable_only' => (string) $request->input('syncable_only', ''), 'renewal_missing_subscription' => (string) $request->input('renewal_missing_subscription', ''), 'batch_synced_24h' => (string) $request->input('batch_synced_24h', ''), + 'batch_activation_run_id' => trim((string) $request->input('batch_activation_run_id', '')), // 与列表页筛选保持一致(可治理):用于在批量操作后仍能回到同一口径 'batch_mark_paid_and_activate_24h' => (string) $request->input('batch_mark_paid_and_activate_24h', ''), 'batch_mark_activated_24h' => (string) $request->input('batch_mark_activated_24h', ''), @@ -1870,6 +1875,7 @@ class PlatformOrderController extends Controller 'syncable_only' => (string) $request->input('syncable_only', ''), 'renewal_missing_subscription' => (string) $request->input('renewal_missing_subscription', ''), 'batch_synced_24h' => (string) $request->input('batch_synced_24h', ''), + 'batch_activation_run_id' => trim((string) $request->input('batch_activation_run_id', '')), // 与列表页筛选保持一致(可治理):用于在批量操作后仍能回到同一口径 'batch_mark_paid_and_activate_24h' => (string) $request->input('batch_mark_paid_and_activate_24h', ''), 'batch_mark_activated_24h' => (string) $request->input('batch_mark_activated_24h', ''), @@ -2122,6 +2128,7 @@ class PlatformOrderController extends Controller 'syncable_only' => (string) $request->input('syncable_only', ''), 'renewal_missing_subscription' => (string) $request->input('renewal_missing_subscription', ''), 'batch_synced_24h' => (string) $request->input('batch_synced_24h', ''), + 'batch_activation_run_id' => trim((string) $request->input('batch_activation_run_id', '')), // 与列表页筛选保持一致(可治理):用于在批量操作后仍能回到同一口径 'batch_mark_paid_and_activate_24h' => (string) $request->input('batch_mark_paid_and_activate_24h', ''), 'batch_mark_activated_24h' => (string) $request->input('batch_mark_activated_24h', ''), @@ -2408,6 +2415,20 @@ class PlatformOrderController extends Controller $builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]); } }) + ->when(($filters['batch_activation_run_id'] ?? '') !== '', function (Builder $builder) use ($filters) { + // 按批次号筛选:用于队列批量同步 run_id 追溯 + $runId = trim((string) ($filters['batch_activation_run_id'] ?? '')); + if ($runId === '') { + return; + } + + $driver = $builder->getQuery()->getConnection()->getDriverName(); + if ($driver === 'sqlite') { + $builder->whereRaw("JSON_EXTRACT(meta, '$.batch_activation.run_id') = ?", [$runId]); + } else { + $builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.run_id')) = ?", [$runId]); + } + }) ->when(($filters['batch_mark_paid_and_activate_24h'] ?? '') !== '', function (Builder $builder) { // 只看最近 24 小时批量“标记支付并生效(BMPA)”过的订单(基于 meta.batch_mark_paid_and_activate.at) $since = now()->subHours(24)->format('Y-m-d H:i:s'); diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index cf30a47..8d2d3b6 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -471,6 +471,7 @@ 最近24小时批量同步过 +