Platform orders: batch sync respects lead_id filter

This commit is contained in:
萝卜
2026-03-14 05:33:42 +00:00
parent f28025dd73
commit 893b4c85ce
3 changed files with 122 additions and 0 deletions

View File

@@ -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', ''),

View File

@@ -595,6 +595,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -627,6 +628,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -661,6 +663,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -697,6 +700,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -747,6 +751,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -797,6 +802,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
@@ -836,6 +842,7 @@
<input type="hidden" name="batch_mark_paid_and_activate_24h" value="{{ $filters['batch_mark_paid_and_activate_24h'] ?? '' }}">
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="lead_id" value="{{ $filters['lead_id'] ?? '' }}">
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">

View File

@@ -0,0 +1,114 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformLead;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderBatchActivateSubscriptionsLeadIdFilterFieldsTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->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'));
}
}