From f3a5788c67242d2c627f4d8dd27fe0aebb2d4aea Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Wed, 4 Nov 2026 15:58:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E5=BE=85=E7=A1=AE=E8=AE=A4=E5=B9=B3=E5=8F=B0=E6=9C=88=E5=BA=A6?= =?UTF-8?q?=E6=B1=87=E6=80=BB=20(#864)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 退款待确认页面增加平台月度汇总。 --- app/Http/Controllers/Business/Pages.php | 9 +- .../NonJingxiRefundMirrorRepository.php | 90 +++++++++++++++++++ .../refunds/non-jingxi-refund-data.blade.php | 66 ++++++++++++++ .../Business/NonJingxiRefundPageTest.php | 15 +++- .../NonJingxiRefundMirrorRepositoryTest.php | 10 +++ 5 files changed, 184 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 88d4d8a6..62a51ead 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -7040,6 +7040,7 @@ class Pages extends Controller $indexPending = false; $pageLabel = $pendingConfirmation ? '退款待确认' : '售后(退货退款)'; $refundMonthlySummary = []; + $refundPlatformMonthlySummary = ['months' => [], 'platforms' => []]; try { if (! $this->nonJingxiRefunds->available()) { @@ -7055,14 +7056,15 @@ class Pages extends Controller $indexPending = true; } else { if ($pendingConfirmation) { - $refundMonthlySummary = \Illuminate\Support\Facades\Cache::remember( - 'refund-pending.monthly-summary.v1:' . $defaultTo, + $refundPlatformMonthlySummary = \Illuminate\Support\Facades\Cache::remember( + 'refund-pending.platform-monthly-summary.v1:' . $defaultTo, now()->addMinutes(5), - fn (): array => $this->nonJingxiRefunds->pendingConfirmationMonthlySummary( + fn (): array => $this->nonJingxiRefunds->pendingConfirmationPlatformMonthlySummary( '2026-10-01', $defaultTo, ), ); + $refundMonthlySummary = $refundPlatformMonthlySummary['months'] ?? []; } else { $result = $this->nonJingxiRefunds->paginate($filters, $page, $limit); $rows = new LengthAwarePaginator( @@ -7094,6 +7096,7 @@ class Pages extends Controller 'refundPendingConfirmationMode' => $pendingConfirmation, 'refundOnlineStatusLabel' => $pendingConfirmation ? '线上状态' : '店铺状态', 'refundMonthlySummary' => $refundMonthlySummary, + 'refundPlatformMonthlySummary' => $refundPlatformMonthlySummary, 'refundExportRouteName' => $pendingConfirmation ? 'business.refunds.refund-pending.export' : 'business.refunds.non-jingxi-refund-data.export', diff --git a/modules/EcommerceFinance/Repositories/NonJingxiRefundMirrorRepository.php b/modules/EcommerceFinance/Repositories/NonJingxiRefundMirrorRepository.php index 988dfe96..93d79c7b 100644 --- a/modules/EcommerceFinance/Repositories/NonJingxiRefundMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/NonJingxiRefundMirrorRepository.php @@ -277,6 +277,96 @@ class NonJingxiRefundMirrorRepository return array_values($months); } + /** + * 按平台和退款月份汇总待确认记录,并同时返回月份总计。 + * + * @return array{ + * months:list, + * platforms:list}> + * } + */ + public function pendingConfirmationPlatformMonthlySummary(string $from, string $to): array + { + if (! $this->ready() || ! $this->queryReady()) { + throw new RuntimeException('business_mirror_dataset_not_ready'); + } + + $start = Carbon::parse($from)->startOfMonth(); + $end = Carbon::parse($to)->startOfMonth(); + if ($start->greaterThan($end)) { + return ['months' => [], 'platforms' => []]; + } + + $monthKeys = []; + for ($month = $start->copy(); $month->lessThanOrEqualTo($end); $month->addMonth()) { + $monthKeys[] = $month->format('Y-m'); + } + $baseFilters = $this->pendingConfirmationFilters([ + 'from' => $start->toDateString(), + 'to' => Carbon::parse($to)->toDateString(), + 'order_no' => '', + 'waybill_no' => '', + 'shop_name' => '', + 'sku_id' => '', + ]); + $monthExpression = $this->connection->getDriverName() === 'sqlite' + ? "strftime('%Y-%m', r.as_date)" + : "DATE_FORMAT(r.as_date, '%Y-%m')"; + $platformCounts = []; + $addCount = static function (string $platform, string $month, int $count) use (&$platformCounts): void { + $platform = trim($platform) !== '' ? trim($platform) : '待确认'; + $platformCounts[$platform][$month] = ($platformCounts[$platform][$month] ?? 0) + $count; + }; + + $primaryPlatform = "COALESCE(NULLIF(TRIM(r.shop_site), ''), '待确认')"; + $primaryRows = $this->sourceQuery($baseFilters, false, false) + ->selectRaw("{$monthExpression} AS refund_month, {$primaryPlatform} AS platform, COUNT(*) AS total") + ->groupByRaw("{$monthExpression}, {$primaryPlatform}") + ->get(); + foreach ($primaryRows as $row) { + $addCount((string) $row->platform, (string) $row->refund_month, (int) $row->total); + } + + $supplementRows = $this->sourceQuery($baseFilters, true, false) + ->selectRaw("{$monthExpression} AS refund_month, r.shop_id, COUNT(*) AS total") + ->groupByRaw("{$monthExpression}, r.shop_id") + ->get(); + $shopIds = $supplementRows->pluck('shop_id')->filter()->unique()->values(); + $shopPlatforms = $shopIds->isEmpty() ? collect() : $this->connection->table('ops_jst_shop_info') + ->whereIn('shop_id', $shopIds) + ->get(['shop_id', 'shop_site']) + ->groupBy('shop_id'); + foreach ($supplementRows as $row) { + $sites = ($shopPlatforms->get($row->shop_id) ?? collect()) + ->pluck('shop_site')->filter()->map(static fn (mixed $site): string => trim((string) $site)) + ->filter()->unique()->values(); + $addCount($sites->count() === 1 ? (string) $sites->first() : '待确认', (string) $row->refund_month, (int) $row->total); + } + + $monthTotals = array_fill_keys($monthKeys, 0); + $platforms = []; + foreach ($platformCounts as $platform => $counts) { + $monthValues = []; + $total = 0; + foreach ($monthKeys as $month) { + $count = (int) ($counts[$month] ?? 0); + $monthValues[$month] = $count; + $monthTotals[$month] += $count; + $total += $count; + } + $platforms[] = ['platform' => (string) $platform, 'total' => $total, 'months' => $monthValues]; + } + usort($platforms, static fn (array $left, array $right): int => [$right['total'], $left['platform']] <=> [$left['total'], $right['platform']]); + + return [ + 'months' => array_map( + static fn (string $month): array => ['month' => $month, 'total' => $monthTotals[$month]], + $monthKeys, + ), + 'platforms' => $platforms, + ]; + } + /** * Export all rows matching the supplied filters in the same order and * shape as the paginated page data, without loading the full result set. diff --git a/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php b/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php index a6079ad1..b54a2af0 100644 --- a/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php +++ b/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php @@ -160,6 +160,43 @@ color: var(--vip-content-muted, #595959); font-size: 0.75rem; } + .refund-platform-summary { + padding: 0.85rem 1rem 1rem; + border-bottom: 1px solid var(--vip-border, #d8d2c7); + background: #fbfaf6; + } + .refund-platform-summary__title { + margin-bottom: 0.6rem; + color: var(--vip-content-ink, #171717); + font-size: 0.78rem; + font-weight: 600; + } + .refund-platform-summary__scroll { + overflow: auto; + max-height: 16rem; + border: 1px solid var(--vip-border, #d8d2c7); + border-radius: 8px; + background: var(--vip-surface, #ffffff); + } + .refund-platform-summary__table { + width: 100%; + min-width: max-content; + border-collapse: collapse; + font-size: 0.75rem; + } + .refund-platform-summary__table th, + .refund-platform-summary__table td { + min-width: 7rem; + padding: 0.55rem 0.7rem; + border-right: 1px solid var(--vip-border, #d8d2c7); + border-bottom: 1px solid var(--vip-border, #d8d2c7); + text-align: right; + white-space: nowrap; + } + .refund-platform-summary__table th:first-child, + .refund-platform-summary__table td:first-child { text-align: left; } + .refund-platform-summary__table th { position: sticky; top: 0; z-index: 1; background: var(--vip-content-accent-soft, #f7f0de); font-weight: 600; } + .refund-platform-summary__table td:first-child { font-weight: 600; } .refund-month-group + .refund-month-group { border-top: 1px solid var(--vip-border, #d8d2c7); } .refund-month-toggle { display: grid; @@ -289,6 +326,35 @@ 按退款月份统计 点击月份展开待确认明细 + @if (!empty($refundPlatformMonthlySummary['platforms'])) +
+
平台月度汇总
+
+ + + + + @foreach ($refundPlatformMonthlySummary['months'] as $summaryMonth) + + @endforeach + + + + + @foreach ($refundPlatformMonthlySummary['platforms'] as $platformSummary) + + + @foreach ($refundPlatformMonthlySummary['months'] as $summaryMonth) + + @endforeach + + + @endforeach + +
平台{{ \Illuminate\Support\Carbon::parse($summaryMonth['month'] . '-01')->format('Y年n月') }}合计
{{ $platformSummary['platform'] }}{{ number_format((int) ($platformSummary['months'][$summaryMonth['month']] ?? 0)) }}{{ number_format((int) $platformSummary['total']) }}
+
+
+ @endif @forelse ($refundMonthlySummary as $monthSummary) @php $monthKey = $monthSummary['month']; diff --git a/tests/Feature/Business/NonJingxiRefundPageTest.php b/tests/Feature/Business/NonJingxiRefundPageTest.php index ef97bfdc..a8d1654f 100644 --- a/tests/Feature/Business/NonJingxiRefundPageTest.php +++ b/tests/Feature/Business/NonJingxiRefundPageTest.php @@ -147,12 +147,18 @@ class NonJingxiRefundPageTest extends FeatureTestCase ]); $repository->shouldReceive('ready')->once()->andReturnTrue(); $repository->shouldReceive('queryReady')->once()->andReturnTrue(); - $repository->shouldReceive('pendingConfirmationMonthlySummary') + $repository->shouldReceive('pendingConfirmationPlatformMonthlySummary') ->once() ->with('2026-10-01', '2026-11-04') ->andReturn([ - ['month' => '2026-10', 'total' => 5641, 'primary' => 5637, 'supplement' => 4], - ['month' => '2026-11', 'total' => 3232, 'primary' => 3232, 'supplement' => 0], + 'months' => [ + ['month' => '2026-10', 'total' => 5641], + ['month' => '2026-11', 'total' => 3232], + ], + 'platforms' => [ + ['platform' => '京东商城', 'total' => 8000, 'months' => ['2026-10' => 5000, '2026-11' => 3000]], + ['platform' => '天猫', 'total' => 873, 'months' => ['2026-10' => 641, '2026-11' => 232]], + ], ]); $this->app->instance(NonJingxiRefundMirrorRepository::class, $repository); @@ -167,6 +173,9 @@ class NonJingxiRefundPageTest extends FeatureTestCase ->assertOk() ->assertSeeText('固定筛选:状态“待确认” · 线上状态“退款成功”') ->assertSeeText('按退款月份统计') + ->assertSeeText('平台月度汇总') + ->assertSeeText('京东商城') + ->assertSeeText('天猫') ->assertSeeText('2026年10月') ->assertSeeText('5,641 条待确认') ->assertSeeText('2026年11月') diff --git a/tests/Unit/EcommerceFinance/NonJingxiRefundMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/NonJingxiRefundMirrorRepositoryTest.php index 8c26c296..25cec323 100644 --- a/tests/Unit/EcommerceFinance/NonJingxiRefundMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/NonJingxiRefundMirrorRepositoryTest.php @@ -205,6 +205,16 @@ class NonJingxiRefundMirrorRepositoryTest extends TestCase ['month' => '2026-10', 'total' => 2, 'primary' => 1, 'supplement' => 1], ['month' => '2026-11', 'total' => 1, 'primary' => 1, 'supplement' => 0], ], $summary); + + $platformSummary = $this->repository->pendingConfirmationPlatformMonthlySummary('2026-10-01', '2026-11-04'); + $this->assertSame([ + ['month' => '2026-10', 'total' => 2], + ['month' => '2026-11', 'total' => 1], + ], $platformSummary['months']); + $this->assertSame([ + ['platform' => '天猫', 'total' => 2, 'months' => ['2026-10' => 1, '2026-11' => 1]], + ['platform' => '待确认', 'total' => 1, 'months' => ['2026-10' => 1, '2026-11' => 0]], + ], $platformSummary['platforms']); } public function test_supplement_and_header_only_refunds_survive_without_invented_details(): void