167 lines
5.2 KiB
PHP
167 lines
5.2 KiB
PHP
<?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 Illuminate\Support\Arr;
|
|
use Tests\TestCase;
|
|
|
|
class AdminPlatformOrderShowLeadContextLinkTest 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_show_should_render_lead_context_badge_and_view_link(): void
|
|
{
|
|
$this->loginAsPlatformAdmin();
|
|
|
|
$merchant = Merchant::query()->firstOrFail();
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'order_show_lead_plan',
|
|
'name' => '订单详情线索提示测试套餐',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$lead = PlatformLead::query()->create([
|
|
'name' => '订单详情线索',
|
|
'mobile' => '',
|
|
'email' => '',
|
|
'company' => '',
|
|
'source' => 'test',
|
|
'status' => 'new',
|
|
'plan_id' => $plan->id,
|
|
'meta' => ['from' => 'test'],
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'site_subscription_id' => null,
|
|
'created_by_admin_id' => 1,
|
|
'order_no' => 'PO_SHOW_LEAD_0001',
|
|
'order_type' => 'new_purchase',
|
|
'status' => 'pending',
|
|
'payment_status' => 'unpaid',
|
|
'payment_channel' => null,
|
|
'plan_name' => $plan->name,
|
|
'billing_cycle' => $plan->billing_cycle,
|
|
'period_months' => 1,
|
|
'quantity' => 1,
|
|
'list_amount' => 10,
|
|
'discount_amount' => 0,
|
|
'payable_amount' => 10,
|
|
'paid_amount' => 0,
|
|
'placed_at' => now(),
|
|
'plan_snapshot' => ['plan_id' => $plan->id],
|
|
'meta' => ['platform_lead_id' => $lead->id],
|
|
'remark' => 'from lead',
|
|
]);
|
|
|
|
$res = $this->get('/admin/platform-orders/' . $order->id);
|
|
$res->assertOk();
|
|
|
|
$res->assertSee('来源线索:#' . $lead->id, false);
|
|
|
|
$expectedLeadUrl = '/admin/platform-leads?' . Arr::query([
|
|
'lead_id' => $lead->id,
|
|
'back' => '/admin/platform-orders/' . $order->id,
|
|
]);
|
|
|
|
$res->assertSee('href="' . $expectedLeadUrl . '"', false);
|
|
$res->assertSee('查看线索', false);
|
|
}
|
|
|
|
public function test_show_should_prefer_order_lead_context_over_lead_hint_from_back(): void
|
|
{
|
|
$this->loginAsPlatformAdmin();
|
|
|
|
$merchant = Merchant::query()->firstOrFail();
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'order_show_lead_priority_plan',
|
|
'name' => '订单详情线索优先级测试套餐',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$lead = PlatformLead::query()->create([
|
|
'name' => '订单详情真实线索',
|
|
'mobile' => '',
|
|
'email' => '',
|
|
'company' => '',
|
|
'source' => 'test',
|
|
'status' => 'new',
|
|
'plan_id' => $plan->id,
|
|
'meta' => ['from' => 'test'],
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'site_subscription_id' => null,
|
|
'created_by_admin_id' => 1,
|
|
'order_no' => 'PO_SHOW_LEAD_0002',
|
|
'order_type' => 'new_purchase',
|
|
'status' => 'pending',
|
|
'payment_status' => 'unpaid',
|
|
'payment_channel' => null,
|
|
'plan_name' => $plan->name,
|
|
'billing_cycle' => $plan->billing_cycle,
|
|
'period_months' => 1,
|
|
'quantity' => 1,
|
|
'list_amount' => 10,
|
|
'discount_amount' => 0,
|
|
'payable_amount' => 10,
|
|
'paid_amount' => 0,
|
|
'placed_at' => now(),
|
|
'plan_snapshot' => ['plan_id' => $plan->id],
|
|
'meta' => ['platform_lead_id' => $lead->id],
|
|
'remark' => 'from lead',
|
|
]);
|
|
|
|
$back = '/admin/platform-orders?' . Arr::query([
|
|
'lead_id' => 999,
|
|
'status' => 'pending',
|
|
]);
|
|
|
|
$res = $this->get('/admin/platform-orders/' . $order->id . '?' . Arr::query([
|
|
'back' => $back,
|
|
]));
|
|
|
|
$res->assertOk();
|
|
$res->assertSee('来源线索:#' . $lead->id, false);
|
|
$res->assertDontSee('来源线索:#999', false);
|
|
|
|
$expectedLeadUrl = '/admin/platform-leads?' . Arr::query([
|
|
'lead_id' => $lead->id,
|
|
'back' => '/admin/platform-orders/' . $order->id,
|
|
]);
|
|
|
|
$res->assertSee('href="' . $expectedLeadUrl . '"', false);
|
|
$res->assertSee('查看线索', false);
|
|
}
|
|
}
|