chore(admin-ui): migrate product import histories to filters/list card and admin pagination
This commit is contained in:
@@ -4,106 +4,128 @@
|
|||||||
@section('page_title', '平台商品导入历史')
|
@section('page_title', '平台商品导入历史')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="card">
|
@php
|
||||||
<p class="muted muted-tight">这里集中查看平台视角的商品导入历史,适合运营侧复盘批量导入结果、失败明细与清理后文件状态。</p>
|
$exportHistoryQuery = http_build_query(array_filter([
|
||||||
|
'merchant_id' => $importHistoryFilters['merchant_id'] ?? '',
|
||||||
|
'import_result_status' => $importHistoryFilters['result_status'] ?? 'all',
|
||||||
|
'import_time_range' => $importHistoryFilters['time_range'] ?? 'all',
|
||||||
|
'start_date' => $importHistoryFilters['start_date'] ?? '',
|
||||||
|
'end_date' => $importHistoryFilters['end_date'] ?? '',
|
||||||
|
'import_sort' => $importHistoryFilters['sort'] ?? 'latest',
|
||||||
|
], fn ($value, $key) => match ($key) {
|
||||||
|
'start_date', 'end_date' => $value !== null && $value !== '',
|
||||||
|
default => $value !== null && $value !== '' && $value !== 'all' && $value !== 'latest',
|
||||||
|
}, ARRAY_FILTER_USE_BOTH));
|
||||||
|
@endphp
|
||||||
|
|
||||||
@php
|
<details class="card mb-20 collapsible filters-card" data-role="collapsible" data-storage-key="admin.products.import_histories.filters" open>
|
||||||
$exportHistoryQuery = http_build_query(array_filter([
|
<summary class="collapsible-summary filters-summary">
|
||||||
'merchant_id' => $importHistoryFilters['merchant_id'] ?? '',
|
<div class="flex-between items-center">
|
||||||
'import_result_status' => $importHistoryFilters['result_status'] ?? 'all',
|
<div>
|
||||||
'import_time_range' => $importHistoryFilters['time_range'] ?? 'all',
|
<h3 class="mb-0">平台商品导入历史</h3>
|
||||||
'start_date' => $importHistoryFilters['start_date'] ?? '',
|
<div class="muted muted-xs">集中复盘平台视角的商品导入结果、失败明细与文件状态(面向运营)。</div>
|
||||||
'end_date' => $importHistoryFilters['end_date'] ?? '',
|
</div>
|
||||||
'import_sort' => $importHistoryFilters['sort'] ?? 'latest',
|
<span class="muted muted-xs">点击收起/展开</span>
|
||||||
], fn ($value, $key) => match ($key) {
|
|
||||||
'start_date', 'end_date' => $value !== null && $value !== '',
|
|
||||||
default => $value !== null && $value !== '' && $value !== 'all' && $value !== 'latest',
|
|
||||||
}, ARRAY_FILTER_USE_BOTH));
|
|
||||||
@endphp
|
|
||||||
<form method="get" action="/admin/products/import-histories" class="mb-12">
|
|
||||||
<div class="actions gap-10">
|
|
||||||
<select name="merchant_id">
|
|
||||||
<option value="">全部商家</option>
|
|
||||||
@foreach(($historyMerchants ?? collect()) as $merchant)
|
|
||||||
<option value="{{ $merchant->id }}" @selected(($importHistoryFilters['merchant_id'] ?? '') === (string) $merchant->id)>{{ $merchant->id }} / {{ $merchant->name }}</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
<select name="import_result_status">
|
|
||||||
<option value="all" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'all')>全部导入结果</option>
|
|
||||||
<option value="success_only" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'success_only')>仅看成功导入</option>
|
|
||||||
<option value="has_failures" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'has_failures')>仅看含失败导入</option>
|
|
||||||
</select>
|
|
||||||
<select name="import_time_range">
|
|
||||||
<option value="all" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'all')>全部时间</option>
|
|
||||||
<option value="today" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'today')>今天</option>
|
|
||||||
<option value="last_7_days" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'last_7_days')>近7天</option>
|
|
||||||
<option value="custom" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'custom')>自定义区间</option>
|
|
||||||
</select>
|
|
||||||
<input type="date" name="start_date" value="{{ $importHistoryFilters['start_date'] ?? '' }}">
|
|
||||||
<span class="muted">至</span>
|
|
||||||
<input type="date" name="end_date" value="{{ $importHistoryFilters['end_date'] ?? '' }}">
|
|
||||||
<select name="import_sort">
|
|
||||||
@foreach(($importHistoryFilterOptions['sorts'] ?? []) as $sortValue => $sortLabel)
|
|
||||||
<option value="{{ $sortValue }}" @selected(($importHistoryFilters['sort'] ?? 'latest') === $sortValue)>{{ $sortLabel }}</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
<button type="submit" class="btn btn-sm">筛选导入历史</button>
|
|
||||||
<a href="{{ '/admin/products/import-histories/export' . ($exportHistoryQuery ? ('?' . $exportHistoryQuery) : '') }}" class="btn btn-secondary btn-sm">导出当前筛选 CSV</a>
|
|
||||||
<a href="/admin/products/import-histories" class="btn btn-secondary btn-sm">清空筛选</a>
|
|
||||||
<a href="/admin/products" class="btn btn-secondary btn-sm">返回商品页</a>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</summary>
|
||||||
|
|
||||||
@if(!empty($importHistoryFilters['date_errors']))
|
<div class="collapsible-body filters-body">
|
||||||
<div class="info-warning">
|
<form method="get" action="/admin/products/import-histories" class="filters-grid">
|
||||||
@foreach($importHistoryFilters['date_errors'] as $dateError)
|
<div class="actions gap-10">
|
||||||
<div>{{ $dateError }}</div>
|
<select name="merchant_id">
|
||||||
@endforeach
|
<option value="">全部商家</option>
|
||||||
</div>
|
@foreach(($historyMerchants ?? collect()) as $merchant)
|
||||||
@endif
|
<option value="{{ $merchant->id }}" @selected(($importHistoryFilters['merchant_id'] ?? '') === (string) $merchant->id)>{{ $merchant->id }} / {{ $merchant->name }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
<select name="import_result_status">
|
||||||
|
<option value="all" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'all')>全部导入结果</option>
|
||||||
|
<option value="success_only" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'success_only')>仅看成功导入</option>
|
||||||
|
<option value="has_failures" @selected(($importHistoryFilters['result_status'] ?? 'all') === 'has_failures')>仅看含失败导入</option>
|
||||||
|
</select>
|
||||||
|
<select name="import_time_range">
|
||||||
|
<option value="all" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'all')>全部时间</option>
|
||||||
|
<option value="today" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'today')>今天</option>
|
||||||
|
<option value="last_7_days" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'last_7_days')>近7天</option>
|
||||||
|
<option value="custom" @selected(($importHistoryFilters['time_range'] ?? 'all') === 'custom')>自定义区间</option>
|
||||||
|
</select>
|
||||||
|
<input type="date" name="start_date" value="{{ $importHistoryFilters['start_date'] ?? '' }}">
|
||||||
|
<span class="muted">至</span>
|
||||||
|
<input type="date" name="end_date" value="{{ $importHistoryFilters['end_date'] ?? '' }}">
|
||||||
|
<select name="import_sort">
|
||||||
|
@foreach(($importHistoryFilterOptions['sorts'] ?? []) as $sortValue => $sortLabel)
|
||||||
|
<option value="{{ $sortValue }}" @selected(($importHistoryFilters['sort'] ?? 'latest') === $sortValue)>{{ $sortLabel }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="btn btn-sm">筛选导入历史</button>
|
||||||
|
<a href="{{ '/admin/products/import-histories/export' . ($exportHistoryQuery ? ('?' . $exportHistoryQuery) : '') }}" class="btn btn-secondary btn-sm">导出当前筛选 CSV</a>
|
||||||
|
<a href="/admin/products/import-histories" class="btn btn-secondary btn-sm">清空筛选</a>
|
||||||
|
<a href="/admin/products" class="btn btn-secondary btn-sm">返回商品页</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div class="grid-4 mb-12">
|
@if(!empty($importHistoryFilters['date_errors']))
|
||||||
|
<div class="info-warning mt-12">
|
||||||
|
@foreach($importHistoryFilters['date_errors'] as $dateError)
|
||||||
|
<div>{{ $dateError }}</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<div class="card mb-20">
|
||||||
|
<div class="grid-4">
|
||||||
<div class="stat-box"><div class="muted">累计导入批次</div><strong class="num-sm">{{ $importHistoryStats['total_imports'] ?? 0 }}</strong></div>
|
<div class="stat-box"><div class="muted">累计导入批次</div><strong class="num-sm">{{ $importHistoryStats['total_imports'] ?? 0 }}</strong></div>
|
||||||
<div class="stat-box"><div class="muted">累计成功商品</div><strong class="num-sm">{{ $importHistoryStats['total_success'] ?? 0 }}</strong></div>
|
<div class="stat-box"><div class="muted">累计成功商品</div><strong class="num-sm">{{ $importHistoryStats['total_success'] ?? 0 }}</strong></div>
|
||||||
<div class="stat-box"><div class="muted">累计失败商品</div><strong class="num-sm">{{ $importHistoryStats['total_failed'] ?? 0 }}</strong></div>
|
<div class="stat-box"><div class="muted">累计失败商品</div><strong class="num-sm">{{ $importHistoryStats['total_failed'] ?? 0 }}</strong></div>
|
||||||
<div class="stat-box"><div class="muted">含失败批次</div><strong class="num-sm">{{ $importHistoryStats['warning_imports'] ?? 0 }}</strong></div>
|
<div class="stat-box"><div class="muted">含失败批次</div><strong class="num-sm">{{ $importHistoryStats['warning_imports'] ?? 0 }}</strong></div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table>
|
<div class="card list-card">
|
||||||
<thead><tr><th>ID</th><th>导入时间</th><th>商家</th><th>上传文件</th><th>结果</th><th>成功</th><th>失败</th><th>操作者</th><th>失败明细</th></tr></thead>
|
<div class="list-card-header">
|
||||||
<tbody>
|
<div>
|
||||||
@forelse($importHistories as $history)
|
<h3 class="list-card-title">导入记录</h3>
|
||||||
<tr>
|
</div>
|
||||||
<td>{{ $history->id }}</td>
|
</div>
|
||||||
<td>{{ $history->imported_at?->format('Y-m-d H:i:s') }}</td>
|
<div class="list-card-body">
|
||||||
<td>{{ $history->merchant?->name ?? '平台批量导入' }}</td>
|
<table class="list-card-table">
|
||||||
<td>{{ $history->file_name }}</td>
|
<thead><tr><th>ID</th><th>导入时间</th><th>商家</th><th>上传文件</th><th>结果</th><th>成功</th><th>失败</th><th>操作者</th><th>失败明细</th></tr></thead>
|
||||||
<td>
|
<tbody>
|
||||||
@if(($history->failed_count ?? 0) > 0)
|
@forelse($importHistories as $history)
|
||||||
<span class="result-warning">部分失败</span>
|
<tr>
|
||||||
@else
|
<td>{{ $history->id }}</td>
|
||||||
<span class="result-success">成功</span>
|
<td>{{ $history->imported_at?->format('Y-m-d H:i:s') }}</td>
|
||||||
@endif
|
<td>{{ $history->merchant?->name ?? '平台批量导入' }}</td>
|
||||||
</td>
|
<td>{{ $history->file_name }}</td>
|
||||||
<td>{{ $history->success_count }}</td>
|
<td>
|
||||||
<td>{{ $history->failed_count }}</td>
|
@if(($history->failed_count ?? 0) > 0)
|
||||||
<td>{{ $history->admin?->name ?? '-' }}</td>
|
<span class="result-warning">部分失败</span>
|
||||||
<td>
|
@else
|
||||||
@if($history->failure_file && ($history->failure_file_available ?? false))
|
<span class="result-success">成功</span>
|
||||||
<a href="/admin/products/import-failures/{{ $history->failure_file }}" class="btn btn-secondary btn-sm">下载 failure CSV</a>
|
@endif
|
||||||
@elseif($history->failure_file)
|
</td>
|
||||||
<span class="muted">文件已过保留期</span>
|
<td>{{ $history->success_count }}</td>
|
||||||
@else
|
<td>{{ $history->failed_count }}</td>
|
||||||
<span class="muted">无</span>
|
<td>{{ $history->admin?->name ?? '-' }}</td>
|
||||||
@endif
|
<td>
|
||||||
</td>
|
@if($history->failure_file && ($history->failure_file_available ?? false))
|
||||||
</tr>
|
<a href="/admin/products/import-failures/{{ $history->failure_file }}" class="btn btn-secondary btn-sm">下载 failure CSV</a>
|
||||||
@empty
|
@elseif($history->failure_file)
|
||||||
<tr><td colspan="9" class="muted">暂无导入记录</td></tr>
|
<span class="muted">文件已过保留期</span>
|
||||||
@endforelse
|
@else
|
||||||
</tbody>
|
<span class="muted">无</span>
|
||||||
</table>
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr><td colspan="9" class="muted table-empty">暂无导入记录</td></tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
<div class="pagination-wrap">{{ $importHistories->links() }}</div>
|
{{ $importHistories->links('pagination.admin') }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminProductImportHistoriesIndexShouldUseFiltersAndListCardStructureTest 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_admin_product_import_histories_index_should_use_filters_and_list_card_structure(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$res = $this->get('/admin/products/import-histories');
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
// 护栏:导入历史页应使用统一 Filters Card + List Card 结构。
|
||||||
|
$res->assertSee('filters-card', false);
|
||||||
|
$res->assertSee('filters-summary', false);
|
||||||
|
$res->assertSee('filters-body', false);
|
||||||
|
$res->assertSee('filters-grid', false);
|
||||||
|
|
||||||
|
$res->assertSee('list-card', false);
|
||||||
|
$res->assertSee('list-card-header', false);
|
||||||
|
$res->assertSee('list-card-body', false);
|
||||||
|
$res->assertSee('list-card-table', false);
|
||||||
|
|
||||||
|
// 分页统一:用扫描型护栏断言。
|
||||||
|
$blade = file_get_contents(resource_path('views/admin/products/import_histories.blade.php'));
|
||||||
|
$this->assertIsString($blade);
|
||||||
|
$this->assertStringContainsString("links('pagination.admin')", $blade);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user