parent
a46d4dc678
commit
4c3ef7b41d
@ -724,28 +724,139 @@ class Pages extends Controller
|
||||
$error = '汇总数据暂时无法读取,请重新导入后再试。';
|
||||
}
|
||||
|
||||
$headers = $snapshot['headers'] ?? [];
|
||||
$allRows = collect($snapshot['rows'] ?? []);
|
||||
$currentPage = max((int) request()->query('page', 1), 1);
|
||||
$filters = $this->courierSummaryFilters();
|
||||
$filteredRows = $this->filterCourierSummaryRows($allRows, $headers, $filters);
|
||||
$perPage = 50;
|
||||
$lastPage = max((int) ceil($filteredRows->count() / $perPage), 1);
|
||||
$currentPage = min(max((int) request()->query('page', 1), 1), $lastPage);
|
||||
|
||||
return [
|
||||
'view' => 'business.pages.courier-payables.summary-table',
|
||||
'courierSummaryPage' => $page,
|
||||
'courierSummaryTitle' => $store->title($page),
|
||||
'courierSummaryHeaders' => $snapshot['headers'] ?? [],
|
||||
'courierSummaryHeaders' => $headers,
|
||||
'courierSummaryRows' => new LengthAwarePaginator(
|
||||
$allRows->forPage($currentPage, $perPage)->values(),
|
||||
$allRows->count(),
|
||||
$filteredRows->forPage($currentPage, $perPage)->values(),
|
||||
$filteredRows->count(),
|
||||
$perPage,
|
||||
$currentPage,
|
||||
['path' => request()->url(), 'query' => request()->except('page')],
|
||||
['path' => request()->url(), 'query' => array_filter(
|
||||
$filters,
|
||||
static fn (string $value): bool => $value !== '',
|
||||
)],
|
||||
),
|
||||
'courierSummaryFilters' => $filters,
|
||||
'courierSummaryHasFilters' => collect($filters)->contains(
|
||||
static fn (string $value): bool => $value !== '',
|
||||
),
|
||||
'courierSummarySourceTotal' => $allRows->count(),
|
||||
'courierSummarySourceName' => $snapshot['source_name'] ?? null,
|
||||
'courierSummaryImportedAt' => $snapshot['imported_at'] ?? null,
|
||||
'courierSummaryError' => $error,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{date:string,person:string,courier:string,keyword:string} */
|
||||
private function courierSummaryFilters(): array
|
||||
{
|
||||
$clean = static function (string $key, int $maxLength): string {
|
||||
$value = request()->query($key, '');
|
||||
|
||||
if (! is_scalar($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return mb_substr(trim((string) $value), 0, $maxLength);
|
||||
};
|
||||
|
||||
return [
|
||||
'date' => $clean('date', 50),
|
||||
'person' => $clean('person', 100),
|
||||
'courier' => $clean('courier', 100),
|
||||
'keyword' => $clean('keyword', 191),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, mixed> $rows
|
||||
* @param list<string> $headers
|
||||
* @param array{date:string,person:string,courier:string,keyword:string} $filters
|
||||
* @return Collection<int, mixed>
|
||||
*/
|
||||
private function filterCourierSummaryRows(Collection $rows, array $headers, array $filters): Collection
|
||||
{
|
||||
if (! collect($filters)->contains(static fn (string $value): bool => $value !== '')) {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$dateColumn = $this->courierSummaryColumnIndex($headers, ['日期', '结算月份', '结算月', '月份']);
|
||||
$personColumn = $this->courierSummaryColumnIndex($headers, ['负责人', '责任人']);
|
||||
$courierColumn = $this->courierSummaryColumnIndex($headers, ['快递公司', '快递名称', '快递名', '快递']);
|
||||
|
||||
return $rows->filter(function (mixed $row) use ($filters, $dateColumn, $personColumn, $courierColumn): bool {
|
||||
if (! is_array($row)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->courierSummaryColumnMatches($row, $dateColumn, $filters['date'])
|
||||
|| ! $this->courierSummaryColumnMatches($row, $personColumn, $filters['person'])
|
||||
|| ! $this->courierSummaryColumnMatches($row, $courierColumn, $filters['courier'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($filters['keyword'] === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($row as $value) {
|
||||
if ($this->courierSummaryContains($value, $filters['keyword'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/** @param list<string> $headers */
|
||||
private function courierSummaryColumnIndex(array $headers, array $aliases): ?int
|
||||
{
|
||||
$normalizedAliases = array_map(
|
||||
static fn (string $alias): string => mb_strtolower(preg_replace('/[\\s ]+/u', '', $alias) ?? $alias),
|
||||
$aliases,
|
||||
);
|
||||
|
||||
foreach ($headers as $index => $header) {
|
||||
$normalizedHeader = mb_strtolower(preg_replace('/[\\s ]+/u', '', trim((string) $header)) ?? trim((string) $header));
|
||||
|
||||
if (in_array($normalizedHeader, $normalizedAliases, true)) {
|
||||
return (int) $index;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function courierSummaryColumnMatches(array $row, ?int $column, string $needle): bool
|
||||
{
|
||||
if ($needle === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $column !== null && $this->courierSummaryContains($row[$column] ?? '', $needle);
|
||||
}
|
||||
|
||||
private function courierSummaryContains(mixed $value, string $needle): bool
|
||||
{
|
||||
if (! is_scalar($value) && ! $value instanceof \Stringable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mb_stripos((string) $value, $needle, 0, 'UTF-8') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consolidated, non-destructive view of the withdrawal configuration kept
|
||||
* with each store receiving account. Updates remain in the source page so
|
||||
|
||||
@ -23,7 +23,14 @@
|
||||
<div class="courier-summary__heading">
|
||||
<strong>{{ $courierSummaryTitle }}</strong>
|
||||
@if ($courierSummarySourceName)
|
||||
<span>{{ $courierSummarySourceName }} · 共 {{ number_format($courierSummaryRows->total()) }} 条</span>
|
||||
<span>
|
||||
{{ $courierSummarySourceName }} ·
|
||||
@if ($courierSummaryHasFilters)
|
||||
查询到 {{ number_format($courierSummaryRows->total()) }} 条 / 共 {{ number_format($courierSummarySourceTotal) }} 条
|
||||
@else
|
||||
共 {{ number_format($courierSummarySourceTotal) }} 条
|
||||
@endif
|
||||
</span>
|
||||
@else
|
||||
<span>共 0 条</span>
|
||||
@endif
|
||||
@ -37,8 +44,8 @@
|
||||
@endif
|
||||
<a
|
||||
href="{{ route('business.courier-payable-summaries.export', ['summaryPage' => $courierSummaryPage]) }}"
|
||||
@class(['courier-summary__button', 'is-disabled' => $courierSummaryRows->total() === 0])
|
||||
@if ($courierSummaryRows->total() === 0) aria-disabled="true" tabindex="-1" @endif
|
||||
@class(['courier-summary__button', 'is-disabled' => $courierSummarySourceTotal === 0])
|
||||
@if ($courierSummarySourceTotal === 0) aria-disabled="true" tabindex="-1" @endif
|
||||
>
|
||||
<span class="material-icons-outlined" aria-hidden="true">download</span>
|
||||
<span>导出</span>
|
||||
@ -62,6 +69,40 @@
|
||||
<div class="courier-summary__notice is-error" role="alert">{{ $courierSummaryError }}</div>
|
||||
@endif
|
||||
|
||||
<form
|
||||
class="courier-summary__filters"
|
||||
method="GET"
|
||||
action="{{ route('business.pages.show', ['section' => 'courier-payables', 'page' => $courierSummaryPage]) }}"
|
||||
aria-label="{{ $courierSummaryTitle }}查询条件"
|
||||
>
|
||||
<label class="courier-summary__filter">
|
||||
<span>日期</span>
|
||||
<input type="text" name="date" value="{{ $courierSummaryFilters['date'] }}" maxlength="50" placeholder="如 2026-07">
|
||||
</label>
|
||||
<label class="courier-summary__filter">
|
||||
<span>负责人</span>
|
||||
<input type="text" name="person" value="{{ $courierSummaryFilters['person'] }}" maxlength="100" placeholder="请输入负责人">
|
||||
</label>
|
||||
<label class="courier-summary__filter">
|
||||
<span>快递公司</span>
|
||||
<input type="text" name="courier" value="{{ $courierSummaryFilters['courier'] }}" maxlength="100" placeholder="快递公司 / 名称">
|
||||
</label>
|
||||
<label class="courier-summary__filter is-keyword">
|
||||
<span>关键词</span>
|
||||
<input type="text" name="keyword" value="{{ $courierSummaryFilters['keyword'] }}" maxlength="191" placeholder="运单号 / 交易号 / 条码 / 店铺 / 备注">
|
||||
</label>
|
||||
<div class="courier-summary__filter-actions">
|
||||
<button type="submit" class="courier-summary__button is-primary">
|
||||
<span class="material-icons-outlined" aria-hidden="true">search</span>
|
||||
<span>查询</span>
|
||||
</button>
|
||||
<a class="courier-summary__button" href="{{ route('business.pages.show', ['section' => 'courier-payables', 'page' => $courierSummaryPage]) }}">
|
||||
<span class="material-icons-outlined" aria-hidden="true">refresh</span>
|
||||
<span>重置</span>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="courier-summary__table-wrap">
|
||||
<table class="courier-summary__table">
|
||||
<thead>
|
||||
@ -82,7 +123,13 @@
|
||||
</tr>
|
||||
@empty
|
||||
<tr class="courier-summary__empty">
|
||||
<td colspan="{{ max(count($courierSummaryHeaders) + 1, 1) }}">暂无数据,请先点击“导入”上传汇总表。</td>
|
||||
<td colspan="{{ max(count($courierSummaryHeaders) + 1, 1) }}">
|
||||
@if ($courierSummaryHasFilters && $courierSummarySourceTotal > 0)
|
||||
当前查询条件下没有匹配数据。
|
||||
@else
|
||||
暂无数据,请先点击“导入”上传汇总表。
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
@ -171,7 +218,14 @@
|
||||
.courier-summary__notice { padding:10px 12px; border-bottom:1px solid var(--vip-border,#d8d2c7); font-size:.75rem; }
|
||||
.courier-summary__notice.is-success { background:#f3f8ef; color:var(--vip-success,#53793e); }
|
||||
.courier-summary__notice.is-error { background:#fff5f5; color:var(--vip-danger,#b80000); }
|
||||
.courier-summary__table-wrap { max-height:calc(100vh - 315px); min-height:180px; overflow:auto; }
|
||||
.courier-summary__filters { display:grid; grid-template-columns:minmax(130px,.75fr) minmax(130px,.75fr) minmax(150px,1fr) minmax(240px,1.5fr) auto; align-items:end; gap:10px; padding:10px 12px; border-bottom:1px solid var(--vip-border,#d8d2c7); background:#fff; }
|
||||
.courier-summary__filter { display:grid; min-width:0; gap:4px; margin:0; }
|
||||
.courier-summary__filter>span { color:var(--vip-content-muted,#595959); font-size:.75rem; font-weight:500; line-height:1.333; }
|
||||
.courier-summary__filter input { width:100%; height:34px; min-width:0; padding:0 10px; border:1px solid var(--vip-border,#d8d2c7); border-radius:8px; background:#fff; color:var(--vip-content-ink,#171717); font:inherit; font-size:.8125rem; }
|
||||
.courier-summary__filter input::placeholder { color:var(--vip-content-muted,#595959); opacity:1; }
|
||||
.courier-summary__filter input:focus { outline:0; border-color:var(--vip-content-accent-dark,#856632); box-shadow:0 0 0 3px rgba(133,102,50,.2); }
|
||||
.courier-summary__filter-actions { display:flex; align-items:center; gap:8px; }
|
||||
.courier-summary__table-wrap { max-height:calc(100vh - 385px); min-height:180px; overflow:auto; }
|
||||
.courier-summary__table { width:max-content; min-width:100%; border-collapse:collapse; font-size:.78125rem; font-variant-numeric:tabular-nums; }
|
||||
.courier-summary__table th,.courier-summary__table td { min-width:128px; height:38px; padding:7px 10px; border-right:1px solid var(--vip-border,#d8d2c7); border-bottom:1px solid var(--vip-border,#d8d2c7); text-align:left; white-space:nowrap; }
|
||||
.courier-summary__table th { position:sticky; top:0; z-index:2; background:var(--vip-content-accent-soft,#f7f0de); font-size:.75rem; font-weight:600; }
|
||||
@ -199,7 +253,8 @@
|
||||
.courier-summary__file-picker:hover { border-color:var(--vip-content-accent-dark,#856632); }
|
||||
.courier-summary__file-picker:focus-within { box-shadow:0 0 0 3px rgba(133,102,50,.2); }
|
||||
.courier-summary__import-footer { display:flex; min-height:58px; align-items:center; justify-content:flex-end; gap:8px; padding:12px 16px; border-top:1px solid var(--vip-border,#d8d2c7); background:var(--vip-content-bg,#f8f6f1); }
|
||||
@media (max-width:700px) { .courier-summary__toolbar { align-items:flex-start; flex-direction:column; } .courier-summary__actions { width:100%; } .courier-summary__template-row { grid-template-columns:28px minmax(0,1fr); } .courier-summary__template-row .courier-summary__button { grid-column:1/-1; justify-content:center; } }
|
||||
@media (max-width:1100px) { .courier-summary__filters { grid-template-columns:repeat(2,minmax(150px,1fr)); } .courier-summary__filter.is-keyword { grid-column:span 2; } .courier-summary__filter-actions { justify-content:flex-end; } }
|
||||
@media (max-width:700px) { .courier-summary__toolbar { align-items:flex-start; flex-direction:column; } .courier-summary__actions { width:100%; } .courier-summary__filters { grid-template-columns:1fr; } .courier-summary__filter.is-keyword { grid-column:auto; } .courier-summary__filter-actions { justify-content:flex-start; } .courier-summary__template-row { grid-template-columns:28px minmax(0,1fr); } .courier-summary__template-row .courier-summary__button { grid-column:1/-1; justify-content:center; } }
|
||||
</style>
|
||||
|
||||
@if ($courierSummaryImportTemplate)
|
||||
|
||||
@ -48,10 +48,99 @@ class CourierPayableSummaryPagesTest extends FeatureTestCase
|
||||
->assertSeeText($title)
|
||||
->assertSeeText('导入')
|
||||
->assertSeeText('导出')
|
||||
->assertSee('name="date"', false)
|
||||
->assertSee('name="person"', false)
|
||||
->assertSee('name="courier"', false)
|
||||
->assertSee('name="keyword"', false)
|
||||
->assertSeeText('查询')
|
||||
->assertSeeText('重置')
|
||||
->assertSeeText('暂无数据,请先点击“导入”上传汇总表。');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_each_summary_page_can_query_by_date_person_courier_and_long_identifier(): void
|
||||
{
|
||||
$pages = [
|
||||
'freight-difference' => ['结算月份', '快递公司', 'SF000000000000000001'],
|
||||
'other-surcharge-summary' => ['日期', '快递公司', 'ORDER000000000000000002'],
|
||||
'return-fee' => ['日期', '快递名称', '7732543323146123456'],
|
||||
];
|
||||
|
||||
foreach ($pages as $page => [$dateHeader, $courierHeader, $longIdentifier]) {
|
||||
$this->storeSnapshot($page, [
|
||||
$dateHeader,
|
||||
'负责人',
|
||||
$courierHeader,
|
||||
'运单号码',
|
||||
'备注',
|
||||
], [
|
||||
['2026-07', '苏木', '测试中通', $longIdentifier, '需要复核'],
|
||||
['2026-08', '周生辰', '测试圆通', 'OTHER000000000000000009', '无需复核'],
|
||||
]);
|
||||
|
||||
$url = route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
'section' => 'courier-payables',
|
||||
'page' => $page,
|
||||
]) . '?' . http_build_query([
|
||||
'date' => '2026-07',
|
||||
'person' => '苏木',
|
||||
'courier' => '中通',
|
||||
'keyword' => $longIdentifier,
|
||||
]);
|
||||
|
||||
$this->loginAs()->get($url)
|
||||
->assertOk()
|
||||
->assertSeeText($longIdentifier)
|
||||
->assertDontSeeText('OTHER000000000000000009')
|
||||
->assertSeeText('查询到 1 条 / 共 2 条')
|
||||
->assertSee('value="2026-07"', false)
|
||||
->assertSee('value="苏木"', false)
|
||||
->assertSee('value="中通"', false)
|
||||
->assertSee('value="' . $longIdentifier . '"', false);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_summary_query_preserves_filters_during_pagination_and_has_a_clear_empty_state(): void
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
for ($index = 1; $index <= 51; $index++) {
|
||||
$rows[] = [
|
||||
'2026-07',
|
||||
'苏木',
|
||||
'测试中通',
|
||||
sprintf('SF%018d', $index),
|
||||
sprintf('ORDER%015d', $index),
|
||||
];
|
||||
}
|
||||
|
||||
$this->storeSnapshot('return-fee', ['日期', '负责人', '快递名称', '运单号码', '交易订单'], $rows);
|
||||
$pageRoute = route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
'section' => 'courier-payables',
|
||||
'page' => 'return-fee',
|
||||
]);
|
||||
$filters = ['courier' => '中通', 'keyword' => 'ORDER'];
|
||||
|
||||
$this->loginAs()->get($pageRoute . '?' . http_build_query($filters))
|
||||
->assertOk()
|
||||
->assertSeeText('第 1 / 2 页')
|
||||
->assertSee('courier=' . rawurlencode('中通') . '&keyword=ORDER&page=2', false);
|
||||
|
||||
$lastWaybill = sprintf('SF%018d', 51);
|
||||
$this->loginAs()->get($pageRoute . '?' . http_build_query([...$filters, 'page' => 2]))
|
||||
->assertOk()
|
||||
->assertSeeText($lastWaybill)
|
||||
->assertSeeText('第 2 / 2 页');
|
||||
|
||||
$this->loginAs()->get($pageRoute . '?keyword=' . rawurlencode('完全不存在的数据'))
|
||||
->assertOk()
|
||||
->assertSeeText('当前查询条件下没有匹配数据。')
|
||||
->assertDontSeeText('暂无数据,请先点击“导入”上传汇总表。')
|
||||
->assertSeeText('查询到 0 条 / 共 51 条');
|
||||
}
|
||||
|
||||
public function test_freight_difference_import_dialog_downloads_the_supplied_xlsx_template(): void
|
||||
{
|
||||
$pageResponse = $this->loginAs()->get(route('business.pages.show', [
|
||||
@ -586,4 +675,21 @@ class CourierPayableSummaryPagesTest extends FeatureTestCase
|
||||
'summaryPage' => 'return-fee',
|
||||
]))->assertForbidden();
|
||||
}
|
||||
|
||||
/** @param list<string> $headers @param list<list<string>> $rows */
|
||||
private function storeSnapshot(string $page, array $headers, array $rows): void
|
||||
{
|
||||
$store = app(CourierPayableSummaryStore::class);
|
||||
Storage::disk('uploads')->put(
|
||||
$store->path((int) $this->company->id, $page),
|
||||
json_encode([
|
||||
'version' => 1,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'source_name' => $page . '.xlsx',
|
||||
'imported_at' => now()->toIso8601String(),
|
||||
'imported_by' => $this->user->id,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user