From 893b4c85ce10a87e8873bfc0c0c511e550be8bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 05:33:42 +0000 Subject: [PATCH] Platform orders: batch sync respects lead_id filter --- .../Admin/PlatformOrderController.php | 1 + .../admin/platform_orders/index.blade.php | 7 ++ ...ateSubscriptionsLeadIdFilterFieldsTest.php | 114 ++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsLeadIdFilterFieldsTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index ec067c3..47a35c4 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1219,6 +1219,7 @@ class PlatformOrderController extends Controller 'synced_only' => (string) $request->input('synced_only', ''), 'sync_status' => trim((string) $request->input('sync_status', '')), 'keyword' => trim((string) $request->input('keyword', '')), + 'lead_id' => trim((string) $request->input('lead_id', '')), 'sync_error_keyword' => trim((string) $request->input('sync_error_keyword', '')), 'bmpa_error_keyword' => trim((string) $request->input('bmpa_error_keyword', '')), 'syncable_only' => (string) $request->input('syncable_only', ''), diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 7ed37d2..188dfe7 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -595,6 +595,7 @@ + @@ -627,6 +628,7 @@ + @@ -661,6 +663,7 @@ + @@ -697,6 +700,7 @@ + @@ -747,6 +751,7 @@ + @@ -797,6 +802,7 @@ + @@ -836,6 +842,7 @@ + diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsLeadIdFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsLeadIdFilterFieldsTest.php new file mode 100644 index 0000000..16d80f2 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsLeadIdFilterFieldsTest.php @@ -0,0 +1,114 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_subscriptions_filtered_scope_respects_lead_id_filter(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_activate_subscriptions_lead_filter_plan', + 'name' => '批量同步订阅(线索筛选)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $leadA = PlatformLead::query()->create([ + 'name' => 'Lead A', + 'mobile' => '13800000001', + 'company' => 'A Inc', + 'status' => 'new', + ]); + + $leadB = PlatformLead::query()->create([ + 'name' => 'Lead B', + 'mobile' => '13800000002', + 'company' => 'B Inc', + 'status' => 'new', + ]); + + // A:可同步 + 归属 leadA + $a = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_LEAD_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' => [ + 'platform_lead_id' => $leadA->id, + ], + ]); + + // B:可同步 + 归属 leadB(应被 lead_id 过滤排除) + $b = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_LEAD_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' => [ + 'platform_lead_id' => $leadB->id, + ], + ]); + + // filtered scope:同步“可同步订单”,并附加 lead_id=leadA + $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'lead_id' => (string) $leadA->id, + 'limit' => 50, + ])->assertRedirect(); + + $a->refresh(); + $b->refresh(); + + $this->assertNotNull(data_get($a->meta, 'subscription_activation.subscription_id')); + $this->assertNull(data_get($b->meta, 'subscription_activation.subscription_id')); + } +}