Platform batch show: add spot-check sample link to order anchors
This commit is contained in:
@@ -34,6 +34,7 @@ class PlatformBatchController extends Controller
|
|||||||
'summary' => null,
|
'summary' => null,
|
||||||
'fallbackCounts' => null,
|
'fallbackCounts' => null,
|
||||||
'governanceLinks' => [],
|
'governanceLinks' => [],
|
||||||
|
'spotCheck' => ['order_id' => 0, 'url' => '', 'label' => ''],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +171,51 @@ class PlatformBatchController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.platform_batches.show', [
|
|
||||||
|
|
||||||
|
// 抽样复核入口:从“成功集合”里取一单,方便运营 spot-check。
|
||||||
|
// - BAS:优先取已同步且无错误的订单
|
||||||
|
// - BMPA:优先取本批次标记支付成功且无错误的订单
|
||||||
|
$spotCheck = [
|
||||||
|
'order_id' => 0,
|
||||||
|
'url' => '',
|
||||||
|
'label' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
$selfWithoutBack = BackUrl::selfWithoutBack();
|
||||||
|
|
||||||
|
$sampleQuery = PlatformOrder::query();
|
||||||
|
$driver3 = $sampleQuery->getQuery()->getConnection()->getDriverName();
|
||||||
|
if ($driver3 === 'sqlite') {
|
||||||
|
$sampleQuery->whereRaw("JSON_EXTRACT(meta, '{$keyPrefix}.run_id') = ?", [$runId]);
|
||||||
|
} else {
|
||||||
|
$sampleQuery->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '{$keyPrefix}.run_id')) = ?", [$runId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type === 'bas') {
|
||||||
|
$sampleQuery->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NOT NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL");
|
||||||
|
|
||||||
|
$sampleOrder = $sampleQuery->orderByDesc('id')->first(['id']);
|
||||||
|
if ($sampleOrder) {
|
||||||
|
$spotCheck['order_id'] = (int) $sampleOrder->id;
|
||||||
|
$spotCheck['label'] = '抽样复核:查看订阅同步';
|
||||||
|
$spotCheck['url'] = BackUrl::withBackAndFragment('/admin/platform-orders/' . $sampleOrder->id, $selfWithoutBack, 'subscription-sync');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type === 'bmpa') {
|
||||||
|
$sampleQuery->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate.run_id') IS NOT NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NULL");
|
||||||
|
|
||||||
|
$sampleOrder = $sampleQuery->orderByDesc('id')->first(['id']);
|
||||||
|
if ($sampleOrder) {
|
||||||
|
$spotCheck['order_id'] = (int) $sampleOrder->id;
|
||||||
|
$spotCheck['label'] = '抽样复核:查看支付回执';
|
||||||
|
$spotCheck['url'] = BackUrl::withBackAndFragment('/admin/platform-orders/' . $sampleOrder->id, $selfWithoutBack, 'payment-receipts');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return view('admin.platform_batches.show', [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'runId' => $runId,
|
'runId' => $runId,
|
||||||
'safeBackForLinks' => $safeBackForLinks,
|
'safeBackForLinks' => $safeBackForLinks,
|
||||||
@@ -178,6 +223,7 @@ class PlatformBatchController extends Controller
|
|||||||
'summary' => $summary,
|
'summary' => $summary,
|
||||||
'fallbackCounts' => $fallbackCounts,
|
'fallbackCounts' => $fallbackCounts,
|
||||||
'governanceLinks' => $governanceLinks,
|
'governanceLinks' => $governanceLinks,
|
||||||
|
'spotCheck' => $spotCheck,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card mb-20">
|
<div class="card mb-20" data-role="platform-batch-spot-check">
|
||||||
|
<h3>抽样复核</h3>
|
||||||
|
@if(($spotCheck['url'] ?? '') !== '')
|
||||||
|
<div class="actions gap-10">
|
||||||
|
<a class="btn btn-secondary btn-sm" data-role="batch-spot-check-link" href="{!! $spotCheck['url'] !!}">{{ $spotCheck['label'] ?? '抽样复核' }}</a>
|
||||||
|
<span class="muted muted-xs">(从本批次成功集合抽一单,用于 spot-check)</span>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="muted">暂无可抽样订单(可能暂无成功单,或 last_result 尚未补齐)。</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card mb-20">
|
||||||
<h3>一键治理入口</h3>
|
<h3>一键治理入口</h3>
|
||||||
<div class="inline-links">
|
<div class="inline-links">
|
||||||
@if(($governanceLinks['all'] ?? '') !== '')
|
@if(($governanceLinks['all'] ?? '') !== '')
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?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 AdminPlatformBatchShowPageSpotCheckBlockShouldRenderTest 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_spot_check_block_with_link_when_has_success_sample_for_bmpa(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'plan_batch_spot_check_0001',
|
||||||
|
'name' => '批次页抽样复核渲染测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$runId = 'BMPA_SPOT_CHECK_0001';
|
||||||
|
|
||||||
|
$order = PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_BMPA_SPOT_CHECK_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' => $runId,
|
||||||
|
'last_result' => [
|
||||||
|
'run_id' => $runId,
|
||||||
|
'success' => 1,
|
||||||
|
'failed' => 0,
|
||||||
|
'matched' => 1,
|
||||||
|
'processed' => 1,
|
||||||
|
'top_reasons' => [],
|
||||||
|
'at' => now()->toDateTimeString(),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$html = $this->get('/admin/platform-batches/show?type=bmpa&run_id=' . $runId)
|
||||||
|
->assertOk()
|
||||||
|
->getContent();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('data-role="platform-batch-spot-check"', $html);
|
||||||
|
$this->assertStringContainsString('data-role="batch-spot-check-link"', $html);
|
||||||
|
$this->assertStringContainsString('/admin/platform-orders/' . $order->id, $html);
|
||||||
|
$this->assertStringContainsString('#payment-receipts', $html);
|
||||||
|
$this->assertStringContainsString('back=', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user