parent
0154a0ddd5
commit
f3a5788c67
@ -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',
|
||||
|
||||
@ -277,6 +277,96 @@ class NonJingxiRefundMirrorRepository
|
||||
return array_values($months);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按平台和退款月份汇总待确认记录,并同时返回月份总计。
|
||||
*
|
||||
* @return array{
|
||||
* months:list<array{month:string,total:int}>,
|
||||
* platforms:list<array{platform:string,total:int,months:array<string,int>}>
|
||||
* }
|
||||
*/
|
||||
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.
|
||||
|
||||
@ -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 @@
|
||||
<strong>按退款月份统计</strong>
|
||||
<span>点击月份展开待确认明细</span>
|
||||
</div>
|
||||
@if (!empty($refundPlatformMonthlySummary['platforms']))
|
||||
<div class="refund-platform-summary">
|
||||
<div class="refund-platform-summary__title">平台月度汇总</div>
|
||||
<div class="refund-platform-summary__scroll">
|
||||
<table class="refund-platform-summary__table" aria-label="退款待确认平台月度汇总">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>平台</th>
|
||||
@foreach ($refundPlatformMonthlySummary['months'] as $summaryMonth)
|
||||
<th>{{ \Illuminate\Support\Carbon::parse($summaryMonth['month'] . '-01')->format('Y年n月') }}</th>
|
||||
@endforeach
|
||||
<th>合计</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($refundPlatformMonthlySummary['platforms'] as $platformSummary)
|
||||
<tr>
|
||||
<td>{{ $platformSummary['platform'] }}</td>
|
||||
@foreach ($refundPlatformMonthlySummary['months'] as $summaryMonth)
|
||||
<td>{{ number_format((int) ($platformSummary['months'][$summaryMonth['month']] ?? 0)) }}</td>
|
||||
@endforeach
|
||||
<td>{{ number_format((int) $platformSummary['total']) }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@forelse ($refundMonthlySummary as $monthSummary)
|
||||
@php
|
||||
$monthKey = $monthSummary['month'];
|
||||
|
||||
@ -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月')
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user