From 976ecc546d8c42acad353835a03f45ad80bc8be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 07:54:12 +0000 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=AE=A2=E5=8D=95=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=EF=BC=9A=E5=AF=B9=E8=B4=A6=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E5=AD=97=E6=AE=B5=E9=80=8F=E4=BC=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8A=A4=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tionsReconcileMismatchFilterFieldsTest.php | 86 +++++++++++++++++++ ...vatedReconcileMismatchFilterFieldsTest.php | 84 ++++++++++++++++++ ...rrorsReconcileMismatchFilterFieldsTest.php | 85 ++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsReconcileMismatchFilterFieldsTest.php create mode 100644 tests/Feature/AdminPlatformOrderBatchMarkActivatedReconcileMismatchFilterFieldsTest.php create mode 100644 tests/Feature/AdminPlatformOrderClearSyncErrorsReconcileMismatchFilterFieldsTest.php diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsReconcileMismatchFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsReconcileMismatchFilterFieldsTest.php new file mode 100644 index 0000000..bd53696 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsReconcileMismatchFilterFieldsTest.php @@ -0,0 +1,86 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_subscriptions_filtered_scope_respects_reconcile_mismatch_filter_fields(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_activate_reconcile_mismatch_filter_fields_test', + 'name' => '批量同步对账不一致筛选字段测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 可同步订单:已支付+已生效+未同步;并构造对账不一致(receipt_total 9.98 vs paid_amount 10) + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BATCH_ACTIVATE_RECON_MISMATCH_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(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 9.98, + ], + ], + ]); + + // 访问列表页:确保批量同步表单透传 reconcile_mismatch + $page = $this->get('/admin/platform-orders?syncable_only=1&reconcile_mismatch=1'); + $page->assertOk(); + $page->assertSee('name="reconcile_mismatch"', false); + $page->assertSee('value="1"', false); + + // 执行批量同步(filtered scope 且必须 syncable_only=1 才能提交) + $res = $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'reconcile_mismatch' => '1', + 'limit' => 50, + ]); + + $res->assertRedirect(); + + // 至少验证该订单确实被命中并写入 subscription_activation.subscription_id + $order->refresh(); + $this->assertNotEmpty(data_get($order->meta, 'subscription_activation.subscription_id')); + } +} diff --git a/tests/Feature/AdminPlatformOrderBatchMarkActivatedReconcileMismatchFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderBatchMarkActivatedReconcileMismatchFilterFieldsTest.php new file mode 100644 index 0000000..1e2ea23 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchMarkActivatedReconcileMismatchFilterFieldsTest.php @@ -0,0 +1,84 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_mark_activated_filtered_scope_respects_reconcile_mismatch_filter_fields(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_mark_activated_reconcile_mismatch_filter_fields_test', + 'name' => '批量仅标记生效对账不一致筛选字段测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 待处理订单:已支付 + pending;并构造对账不一致 + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BATCH_MARK_ACTIVATED_RECON_MISMATCH_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + '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(), + 'paid_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 9.98, + ], + ], + ]); + + // 访问列表页:确保批量仅标记生效表单透传 reconcile_mismatch + $page = $this->get('/admin/platform-orders?payment_status=paid&status=pending&reconcile_mismatch=1'); + $page->assertOk(); + $page->assertSee('name="reconcile_mismatch"', false); + $page->assertSee('value="1"', false); + + $res = $this->post('/admin/platform-orders/batch-mark-activated', [ + 'scope' => 'filtered', + 'payment_status' => 'paid', + 'status' => 'pending', + 'reconcile_mismatch' => '1', + 'limit' => 50, + ]); + + $res->assertRedirect(); + + $order->refresh(); + $this->assertSame('activated', $order->status); + } +} diff --git a/tests/Feature/AdminPlatformOrderClearSyncErrorsReconcileMismatchFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderClearSyncErrorsReconcileMismatchFilterFieldsTest.php new file mode 100644 index 0000000..2b48348 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderClearSyncErrorsReconcileMismatchFilterFieldsTest.php @@ -0,0 +1,85 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_clear_sync_errors_filtered_scope_respects_reconcile_mismatch_filter_fields(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'clear_sync_errors_reconcile_mismatch_filter_fields_test', + 'name' => '清理失败标记对账不一致筛选字段测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_CLEAR_SYNC_ERRORS_RECON_MISMATCH_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(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => '模拟失败原因', + 'at' => now()->toDateTimeString(), + 'admin_id' => 1, + ], + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 9.98, + ], + ], + ]); + + // 确认列表页清理表单透传 reconcile_mismatch + $page = $this->get('/admin/platform-orders?reconcile_mismatch=1'); + $page->assertOk(); + $page->assertSee('name="reconcile_mismatch"', false); + $page->assertSee('value="1"', false); + + $res = $this->post('/admin/platform-orders/clear-sync-errors', [ + 'scope' => 'filtered', + 'reconcile_mismatch' => '1', + ]); + $res->assertRedirect(); + + $order->refresh(); + $this->assertEmpty(data_get($order->meta, 'subscription_activation_error')); + } +}