diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 995a40f..e652e19 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1704,6 +1704,34 @@ class PlatformOrderController extends Controller return redirect()->back()->with('success', $msg); } + public function clearSyncError(Request $request, PlatformOrder $order): RedirectResponse + { + $admin = $this->ensurePlatformAdmin($request); + + $meta = (array) ($order->meta ?? []); + if (! data_get($meta, 'subscription_activation_error')) { + return redirect()->back()->with('warning', '当前订单暂无同步失败标记,无需清理。'); + } + + data_forget($meta, 'subscription_activation_error'); + + // 轻量审计:记录清理动作(不做独立表,先落 meta,便于排查) + $audit = (array) (data_get($meta, 'audit', []) ?? []); + $audit[] = [ + 'action' => 'clear_sync_error', + 'scope' => 'single', + 'at' => now()->toDateTimeString(), + 'admin_id' => $admin->id, + 'note' => '手动点击订单详情【清除同步失败标记】', + ]; + data_set($meta, 'audit', $audit); + + $order->meta = $meta; + $order->save(); + + return redirect()->back()->with('success', '已清除该订单的同步失败标记。'); + } + 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 211930b..fa06392 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -565,7 +565,15 @@
-

最近一次同步失败

+
+

最近一次同步失败

+ @if($activationError) +
+ @csrf + +
+ @endif +
@if($activationError) @@ -574,6 +582,7 @@
操作管理员{{ data_get($activationError, 'admin_id') ?: '-' }}
+
提示:当你已确认问题已解决,但历史失败标记仍残留时,可先清理标记,再点击上方「重试同步订阅」。
@else

暂无失败记录。

@endif diff --git a/routes/web.php b/routes/web.php index 1e6b0e3..195ec3e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -128,6 +128,7 @@ Route::prefix('admin')->group(function () { Route::post('/platform-orders/{order}/mark-partially-refunded', [PlatformOrderController::class, 'markPartiallyRefunded']); 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::get('/site-subscriptions', [SiteSubscriptionController::class, 'index']); Route::get('/site-subscriptions/export', [SiteSubscriptionController::class, 'export']); diff --git a/tests/Feature/AdminPlatformOrderClearSyncErrorSingleTest.php b/tests/Feature/AdminPlatformOrderClearSyncErrorSingleTest.php new file mode 100644 index 0000000..394ce66 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderClearSyncErrorSingleTest.php @@ -0,0 +1,79 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_can_clear_single_order_sync_error_and_append_audit(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'clear_sync_error_single_test', + 'name' => '清理单订单同步失败标记测试', + '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_SYNC_ERR_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' => 9, + 'paid_amount' => 9, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => '历史同步失败', + 'at' => now()->subMinutes(2)->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/clear-sync-error') + ->assertRedirect(); + + $order->refresh(); + $this->assertEmpty(data_get($order->meta, 'subscription_activation_error')); + + $audit = (array) (data_get($order->meta, 'audit', []) ?? []); + $this->assertNotEmpty($audit); + $last = end($audit); + $this->assertSame('clear_sync_error', data_get($last, 'action')); + $this->assertSame('single', data_get($last, 'scope')); + $this->assertNotEmpty(data_get($last, 'admin_id')); + } +} diff --git a/tests/Feature/AdminPlatformOrderShowHasClearSyncErrorButtonTest.php b/tests/Feature/AdminPlatformOrderShowHasClearSyncErrorButtonTest.php new file mode 100644 index 0000000..39af112 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderShowHasClearSyncErrorButtonTest.php @@ -0,0 +1,71 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_show_page_renders_clear_sync_error_button_when_error_exists(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'show_clear_sync_error_btn_test', + 'name' => '详情页清理同步失败标记按钮测试', + '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_SYNC_ERR_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' => 9, + 'paid_amount' => 9, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => '历史同步失败', + 'at' => now()->subMinutes(2)->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $order->id) + ->assertOk() + ->assertSee('/admin/platform-orders/' . $order->id . '/clear-sync-error', false) + ->assertSee('清除失败标记'); + } +}