平台订单摘要治理链接补齐 data-role 与 back 口径护栏

This commit is contained in:
萝卜
2026-03-18 18:29:22 +08:00
parent 04e823ec0a
commit e3bec58774
2 changed files with 82 additions and 4 deletions

View File

@@ -668,23 +668,23 @@
<div class="card">
<h3>BMPA 成功 / 失败</h3>
<div class="metric-number">
<a class="link" href="{!! $safeFullUrlWithQuery(['bmpa_success_only' => '1', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['bmpa_success_orders'] ?? 0 }}</a>
<a data-role="po-summary-link-bmpa-success-orders" class="link" href="{!! $safeFullUrlWithQuery(['bmpa_success_only' => '1', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['bmpa_success_orders'] ?? 0 }}</a>
<span class="muted"> / </span>
<a class="link" href="{!! $safeFullUrlWithQuery(['bmpa_failed_only' => '1', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['bmpa_failed_orders'] ?? 0 }}</a>
<a data-role="po-summary-link-bmpa-failed-orders" class="link" href="{!! $safeFullUrlWithQuery(['bmpa_failed_only' => '1', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['bmpa_failed_orders'] ?? 0 }}</a>
</div>
<div class="muted muted-xs">成功口径:存在 run_id 且无 error.message失败口径meta 失败标记</div>
</div>
<div class="card">
<h3>可同步订单</h3>
<div class="metric-number">
<a class="link" href="{!! $safeFullUrlWithQuery(['syncable_only' => '1', 'sync_status' => 'unsynced', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['syncable_orders'] ?? 0 }}</a>
<a data-role="po-summary-link-syncable-orders" class="link" href="{!! $safeFullUrlWithQuery(['syncable_only' => '1', 'sync_status' => 'unsynced', 'fail_only' => null, 'page' => null]) !!}">{{ $summaryStats['syncable_orders'] ?? 0 }}</a>
</div>
<div class="muted muted-xs">已支付 + 已生效 + 未同步(续费单需已绑定订阅)</div>
</div>
<div class="card">
<h3>续费缺订阅</h3>
<div class="metric-number">
<a class="link" href="{!! $safeFullUrlWithQuery(['renewal_missing_subscription' => '1', 'page' => null]) !!}">{{ $summaryStats['renewal_missing_subscription_orders'] ?? 0 }}</a>
<a data-role="po-summary-link-renewal-missing-sub-orders" class="link" href="{!! $safeFullUrlWithQuery(['renewal_missing_subscription' => '1', 'page' => null]) !!}">{{ $summaryStats['renewal_missing_subscription_orders'] ?? 0 }}</a>
</div>
<div class="muted muted-xs">renewal + site_subscription_id 为空(需治理:去订单详情补订阅/核对来源)</div>
</div>

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexSummaryGovernanceLinksShouldHaveDataRoleAndKeepBackTest 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_platform_orders_index_summary_governance_links_should_have_data_role_and_keep_back(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/platform-orders?merchant_id=1&back=/admin&page=2');
$res->assertOk();
$html = (string) $res->getContent();
$cases = [
[
'role' => 'po-summary-link-bmpa-success-orders',
'expect' => ['bmpa_success_only' => '1'],
'must_not_have' => ['page'],
],
[
'role' => 'po-summary-link-bmpa-failed-orders',
'expect' => ['bmpa_failed_only' => '1'],
'must_not_have' => ['page', 'fail_only'],
],
[
'role' => 'po-summary-link-syncable-orders',
'expect' => ['syncable_only' => '1', 'sync_status' => 'unsynced'],
'must_not_have' => ['page', 'fail_only'],
],
[
'role' => 'po-summary-link-renewal-missing-sub-orders',
'expect' => ['renewal_missing_subscription' => '1'],
'must_not_have' => ['page'],
],
];
foreach ($cases as $c) {
$role = (string) ($c['role'] ?? '');
$re = '/<a[^>]*data-role="' . preg_quote($role, '/') . '"[^>]*href="([^"]+)"/u';
$this->assertMatchesRegularExpression($re, $html);
preg_match($re, $html, $m);
$rawHref = (string) ($m[1] ?? '');
$this->assertStringNotContainsString('&amp;back=', $rawHref);
$href = html_entity_decode($rawHref);
$query = parse_url($href, PHP_URL_QUERY) ?: '';
parse_str($query, $q);
foreach (($c['expect'] ?? []) as $k => $v) {
$this->assertSame((string) $v, (string) ($q[$k] ?? ''), $role . ' missing expected ' . $k);
}
$this->assertSame('/admin', (string) ($q['back'] ?? ''));
foreach (($c['must_not_have'] ?? []) as $key) {
$this->assertArrayNotHasKey((string) $key, $q, $role . ' should clear ' . $key);
}
}
}
}