admin: 增加批次详情页(BAS/BMPA)支持run_id复盘
This commit is contained in:
125
app/Http/Controllers/Admin/PlatformBatchController.php
Normal file
125
app/Http/Controllers/Admin/PlatformBatchController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Concerns\ResolvesPlatformAdminContext;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PlatformOrder;
|
||||
use App\Support\BackUrl;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PlatformBatchController extends Controller
|
||||
{
|
||||
use ResolvesPlatformAdminContext;
|
||||
|
||||
public function show(Request $request): View
|
||||
{
|
||||
$this->ensurePlatformAdmin($request);
|
||||
|
||||
$type = trim((string) $request->query('type', ''));
|
||||
$runId = trim((string) $request->query('run_id', ''));
|
||||
|
||||
$type = $type === 'bmpa' ? 'bmpa' : ($type === 'bas' ? 'bas' : '');
|
||||
|
||||
$incomingBack = (string) $request->query('back', '');
|
||||
$safeBackForLinks = BackUrl::sanitizeForLinks($incomingBack);
|
||||
|
||||
if ($type === '' || $runId === '') {
|
||||
return view('admin.platform_batches.show', [
|
||||
'type' => $type,
|
||||
'runId' => $runId,
|
||||
'safeBackForLinks' => $safeBackForLinks,
|
||||
'error' => '参数不完整:请提供 type(bas/bmpa)与 run_id。',
|
||||
'summary' => null,
|
||||
'governanceLinks' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
// 基于订单 meta 的扁平字段回捞 last_result(冗余写入策略下可行)
|
||||
// 注意:为避免全表扫描,这里先按 run_id 过滤再取最近一条。
|
||||
$keyPrefix = $type === 'bas' ? '$.batch_activation' : '$.batch_mark_paid_and_activate';
|
||||
|
||||
$query = PlatformOrder::query();
|
||||
$driver = $query->getQuery()->getConnection()->getDriverName();
|
||||
|
||||
if ($driver === 'sqlite') {
|
||||
$query->whereRaw("JSON_EXTRACT(meta, '{$keyPrefix}.run_id') = ?", [$runId]);
|
||||
} else {
|
||||
$query->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '{$keyPrefix}.run_id')) = ?", [$runId]);
|
||||
}
|
||||
|
||||
$order = $query->orderByDesc('id')->first(['id', 'meta']);
|
||||
|
||||
$summary = null;
|
||||
if ($order) {
|
||||
$summary = data_get($order->meta, $type === 'bas'
|
||||
? 'batch_activation.last_result'
|
||||
: 'batch_mark_paid_and_activate.last_result');
|
||||
}
|
||||
|
||||
// 治理入口:全部/失败/按Top原因/可重试
|
||||
$governanceLinks = [];
|
||||
|
||||
if ($type === 'bas') {
|
||||
$governanceLinks['all'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$governanceLinks['failed'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
'sync_status' => 'failed',
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$governanceLinks['retry_syncable'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
'sync_status' => 'unsynced',
|
||||
'syncable_only' => '1',
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$topReason = (string) (data_get($summary, 'top_reasons.0.reason') ?? '');
|
||||
if ($topReason !== '') {
|
||||
$governanceLinks['top_reason'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_activation_run_id' => $runId,
|
||||
'sync_status' => 'failed',
|
||||
'sync_error_keyword' => $topReason,
|
||||
]), $safeBackForLinks);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === 'bmpa') {
|
||||
$governanceLinks['all'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$governanceLinks['failed'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
'bmpa_failed_only' => '1',
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$governanceLinks['retry_processable'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'unpaid',
|
||||
]), $safeBackForLinks);
|
||||
|
||||
$topReason = (string) (data_get($summary, 'top_reasons.0.reason') ?? '');
|
||||
if ($topReason !== '') {
|
||||
$governanceLinks['top_reason'] = BackUrl::withBack('/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'batch_bmpa_run_id' => $runId,
|
||||
'bmpa_failed_only' => '1',
|
||||
'bmpa_error_keyword' => $topReason,
|
||||
]), $safeBackForLinks);
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin.platform_batches.show', [
|
||||
'type' => $type,
|
||||
'runId' => $runId,
|
||||
'safeBackForLinks' => $safeBackForLinks,
|
||||
'error' => '',
|
||||
'summary' => $summary,
|
||||
'governanceLinks' => $governanceLinks,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user