From 98418be91f0fc848d6327cdbb97767e134600f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 10 Mar 2026 12:59:18 +0000 Subject: [PATCH] feat(admin): batch activate from subscription show --- .../admin/site_subscriptions/show.blade.php | 16 +++ ...eSubscriptionBatchActivateFromShowTest.php | 118 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php diff --git a/resources/views/admin/site_subscriptions/show.blade.php b/resources/views/admin/site_subscriptions/show.blade.php index 2a7e9e8..4ce8d7e 100644 --- a/resources/views/admin/site_subscriptions/show.blade.php +++ b/resources/views/admin/site_subscriptions/show.blade.php @@ -75,6 +75,22 @@ 查看可同步订单 @endif + +
+
+ @csrf + + + + + +
+
说明:该按钮等价于平台订单页的“批量同步订阅(当前筛选范围)”,已内置只处理可同步订单(已支付+已生效+未同步)。
+
diff --git a/tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php b/tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php new file mode 100644 index 0000000..dd60c9d --- /dev/null +++ b/tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php @@ -0,0 +1,118 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_admin_can_batch_activate_syncable_orders_from_subscription_show_page(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'sub_show_batch_sync', + 'name' => '订阅详情页批量同步测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $sub = SiteSubscription::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'status' => 'activated', + 'source' => 'manual', + 'subscription_no' => 'SUB_BATCH_SHOW_0001', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'amount' => 10, + 'starts_at' => now()->subDay(), + 'ends_at' => now()->addMonth(), + 'activated_at' => now()->subDay(), + ]); + + // 订单A:可同步(已支付+已生效+未同步) + $o1 = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'site_subscription_id' => $sub->id, + 'created_by_admin_id' => 1, + 'order_no' => 'PO_SUB_BATCH_0001', + 'order_type' => 'renewal', + '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()->subMinutes(5), + 'paid_at' => now()->subMinutes(4), + 'activated_at' => now()->subMinutes(3), + ]); + + // 订单B:同订阅但不可同步(未支付) + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'site_subscription_id' => $sub->id, + 'created_by_admin_id' => 1, + 'order_no' => 'PO_SUB_BATCH_0002', + 'order_type' => 'renewal', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 0, + 'placed_at' => now()->subMinutes(2), + ]); + + $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'site_subscription_id' => (string) $sub->id, + 'syncable_only' => '1', + 'limit' => 50, + ])->assertRedirect(); + + $o1->refresh(); + $this->assertNotNull(data_get($o1->meta, 'subscription_activation.subscription_id')); + } + + public function test_guest_cannot_batch_activate_from_subscription_show_page(): void + { + $this->seed(); + + $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'limit' => 10, + ])->assertRedirect('/admin/login'); + } +}