业绩明细:平台/店铺可搜索多选、导出跟随筛选且空值导出 0.00、分页支持每页条数与跳页(表头吸顶/序号列固定)

This commit is contained in:
yueyang 2026-10-07 17:54:34 +08:00
parent c8a035a18f
commit dba61e5c8e
2 changed files with 234 additions and 32 deletions

View File

@ -95,6 +95,18 @@ class Pages extends Controller
*/
private const PAYABLES_FINAL_SECTIONS = ['supplier-payables-final', 'courier-payables-final'];
/** 业绩明细的平台筛选顺序(与店铺收款账户账单页签一致)。 */
private const RECEIPT_PLATFORM_OPTIONS = [
'淘系支付宝',
'淘系微信',
'拼多多',
'京东账单',
'京喜账单',
'京东网银钱包',
'抖音',
'得物',
];
public function __construct(
private readonly EdgeBandingRepository $edgeBanding,
private readonly InventoryRepository $inventory,
@ -586,7 +598,11 @@ class Pages extends Controller
// 明确指定月份时严格按该月份取数(该月没同步就显示空表)。
$month = $requested !== '' ? $requested : ($months[0] ?? null);
$limit = min(max((int) setting('default.list_limit', 25), 1), 50);
// 每页条数:业绩明细页面可切 10 / 20 / 50,未指定时沿用系统默认(上限 50)。
$requestedLimit = (int) request('per_page', 0);
$limit = in_array($requestedLimit, [10, 20, 50], true)
? $requestedLimit
: min(max((int) setting('default.list_limit', 25), 1), 50);
$page = max((int) request('page', 1), 1);
$empty = new LengthAwarePaginator([], 0, $limit, $page, [
'path' => request()->url(),
@ -596,20 +612,22 @@ class Pages extends Controller
return [$empty, null];
}
$applyFilters = static function ($query): void {
$platform = trim((string) request('platform', ''));
if ($platform !== '') {
$query->where('platform', $platform);
// 平台 / 店铺与其它页面一致:可打字搜索的多选(一个都不勾=全部),同时兼容旧的单值链接。
$platformFilter = $this->receiptOrderMatchFilterValues(request('platform'));
$storeFilter = $this->receiptOrderMatchFilterValues(request('store_name'));
$orderNo = trim((string) request('online_order_no', ''));
$status = trim((string) request('match_status', ''));
$applyFilters = static function ($query) use ($platformFilter, $storeFilter, $orderNo, $status): void {
if ($platformFilter !== []) {
$query->whereIn('platform', $platformFilter);
}
$store = trim((string) request('store_name', ''));
if ($store !== '') {
$query->where('store_name', 'like', '%' . addcslashes($store, '%_\\') . '%');
if ($storeFilter !== []) {
$query->whereIn('store_name', $storeFilter);
}
$orderNo = trim((string) request('online_order_no', ''));
if ($orderNo !== '') {
$query->where('online_order_no', 'like', '%' . addcslashes($orderNo, '%_\\') . '%');
}
$status = trim((string) request('match_status', ''));
if ($status !== '') {
// 基础状态(已匹配/未匹配)按状态列过滤,其余按异常标注过滤。
if (in_array($status, ['已匹配', '未匹配'], true)) {
@ -659,8 +677,36 @@ class Pages extends Controller
'offset_total' => round((float) ($agg->offset_total ?? 0), 2),
'goods_total' => round((float) ($agg->goods_total ?? 0), 2),
'difference_total' => round((float) ($agg->difference_total ?? 0), 2),
'per_page' => $limit,
];
// 筛选下拉候选:本月镜像里实际出现的平台与店铺(按 6 小时缓存,避免每次开页做去重扫描),
// 并把当前已选值并入,保证筛选项的文字不会因为换月而消失。
$filterOptions = cache()->remember(
'performance-details-filter-options-v1:' . $month,
now()->addHours(6),
static function () use ($connection, $month): array {
$maker = static fn () => DB::connection($connection)->table('store_receipt_order_match_rows')
->where('report_month', $month);
return [
'platforms' => $maker()->whereNotNull('platform')->distinct()->orderBy('platform')->pluck('platform')->all(),
'stores' => $maker()->whereNotNull('store_name')->where('store_name', '!=', '')
->distinct()->orderBy('store_name')->pluck('store_name')->all(),
];
},
);
$stats['selected_platforms'] = $platformFilter;
$stats['selected_stores'] = $storeFilter;
$stats['platform_options'] = array_values(array_unique(array_merge(
self::RECEIPT_PLATFORM_OPTIONS,
array_map('strval', $filterOptions['platforms'] ?? []),
)));
$stats['store_options'] = array_values(array_unique(array_merge(
$storeFilter,
array_map('strval', $filterOptions['stores'] ?? []),
)));
if ($total === 0) {
return [$empty, $stats];
}
@ -680,6 +726,28 @@ class Pages extends Controller
]), $stats];
}
/**
* 业绩明细的多选筛选值:多选控件提交 name[](数组),同时兼容历史单值链接。
*
* @return list<string>
*/
private function receiptOrderMatchFilterValues(mixed $input): array
{
$values = is_array($input) ? $input : [$input];
$clean = [];
foreach ($values as $value) {
if (is_array($value)) {
continue;
}
$text = trim((string) $value);
if ($text !== '') {
$clean[$text] = true;
}
}
return array_keys($clean);
}
/**
* 业绩明细 → 店铺收款匹配订单明细导出:按当前月份与筛选条件导出 CSV,列序跟随页面显示列。
*/
@ -714,13 +782,13 @@ class Pages extends Controller
$query = DB::connection($connection)->table('store_receipt_order_match_rows')
->when($month !== null, static fn ($builder) => $builder->where('report_month', $month));
$platform = trim((string) $request->query('platform', ''));
if ($platform !== '') {
$query->where('platform', $platform);
$platforms = $this->receiptOrderMatchFilterValues($request->query('platform'));
if ($platforms !== []) {
$query->whereIn('platform', $platforms);
}
$store = trim((string) $request->query('store_name', ''));
if ($store !== '') {
$query->where('store_name', 'like', '%' . addcslashes($store, '%_\\') . '%');
$stores = $this->receiptOrderMatchFilterValues($request->query('store_name'));
if ($stores !== []) {
$query->whereIn('store_name', $stores);
}
$orderNo = trim((string) $request->query('online_order_no', ''));
if ($orderNo !== '') {
@ -765,7 +833,8 @@ class Pages extends Controller
$format = $map[$key][2];
$value = $row->{$map[$key][0]} ?? '';
if ($format === 'money') {
$line[] = $value === null || $value === '' ? '' : number_format((float) $value, 2, '.', '');
// 金额列空值导出成 0.00:Excel 里直接求和、做差额核对不用再补空。
$line[] = number_format((float) ($value === null || $value === '' ? 0 : $value), 2, '.', '');
continue;
}

View File

@ -1352,16 +1352,60 @@
</div>
</form>
@elseif (($page['slug'] ?? '') === 'performance-details')
@include('business.pages.partials.multi-select')
<style>
/* 业绩明细:多选筛选与其它页面一致(标签 + 可搜索下拉),这里只补布局对齐。 */
.installation-filter-bar .cw-ms__box { flex: 1 1 auto; min-width: 0; }
.installation-filter-bar .cw-ms__btn { font-size: 0.75rem; }
/* 分页便捷化:每页条数、首页/末页、跳页(与账单明细页同一套控件) */
.directory-table-pagination__nav { display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.directory-table-pagination__size,
.directory-table-pagination__jump { display: inline-flex; align-items: center; gap: 0.25rem; color: #595959; }
.directory-table-pagination__size select,
.directory-table-pagination__jump input {
height: 1.85rem;
padding: 0 0.35rem;
border: 1px solid #d8d2c7;
border-radius: 0.4rem;
background: #fff;
color: #171717;
font: inherit;
font-size: 0.75rem;
}
.directory-table-pagination__jump input { width: 4.5rem; }
.directory-table-pagination__nav .is-disabled { color: #b9b3a8; }
/* 列多、行多:表头吸顶 + 序号列固定,横向滚动时不丢行标识 */
#directory-table-performance-details thead th {
position: sticky;
top: 0;
z-index: 3;
background: #faf6ec;
}
#directory-table-performance-details tbody td[data-directory-fixed="start"],
#directory-table-performance-details thead th[data-directory-fixed="start"] {
position: sticky;
left: 0;
z-index: 4;
background: #fffdf8;
}
#directory-table-performance-details thead th[data-directory-fixed="start"] { z-index: 5; }
</style>
<form method="GET" action="{{ request()->url() }}" class="installation-filter-bar" aria-label="业绩明细筛选查询栏">
<label class="installation-filter-field">
{{-- 查询时保留当前每页条数 --}}
<input type="hidden" name="per_page" value="{{ (int) ($receiptStats['per_page'] ?? 25) }}">
<div class="installation-filter-field cw-ms" id="rdPlatform" data-name="platform"
data-initial="{{ json_encode(array_values($receiptStats['selected_platforms'] ?? []), JSON_UNESCAPED_UNICODE) }}">
<span>平台:</span>
<select name="platform">
<option value="">全部</option>
@foreach (['淘系支付宝', '淘系微信', '拼多多', '京东账单', '京喜账单', '京东网银钱包', '抖音', '得物'] as $receiptPlatformOption)
<option value="{{ $receiptPlatformOption }}" @selected((string) request('platform') === $receiptPlatformOption)>{{ $receiptPlatformOption }}</option>
@endforeach
</select>
</label>
<span class="cw-ms__box">
<button type="button" class="cw-ms__btn" data-role="btn" aria-expanded="false">
<span class="cw-ms__label">全部</span><span class="cw-ms__caret">▾</span>
</button>
<span class="cw-ms__panel" data-role="panel" hidden></span>
<span class="cw-ms__values" data-role="values"></span>
</span>
</div>
<label class="installation-filter-field">
<span>月份:</span>
@php
@ -1388,10 +1432,17 @@
</div>
</div>
</label>
<label class="installation-filter-field">
<div class="installation-filter-field cw-ms" id="rdStore" data-name="store_name"
data-initial="{{ json_encode(array_values($receiptStats['selected_stores'] ?? []), JSON_UNESCAPED_UNICODE) }}">
<span>店铺名称:</span>
<input type="text" name="store_name" value="{{ request('store_name') }}" placeholder="支持包含查询">
</label>
<span class="cw-ms__box">
<button type="button" class="cw-ms__btn" data-role="btn" aria-expanded="false">
<span class="cw-ms__label">全部</span><span class="cw-ms__caret">▾</span>
</button>
<span class="cw-ms__panel" data-role="panel" hidden></span>
<span class="cw-ms__values" data-role="values"></span>
</span>
</div>
<label class="installation-filter-field">
<span>线上单号:</span>
<input type="text" name="online_order_no" value="{{ request('online_order_no') }}" placeholder="支持包含查询">
@ -1410,6 +1461,21 @@
<a href="{{ request()->url() }}" class="biz-btn biz-btn-ghost">清除</a>
</div>
</form>
<script>
(function () {
var api = window.CaiWuMultiSelect;
if (!api) { return; }
[
['rdPlatform', @json(array_values($receiptStats['platform_options'] ?? [])), '打字找平台(可多选)'],
['rdStore', @json(array_values($receiptStats['store_options'] ?? [])), '打字找店铺(可多选)']
].forEach(function (def) {
var el = document.getElementById(def[0]);
if (el) {
api.create(el, { options: def[1], searchable: true, searchPlaceholder: def[2] });
}
});
})();
</script>
@elseif (in_array(($page['slug'] ?? ''), ['inventory-report', 'monthly-weighted-average-price'], true))
<form method="GET" action="{{ request()->url() }}" class="installation-filter-bar" aria-label="进销存报表筛选查询栏">
<label class="installation-filter-field">
@ -1647,22 +1713,84 @@
</div>
@if ($directoryIsPaginated && empty($upstreamError))
@php
$directoryIsReceiptMatchPage = ($page['slug'] ?? '') === 'performance-details';
$directoryLastPageSafe = max((int) $directoryLastPage, 1);
@endphp
<footer class="directory-table-pagination">
<span>共 {{ $directoryTotal }} 条 · 第 {{ $directoryCurrentPage }} / {{ $directoryLastPage }} 页</span>
<span>
<span>共 {{ number_format($directoryTotal) }} 条 · 第 {{ number_format($directoryCurrentPage) }} / {{ number_format($directoryLastPageSafe) }} 页</span>
<span class="directory-table-pagination__nav">
@if ($directoryIsReceiptMatchPage)
<label class="directory-table-pagination__size">每页
<select data-directory-per-page aria-label="每页条数">
@foreach ([10, 20, 50] as $size)
<option value="{{ $size }}" @selected((int) $directoryRows->perPage() === $size)>{{ $size }}</option>
@endforeach
</select>
</label>
@endif
@if ($directoryRows->onFirstPage())
@if ($directoryIsReceiptMatchPage)
<span class="is-disabled" title="首页">«</span>
@endif
<span>上一页</span>
@else
@if ($directoryIsReceiptMatchPage)
<a href="{{ $directoryRows->url(1) }}" title="首页">«</a>
@endif
<a href="{{ $directoryRows->previousPageUrl() }}">上一页</a>
@endif
·
@if ($directoryRows->hasMorePages())
<a href="{{ $directoryRows->nextPageUrl() }}">下一页</a>
@if ($directoryIsReceiptMatchPage)
<a href="{{ $directoryRows->url($directoryLastPageSafe) }}" title="末页">»</a>
@endif
@else
<span>下一页</span>
@if ($directoryIsReceiptMatchPage)
<span class="is-disabled" title="末页">»</span>
@endif
@endif
@if ($directoryIsReceiptMatchPage && $directoryLastPageSafe > 1)
<label class="directory-table-pagination__jump">跳到
<input type="number" min="1" max="{{ $directoryLastPageSafe }}" value="{{ $directoryCurrentPage }}" data-directory-page-jump aria-label="跳到第几页">
页
</label>
@endif
</span>
</footer>
@if ($directoryIsReceiptMatchPage)
<script>
(function () {
var footer = document.currentScript.previousElementSibling;
if (!footer) { return; }
var sizeSelect = footer.querySelector('[data-directory-per-page]');
if (sizeSelect) {
sizeSelect.addEventListener('change', function () {
var url = new URL(window.location.href);
url.searchParams.set('per_page', sizeSelect.value);
url.searchParams.set('page', '1');
window.location.href = url.toString();
});
}
var jumpInput = footer.querySelector('[data-directory-page-jump]');
if (jumpInput) {
var maxPage = Number(jumpInput.getAttribute('max')) || 1;
var go = function () {
var target = Math.min(Math.max(parseInt(jumpInput.value, 10) || 1, 1), maxPage);
var url = new URL(window.location.href);
url.searchParams.set('page', String(target));
window.location.href = url.toString();
};
jumpInput.addEventListener('keydown', function (event) {
if (event.key === 'Enter') { event.preventDefault(); go(); }
});
jumpInput.addEventListener('change', go);
}
})();
</script>
@endif
@endif
@if ($isInventoryReportPage)
@ -2424,8 +2552,13 @@
tools.querySelector('[data-inventory-export]')?.addEventListener('click', (event) => {
const url = new URL(event.currentTarget.dataset.exportUrl, window.location.origin);
const current = new URL(window.location.href);
['month', 'product_code', 'warehouse_provider', 'category'].forEach((key) => {
if (current.searchParams.has(key)) url.searchParams.set(key, current.searchParams.get(key));
// 导出跟随当前筛选:把页面上已有的查询参数原样带上(含 platform[] / store_name[] 这类多选),
// 只排除分页与本次导出自己的参数,否则「只筛了拼多多」也会导出全部。
const skipped = new Set(['page', 'scope', 'columns']);
current.searchParams.forEach((value, key) => {
if (!skipped.has(key)) {
url.searchParams.append(key, value);
}
});
const scope = tools.querySelector('[data-inventory-export-scope]').value;
url.searchParams.set('scope', scope);