From 10fa9a239d8b4e66f605e4c417b85cc46f3e276e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 04:40:47 +0000 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=90=8C=E6=AD=A5=E8=AE=A2?= =?UTF-8?q?=E9=98=85=EF=BC=9Arefund=5Finconsistent=20=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E5=8F=A3=E5=BE=84=E6=B5=8B=E8=AF=95=E6=8A=A4=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ionsRefundInconsistentFilterFieldsTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFieldsTest.php diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFieldsTest.php new file mode 100644 index 0000000..4ff1abb --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFieldsTest.php @@ -0,0 +1,103 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_subscriptions_filtered_scope_respects_refund_inconsistent_filter(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_activate_subscriptions_refund_inconsistent_plan', + 'name' => '批量同步订阅(退款不一致口径)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // A:退款不一致(状态!=refunded,但退款总额已达/超已付),且可同步 + $a = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_REFUND_INCONS_A', + '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' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 10.00, + ], + ], + ]); + + // B:退款一致(无退款),也可同步,但应被 refund_inconsistent=1 排除 + $b = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_REFUND_INCONS_B', + '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' => [], + ]); + + // 批量同步订阅:filtered scope 必须带 syncable_only=1;并附加 refund_inconsistent=1 + $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'refund_inconsistent' => '1', + 'limit' => 50, + ])->assertRedirect(); + + $a->refresh(); + $b->refresh(); + + // A 应被同步(meta.subscription_activation.subscription_id 存在) + $this->assertNotNull(data_get($a->meta, 'subscription_activation.subscription_id')); + + // B 不应被同步 + $this->assertNull(data_get($b->meta, 'subscription_activation.subscription_id')); + } +}