From d6d95a5cb01d447afe7c9c3afad78458685fdf62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 12:07:15 +0800 Subject: [PATCH] refactor(billing): unify BMPA audit to use snapshot fields --- .../Admin/PlatformOrderController.php | 6 +- .../admin/platform_orders/show.blade.php | 8 ++- ...dActivateAuditSnapshotShouldRenderTest.php | 70 +++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderMarkPaidAndActivateAuditSnapshotShouldRenderTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index b48d023..4d4c90e 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -891,8 +891,10 @@ class PlatformOrderController extends Controller 'at' => now()->toDateTimeString(), 'admin_id' => $admin->id, 'subscription_id' => $subscription->id, - 'paid_amount' => (float) ($order->paid_amount ?? 0), - 'payable_amount' => (float) ($order->payable_amount ?? 0), + 'snapshot' => [ + 'paid_amount' => (float) ($order->paid_amount ?? 0), + 'payable_amount' => (float) ($order->payable_amount ?? 0), + ], 'note' => '手动点击订单详情【标记支付并生效】(包含订阅同步)', ]; data_set($meta, 'audit', $audit); diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index ebc458e..7789a57 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -865,8 +865,12 @@ $snapPaid = data_get($snap, 'paid_amount'); $snapRefund = data_get($snap, 'refund_total'); if ($snapPaid !== null || $snapRefund !== null) { - $pairs[] = 'paid=¥' . number_format((float) ($snapPaid ?? 0), 2); - $pairs[] = 'refund=¥' . number_format((float) ($snapRefund ?? 0), 2); + if ($snapPaid !== null) { + $pairs[] = 'paid=¥' . number_format((float) $snapPaid, 2); + } + if ($snapRefund !== null) { + $pairs[] = 'refund=¥' . number_format((float) $snapRefund, 2); + } // 剩余字段:key=value foreach ($snap as $k => $v) { diff --git a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateAuditSnapshotShouldRenderTest.php b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateAuditSnapshotShouldRenderTest.php new file mode 100644 index 0000000..071de35 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateAuditSnapshotShouldRenderTest.php @@ -0,0 +1,70 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_mark_paid_and_activate_should_write_snapshot_paid_amount_and_show_page_can_render_it(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'mark_paid_audit_snapshot_plan', + 'name' => '标记支付并生效审计快照测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_MARK_PAID_AUDIT_SNAPSHOT_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' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/mark-paid-and-activate') + ->assertRedirect(); + + $order->refresh(); + + $this->assertSame(30.0, (float) data_get($order->meta, 'audit.0.snapshot.paid_amount')); + $this->assertSame(30.0, (float) data_get($order->meta, 'audit.0.snapshot.payable_amount')); + + $this->get('/admin/platform-orders/' . $order->id) + ->assertOk() + ->assertSee('paid=¥30.00') + ->assertSee('payable_amount=30'); + } +}