Platform orders: batch actions include lead_id filter

This commit is contained in:
萝卜
2026-03-14 05:43:55 +00:00
parent 893b4c85ce
commit 8cf28184bd
2 changed files with 119 additions and 0 deletions

View File

@@ -1383,6 +1383,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', ''),
@@ -1587,6 +1588,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', ''),
@@ -1712,6 +1714,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', ''),
@@ -1791,6 +1794,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

@@ -0,0 +1,115 @@
<?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 AdminPlatformOrderBatchMarkPaidAndActivateLeadIdFilterFieldsTest 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_mark_paid_and_activate_filtered_scope_respects_lead_id_filter(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'batch_mark_paid_and_activate_lead_filter_plan',
'name' => '批量BMPA线索筛选测试套餐',
'billing_cycle' => 'monthly',
'price' => 30,
'list_price' => 30,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$leadA = PlatformLead::query()->create([
'name' => 'Lead A',
'mobile' => '13800000011',
'company' => 'A Inc',
'status' => 'new',
]);
$leadB = PlatformLead::query()->create([
'name' => 'Lead B',
'mobile' => '13800000012',
'company' => 'B Inc',
'status' => 'new',
]);
// A待处理+未支付 + 归属 leadA应被推进
$a = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BMPA_LEAD_A',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 30,
'paid_amount' => 0,
'placed_at' => now()->subMinutes(10),
'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_BMPA_LEAD_B',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 30,
'paid_amount' => 0,
'placed_at' => now()->subMinutes(9),
'meta' => [
'platform_lead_id' => $leadB->id,
],
]);
$this->post('/admin/platform-orders/batch-mark-paid-and-activate', [
'scope' => 'filtered',
'status' => 'pending',
'payment_status' => 'unpaid',
'lead_id' => (string) $leadA->id,
'limit' => 50,
])->assertRedirect();
$a->refresh();
$b->refresh();
$this->assertSame('paid', $a->payment_status);
$this->assertSame('activated', $a->status);
$this->assertNotNull(data_get($a->meta, 'subscription_activation.subscription_id'));
$this->assertSame('unpaid', $b->payment_status);
$this->assertSame('pending', $b->status);
$this->assertNull(data_get($b->meta, 'subscription_activation.subscription_id'));
}
}