From 98073f2b71ffb2e2df83f3267b326e2cfff02fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 14:13:30 +0000 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=AE=A2=E5=8D=95=EF=BC=9A?= =?UTF-8?q?=E8=A1=A5=E9=BD=90=20BMPA=20=E5=8D=95=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=85=A5=E5=8F=A3=EF=BC=88=E8=B7=AF=E7=94=B1?= =?UTF-8?q?+=E6=8E=A7=E5=88=B6=E5=99=A8+=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E6=8C=89=E9=92=AE+=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- -n | 0 .../Admin/PlatformOrderController.php | 28 +++++++ .../admin/platform_orders/show.blade.php | 27 +++++++ routes/web.php | 1 + ...nPlatformOrderClearBmpaErrorSingleTest.php | 77 +++++++++++++++++++ ...rmOrderShowHasClearBmpaErrorButtonTest.php | 69 +++++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 -n create mode 100644 tests/Feature/AdminPlatformOrderClearBmpaErrorSingleTest.php create mode 100644 tests/Feature/AdminPlatformOrderShowHasClearBmpaErrorButtonTest.php diff --git a/-n b/-n new file mode 100644 index 0000000..e69de29 diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index e652e19..b635d20 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1732,6 +1732,34 @@ class PlatformOrderController extends Controller return redirect()->back()->with('success', '已清除该订单的同步失败标记。'); } + public function clearBmpaError(Request $request, PlatformOrder $order): RedirectResponse + { + $admin = $this->ensurePlatformAdmin($request); + + $meta = (array) ($order->meta ?? []); + if (! data_get($meta, 'batch_mark_paid_and_activate_error')) { + return redirect()->back()->with('warning', '当前订单暂无 BMPA 失败标记,无需清理。'); + } + + data_forget($meta, 'batch_mark_paid_and_activate_error'); + + // 轻量审计:记录清理动作(不做独立表,先落 meta,便于排查) + $audit = (array) (data_get($meta, 'audit', []) ?? []); + $audit[] = [ + 'action' => 'clear_bmpa_error', + 'scope' => 'single', + 'at' => now()->toDateTimeString(), + 'admin_id' => $admin->id, + 'note' => '手动点击订单详情【清除 BMPA 失败标记】', + ]; + data_set($meta, 'audit', $audit); + + $order->meta = $meta; + $order->save(); + + return redirect()->back()->with('success', '已清除该订单的 BMPA 失败标记。'); + } + public function clearSyncErrors(Request $request): RedirectResponse { $this->ensurePlatformAdmin($request); diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index fa06392..0df775c 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -368,6 +368,7 @@ @php $activation = data_get($order->meta, 'subscription_activation'); $activationError = data_get($order->meta, 'subscription_activation_error'); + $bmpaError = data_get($order->meta, 'batch_mark_paid_and_activate_error'); $audit = (array) (data_get($order->meta, 'audit', []) ?? []); $paymentReceipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []); $refundReceipts = (array) (data_get($order->meta, 'refund_receipts', []) ?? []); @@ -588,6 +589,31 @@ @endif +
+
+

最近一次 BMPA 失败

+ @if($bmpaError) +
+ @csrf + +
+ @endif +
+ + @if($bmpaError) + + + + + + +
失败原因{{ data_get($bmpaError, 'message') }}
失败时间{{ data_get($bmpaError, 'at') ?: '-' }}
操作管理员{{ data_get($bmpaError, 'admin_id') ?: '-' }}
+
提示:当你已修复导致 BMPA 失败的原因(回执/退款/权限/幂等等),但历史失败标记仍残留时,可先清理标记,再重新执行 BMPA。
+ @else +

暂无失败记录。

+ @endif +
+

审计记录(最近 20 条)

@if(count($audit) > 0) @@ -595,6 +621,7 @@ $auditItems = array_slice(array_reverse($audit), 0, 20); $auditActionLabels = [ 'clear_sync_error' => '清除同步失败标记', + 'clear_bmpa_error' => '清除 BMPA 失败标记', 'batch_activate_subscription' => '批量同步订阅', 'mark_activated' => '仅标记为已生效', 'batch_mark_activated' => '批量仅标记为已生效', diff --git a/routes/web.php b/routes/web.php index 195ec3e..00697e4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -129,6 +129,7 @@ Route::prefix('admin')->group(function () { Route::post('/platform-orders/{order}/mark-paid-status', [PlatformOrderController::class, 'markPaidStatus']); Route::post('/platform-orders/{order}/mark-activated', [PlatformOrderController::class, 'markActivated']); Route::post('/platform-orders/{order}/clear-sync-error', [PlatformOrderController::class, 'clearSyncError']); + Route::post('/platform-orders/{order}/clear-bmpa-error', [PlatformOrderController::class, 'clearBmpaError']); Route::get('/site-subscriptions', [SiteSubscriptionController::class, 'index']); Route::get('/site-subscriptions/export', [SiteSubscriptionController::class, 'export']); diff --git a/tests/Feature/AdminPlatformOrderClearBmpaErrorSingleTest.php b/tests/Feature/AdminPlatformOrderClearBmpaErrorSingleTest.php new file mode 100644 index 0000000..3622f11 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderClearBmpaErrorSingleTest.php @@ -0,0 +1,77 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_can_clear_single_order_bmpa_error_and_append_audit(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'clear_bmpa_error_single_test', + 'name' => '清理单订单 BMPA 失败标记测试', + 'billing_cycle' => 'monthly', + 'price' => 9, + 'list_price' => 9, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_CLEAR_BMPA_ERR_SINGLE_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 9, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'batch_mark_paid_and_activate_error' => [ + 'message' => '历史 BMPA 失败', + 'at' => now()->subMinutes(3)->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/clear-bmpa-error') + ->assertRedirect(); + + $order->refresh(); + $this->assertEmpty(data_get($order->meta, 'batch_mark_paid_and_activate_error')); + + $audit = (array) (data_get($order->meta, 'audit', []) ?? []); + $this->assertNotEmpty($audit); + $last = end($audit); + $this->assertSame('clear_bmpa_error', data_get($last, 'action')); + $this->assertSame('single', data_get($last, 'scope')); + $this->assertNotEmpty(data_get($last, 'admin_id')); + } +} diff --git a/tests/Feature/AdminPlatformOrderShowHasClearBmpaErrorButtonTest.php b/tests/Feature/AdminPlatformOrderShowHasClearBmpaErrorButtonTest.php new file mode 100644 index 0000000..45a7d89 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderShowHasClearBmpaErrorButtonTest.php @@ -0,0 +1,69 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_show_page_renders_clear_bmpa_error_button_when_error_exists(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'show_clear_bmpa_error_btn_test', + 'name' => '详情页清理 BMPA 失败标记按钮测试', + 'billing_cycle' => 'monthly', + 'price' => 9, + 'list_price' => 9, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_SHOW_CLEAR_BMPA_ERR_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 9, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'batch_mark_paid_and_activate_error' => [ + 'message' => '历史 BMPA 失败', + 'at' => now()->subMinutes(2)->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $order->id) + ->assertOk() + ->assertSee('/admin/platform-orders/' . $order->id . '/clear-bmpa-error', false) + ->assertSee('清除 BMPA 失败标记'); + } +}