feat(batch): Top失败原因行支持一键按原因治理链接
This commit is contained in:
@@ -113,7 +113,9 @@ class PlatformBatchController extends Controller
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$topReason = (string) (data_get($summary, 'top_reasons.0.reason') ?? '');
|
||||
if ($topReason !== '') {
|
||||
$maxLen = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
|
||||
$maxLen = max(50, min(1000, $maxLen));
|
||||
if ($topReason !== '' && mb_strlen($topReason) <= $maxLen) {
|
||||
$governanceLinks['top_reason'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
'sync_status' => 'failed',
|
||||
@@ -139,7 +141,9 @@ class PlatformBatchController extends Controller
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$topReason = (string) (data_get($summary, 'top_reasons.0.reason') ?? '');
|
||||
if ($topReason !== '') {
|
||||
$maxLen = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
|
||||
$maxLen = max(50, min(1000, $maxLen));
|
||||
if ($topReason !== '' && mb_strlen($topReason) <= $maxLen) {
|
||||
$governanceLinks['top_reason'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
'bmpa_failed_only' => '1',
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
|
||||
$fallbackMatched = (int) (data_get($fallbackCounts, 'matched') ?? 0);
|
||||
$fallbackFailed = (int) (data_get($fallbackCounts, 'failed') ?? 0);
|
||||
|
||||
$SYNC_ERROR_KEYWORD_LINK_MAX_LEN = (int) config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200);
|
||||
$SYNC_ERROR_KEYWORD_LINK_MAX_LEN = max(50, min(1000, $SYNC_ERROR_KEYWORD_LINK_MAX_LEN));
|
||||
$SYNC_FAILED_REASON_TRUNCATE_LEN = (int) config('saasshop.platform_orders.sync_failed_reason_display_truncate_len', 60);
|
||||
$SYNC_FAILED_REASON_TRUNCATE_LEN = max(20, min(200, $SYNC_FAILED_REASON_TRUNCATE_LEN));
|
||||
@endphp
|
||||
|
||||
<div class="card mb-20">
|
||||
@@ -106,9 +111,43 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($topReasons as $r)
|
||||
@php
|
||||
$reason = (string) (data_get($r, 'reason') ?? '');
|
||||
$cnt = (int) (data_get($r, 'count') ?? 0);
|
||||
|
||||
$reasonTooLong = mb_strlen($reason) > $SYNC_ERROR_KEYWORD_LINK_MAX_LEN;
|
||||
$reasonDisplay = $reasonTooLong ? (mb_substr($reason, 0, $SYNC_FAILED_REASON_TRUNCATE_LEN) . '...') : $reason;
|
||||
|
||||
$reasonGovUrl = '';
|
||||
if (! $reasonTooLong && $reason !== '') {
|
||||
if ($type === 'bas') {
|
||||
$reasonGovUrl = \App\Support\BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
'sync_status' => 'failed',
|
||||
'sync_error_keyword' => $reason,
|
||||
]), $safeBackForLinks);
|
||||
}
|
||||
if ($type === 'bmpa') {
|
||||
$reasonGovUrl = \App\Support\BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
'bmpa_failed_only' => '1',
|
||||
'bmpa_error_keyword' => $reason,
|
||||
]), $safeBackForLinks);
|
||||
}
|
||||
}
|
||||
@endphp
|
||||
<tr>
|
||||
<td>{{ (string) (data_get($r, 'reason') ?? '-') }}</td>
|
||||
<td>{{ (int) (data_get($r, 'count') ?? 0) }}</td>
|
||||
<td>
|
||||
@if($reasonGovUrl !== '')
|
||||
<a class="link" data-role="batch-top-reason-link" href="{{ $reasonGovUrl }}" title="按该原因筛选">{{ $reasonDisplay }}</a>
|
||||
@else
|
||||
<span title="{{ $reason }}">{{ $reasonDisplay !== '' ? $reasonDisplay : '-' }}</span>
|
||||
@if($reasonTooLong)
|
||||
<div class="muted muted-xs text-danger">原因过长,请复制到列表页筛选框</div>
|
||||
@endif
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $cnt }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlatformOrder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPlatformBatchShowPageTopReasonsShouldRenderGovernanceLinksTest 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_show_page_should_render_top_reason_governance_links_for_bas_and_bmpa(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'plan_batch_show_top_reason_links_0001',
|
||||
'name' => '批次页 TopReason 链接渲染测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
// 1) BAS
|
||||
$basRunId = 'BAS_TOP_REASON_LINK_0001';
|
||||
$basReason = '模拟失败:订阅同步异常';
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_SHOW_TOP_REASON_BAS_0001',
|
||||
'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()->subMinutes(10),
|
||||
'paid_at' => now()->subMinutes(9),
|
||||
'activated_at' => now()->subMinutes(8),
|
||||
'meta' => [
|
||||
'batch_activation' => [
|
||||
'run_id' => $basRunId,
|
||||
'last_result' => [
|
||||
'run_id' => $basRunId,
|
||||
'success' => 3,
|
||||
'failed' => 1,
|
||||
'matched' => 10,
|
||||
'processed' => 4,
|
||||
'top_reasons' => [
|
||||
['reason' => $basReason, 'count' => 1],
|
||||
],
|
||||
'at' => now()->toDateTimeString(),
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$basHtml = $this->get('/admin/platform-batches/show?type=bas&run_id=' . $basRunId)
|
||||
->assertOk()
|
||||
->getContent();
|
||||
|
||||
$this->assertStringContainsString('data-role="batch-top-reason-link"', $basHtml);
|
||||
$this->assertStringContainsString('batch_activation_run_id=' . $basRunId, $basHtml);
|
||||
$this->assertStringContainsString('sync_status=failed', $basHtml);
|
||||
$this->assertStringContainsString('sync_error_keyword=', $basHtml);
|
||||
$this->assertStringContainsString(urlencode($basReason), $basHtml);
|
||||
|
||||
// 2) BMPA
|
||||
$bmpaRunId = 'BMPA_TOP_REASON_LINK_0001';
|
||||
$bmpaReason = '模拟失败:订单不是待处理+未支付';
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_SHOW_TOP_REASON_BMPA_0001',
|
||||
'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()->subMinutes(10),
|
||||
'paid_at' => now()->subMinutes(9),
|
||||
'activated_at' => now()->subMinutes(8),
|
||||
'meta' => [
|
||||
'batch_mark_paid_and_activate' => [
|
||||
'run_id' => $bmpaRunId,
|
||||
'last_result' => [
|
||||
'run_id' => $bmpaRunId,
|
||||
'success' => 2,
|
||||
'failed' => 2,
|
||||
'matched' => 10,
|
||||
'processed' => 4,
|
||||
'top_reasons' => [
|
||||
['reason' => $bmpaReason, 'count' => 2],
|
||||
],
|
||||
'at' => now()->toDateTimeString(),
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$bmpaHtml = $this->get('/admin/platform-batches/show?type=bmpa&run_id=' . $bmpaRunId)
|
||||
->assertOk()
|
||||
->getContent();
|
||||
|
||||
$this->assertStringContainsString('data-role="batch-top-reason-link"', $bmpaHtml);
|
||||
$this->assertStringContainsString('batch_bmpa_run_id=' . $bmpaRunId, $bmpaHtml);
|
||||
$this->assertStringContainsString('bmpa_failed_only=1', $bmpaHtml);
|
||||
$this->assertStringContainsString('bmpa_error_keyword=', $bmpaHtml);
|
||||
$this->assertStringContainsString(urlencode($bmpaReason), $bmpaHtml);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user