fix: 安装费用改为月度安装公司对比 (#1483)

This commit is contained in:
yueyang 2026-11-26 17:51:46 +08:00
parent 12bc2f9efd
commit d112d90ed9
3 changed files with 148 additions and 141 deletions

View File

@ -59,6 +59,8 @@ class InstallationFeeUsagePageData
}
$periods = $this->buildPeriods($fromMonth, $toMonth, $result['rows']);
$summary = $this->buildSummary($periods);
$periods = $this->applyComparableCosts($periods, $summary['benchmark_rates']);
return $this->payload(
$range,
@ -66,7 +68,7 @@ class InstallationFeeUsagePageData
$fromMonth,
$toMonth,
$periods,
$this->buildSummary($periods),
$summary,
);
}
@ -334,6 +336,57 @@ class InstallationFeeUsagePageData
];
}
/** @param array{wan:?float,luban:?float} $rates */
private function applyComparableCosts(array $periods, array $rates): array
{
$previousTotal = null;
$previousOrders = null;
foreach ($periods as &$period) {
$periodTotal = 0.0;
$hasEstimatedCost = false;
foreach ($period['vendors'] as &$vendor) {
$rate = $rates[$vendor['key']] ?? null;
if ($rate === null) {
$vendor['comparable_amount'] = null;
$vendor['comparable_unit_cost'] = null;
continue;
}
$amount = round($vendor['orders'] * $rate, 2);
$vendor['comparable_amount'] = $amount;
$vendor['comparable_unit_cost'] = $this->unitCost($amount, $vendor['orders']);
$periodTotal += $amount;
$hasEstimatedCost = true;
}
unset($vendor);
$period['comparable_amount'] = $hasEstimatedCost ? round($periodTotal, 2) : null;
$period['comparable_unit_cost'] = $period['comparable_amount'] === null
? null
: $this->unitCost($period['comparable_amount'], $period['total_orders']);
$period['fee_change_rate'] = $period['comparable_amount'] !== null
&& $previousTotal !== null
&& $previousTotal > 0
? round((($period['comparable_amount'] - $previousTotal) / $previousTotal) * 100, 1)
: null;
$period['order_change_rate'] = $period['total_orders'] > 0
&& $previousOrders !== null
&& $previousOrders > 0
? round((($period['total_orders'] - $previousOrders) / $previousOrders) * 100, 1)
: null;
if ($period['comparable_amount'] !== null) {
$previousTotal = $period['comparable_amount'];
}
if ($period['total_orders'] > 0) {
$previousOrders = $period['total_orders'];
}
}
unset($period);
return $periods;
}
private function isCompleteReviewPeriod(array $period): bool
{
if ($period['total_orders'] <= 0) {

View File

@ -7,7 +7,6 @@
$error = $installationFeeUsageError ?? null;
$currentPeriod = $summary['latest_period'] ?? null;
$previousPeriod = $summary['previous_period'] ?? null;
$vendorRows = $summary['vendors'] ?? [];
$moneyWan = static fn (mixed $value): string => number_format((float) $value / 10000, 2);
$money = static fn (mixed $value): string => number_format((float) $value, 2);
$percent = static fn (mixed $value): string => number_format((float) $value, 1);
@ -312,6 +311,30 @@
white-space: nowrap;
}
.installation-company-table .is-muted,
.installation-company-value {
display: block;
margin-top: 0.15rem;
color: var(--ic-muted);
font-size: 0.6875rem;
line-height: 1.45;
white-space: nowrap;
}
.installation-company-pill {
display: inline-flex;
align-items: center;
min-height: 1.35rem;
margin-left: 0.3rem;
padding: 0 0.38rem;
border: 1px solid rgba(133, 102, 50, 0.36);
border-radius: 999px;
color: var(--ic-accent-dark);
font-size: 0.625rem;
font-weight: 600;
vertical-align: middle;
}
.installation-company-share {
display: flex;
min-width: 8rem;
@ -451,170 +474,102 @@
<div class="installation-company-kpi">
<span>{{ $currentPeriod ?? '当前月' }} 安装单量</span>
<strong>{{ number_format((int) ($summary['current_orders'] ?? 0)) }} 单</strong>
<small>{{ $previousPeriod ?? '上月' }}:{{ number_format((int) ($summary['previous_orders'] ?? 0)) }} 单</small>
<small>万师傅 {{ number_format((int) ($summary['vendors'][0]['orders'] ?? 0)) }} 单 · 鲁班 {{ number_format((int) ($summary['vendors'][1]['orders'] ?? 0)) }} 单</small>
</div>
<div class="installation-company-kpi">
<span>{{ $currentPeriod ?? '当前月' }} 已审核安装费</span>
<strong>¥{{ $moneyWan($summary['current_confirmed_amount'] ?? 0) }} 万</strong>
<small>{{ $previousPeriod ?? '上月' }}:¥{{ $moneyWan($summary['previous_confirmed_amount'] ?? 0) }} 万</small>
<span>{{ $currentPeriod ?? '当前月' }} 预估安装费</span>
<strong>¥{{ $moneyWan($summary['estimated_mixed_amount'] ?? 0) }} 万</strong>
<small>按安装公司基准单均折算全部发货单</small>
</div>
<div class="installation-company-kpi">
<span>{{ $currentPeriod ?? '当前月' }} 审核覆盖</span>
<strong>{{ $percent($summary['current_review_rate'] ?? 0) }}%</strong>
<small>{{ number_format((int) ($summary['current_reviewed_orders'] ?? 0)) }} / {{ number_format((int) ($summary['current_orders'] ?? 0)) }} 单已审核</small>
<span>{{ $currentPeriod ?? '当前月' }} 预估单均</span>
<strong>¥{{ $money($summary['estimated_mixed_unit_cost'] ?? 0) }}</strong>
<small>预估安装费 ÷ 可识别安装单量</small>
</div>
<div class="installation-company-kpi">
<span>供应商切换预估影响</span>
<span>切换安装公司影响</span>
<strong class="{{ $switchImpactDisplay['class'] }}">{{ $switchImpactDisplay['text'] }}</strong>
<small>
@if ($hasBenchmark)
预订单均 ¥{{ $money($summary['estimated_mixed_unit_cost'] ?? 0) }}
· 全万师傅 ¥{{ $money($summary['estimated_all_wan_unit_cost'] ?? 0) }}
全万师傅预估 ¥{{ $moneyWan($summary['estimated_all_wan_amount'] ?? 0) }} 万
· 基准 {{ $summary['benchmark_label'] }}
@else
暂无完整审核基准
暂无可用基准
@endif
</small>
</div>
</section>
<p class="installation-company-rules">
单量按安装主单的发货月份统计,安装公司分为万师傅、鲁班系列和其他安装公司;金额只计入客服审核通过的明细结算金额。
切换影响按同单量预估:以最近两个“万师傅和鲁班审核覆盖率均不低于 70%”的月份为安装公司单均基准,
比较当前实际供应商占比与全部使用万师傅的预估成本。正数为预计增加,负数为预计节省,最终以审核结算为准。
@if ($hasBenchmark) 当前基准:{{ $summary['benchmark_label'] }}。@endif
单量按发货月份汇总,安装公司分为万师傅、鲁班系列和其他安装公司。为了让每个月可以横向比较,
安装费统一按最近两个完整月份的公司单均乘以当月各公司实际单量进行预估,不再区分审核和未审核。
切换影响是当前供应商占比与“全部使用万师傅”的预估差额,最终金额以结算为准。
</p>
<section class="installation-company-card" aria-labelledby="installation-company-current-title">
<div class="installation-company-card__head">
<strong id="installation-company-current-title">{{ $currentPeriod ?? '当前月' }} · 安装公司费用分析</strong>
<span>{{ $previousPeriod ?? '上月' }} 对比 · 金额单位:元</span>
</div>
<div class="installation-company-table-wrap">
<table class="installation-company-table is-current">
<thead>
<tr>
<th scope="col">安装公司</th>
<th scope="col" class="is-number">{{ $currentPeriod ?? '当前月' }}单量</th>
<th scope="col">单量占比</th>
<th scope="col" class="is-number">审核覆盖</th>
<th scope="col" class="is-number">已审核金额</th>
<th scope="col" class="is-number">已审核单均</th>
<th scope="col" class="is-number">基准单均</th>
<th scope="col" class="is-number">预估安装费</th>
<th scope="col" class="is-number">{{ $previousPeriod ?? '上月' }}单量</th>
<th scope="col" class="is-number">{{ $previousPeriod ?? '上月' }}已审核金额</th>
<th scope="col" class="is-number">{{ $previousPeriod ?? '上月' }}单均</th>
</tr>
</thead>
<tbody>
@forelse ($vendorRows as $vendor)
<tr>
<td class="is-company">{{ $vendor['label'] }}</td>
<td class="is-number">{{ number_format((int) $vendor['orders']) }}</td>
<td>
<div class="installation-company-share">
<span>{{ $percent($vendor['order_share'] ?? 0) }}%</span>
<span class="installation-company-share__track" aria-hidden="true">
<span class="installation-company-share__fill" style="width: {{ min(100, max(0, (float) ($vendor['order_share'] ?? 0))) }}%"></span>
</span>
</div>
</td>
<td class="is-number">
{{ $percent($vendor['review_rate'] ?? 0) }}%
<span>({{ number_format((int) ($vendor['reviewed_orders'] ?? 0)) }})</span>
</td>
<td class="is-number">¥{{ $money($vendor['settled_amount'] ?? 0) }}</td>
<td class="is-number">¥{{ $money($vendor['unit_cost'] ?? 0) }}</td>
<td class="is-number">
{{ $vendor['benchmark_rate'] === null ? '—' : '¥' . $money($vendor['benchmark_rate']) }}
</td>
<td class="is-number">
{{ $vendor['estimated_amount'] === null ? '—' : '¥' . $money($vendor['estimated_amount']) }}
</td>
<td class="is-number">{{ number_format((int) ($vendor['previous_orders'] ?? 0)) }}</td>
<td class="is-number">¥{{ $money($vendor['previous_settled_amount'] ?? 0) }}</td>
<td class="is-number">¥{{ $money($vendor['previous_unit_cost'] ?? 0) }}</td>
</tr>
@empty
<tr>
<td colspan="11" class="installation-company-empty">所选期间暂无安装公司数据。</td>
</tr>
@endforelse
</tbody>
@if ($vendorRows !== [])
<tfoot>
<tr>
<td>合计</td>
<td class="is-number">{{ number_format((int) ($summary['current_orders'] ?? 0)) }}</td>
<td>100.0%</td>
<td class="is-number">{{ $percent($summary['current_review_rate'] ?? 0) }}%</td>
<td class="is-number">¥{{ $money($summary['current_confirmed_amount'] ?? 0) }}</td>
<td class="is-number">¥{{ $money($summary['current_confirmed_unit_cost'] ?? 0) }}</td>
<td class="is-number">—</td>
<td class="is-number">¥{{ $money($summary['estimated_mixed_amount'] ?? 0) }}</td>
<td class="is-number">{{ number_format((int) ($summary['previous_orders'] ?? 0)) }}</td>
<td class="is-number">¥{{ $money($summary['previous_confirmed_amount'] ?? 0) }}</td>
<td class="is-number">¥{{ $money($summary['previous_confirmed_unit_cost'] ?? 0) }}</td>
</tr>
<tr>
<td colspan="7">同样单量全部使用万师傅的预估成本</td>
<td class="is-number">¥{{ $money($summary['estimated_all_wan_amount'] ?? 0) }}</td>
<td colspan="3">
切换影响
<span class="installation-company-impact {{ $switchImpactDisplay['class'] }}">{{ $switchImpactDisplay['text'] }}</span>
</td>
</tr>
</tfoot>
@endif
</table>
</div>
</section>
<section class="installation-company-card" aria-labelledby="installation-company-monthly-title">
<div class="installation-company-card__head">
<strong id="installation-company-monthly-title">逐月 · 各安装公司单量与已审核金额</strong>
<span>按发货月份;最近月份优先</span>
<strong id="installation-company-monthly-title">月度安装费对比</strong>
<span>按安装公司区分 · 最近月份优先</span>
</div>
<div class="installation-company-table-wrap is-monthly">
<table class="installation-company-table is-monthly">
<thead>
<tr>
<th scope="col">月份</th>
<th scope="col">安装公司</th>
<th scope="col" class="is-number">安装单量</th>
<th scope="col">单量占比</th>
<th scope="col" class="is-number">审核覆盖</th>
<th scope="col" class="is-number">已审核金额</th>
<th scope="col" class="is-number">已审核单均</th>
<th scope="col">万师傅</th>
<th scope="col">鲁班系列</th>
<th scope="col">其他安装公司</th>
<th scope="col" class="is-number">预估安装费</th>
<th scope="col" class="is-number">单均</th>
<th scope="col" class="is-number">安装费环比</th>
</tr>
</thead>
<tbody>
@php($hasMonthlyRows = false)
@foreach (array_reverse($periods) as $period)
@foreach (['wan', 'luban', 'other'] as $vendorKey)
@php($vendor = $period['vendors'][$vendorKey])
@if ((int) $vendor['orders'] > 0)
@php($hasMonthlyRows = true)
<tr>
<td class="is-company">{{ $period['period'] }}</td>
<td>{{ $vendor['label'] }}</td>
<td class="is-number">{{ number_format((int) $vendor['orders']) }}</td>
<td>{{ $percent($vendor['order_share']) }}%</td>
<td class="is-number">
{{ $percent($vendor['review_rate']) }}%
<span>({{ number_format((int) $vendor['reviewed_orders']) }})</span>
@forelse (array_reverse($periods) as $period)
@if ((int) $period['total_orders'] > 0)
<tr>
<td class="is-company">
{{ $period['period'] }}
@if ($period['period'] === $currentPeriod)
<span class="installation-company-pill">当前</span>
@endif
</td>
<td class="is-number">{{ number_format((int) $period['total_orders']) }}</td>
@foreach (['wan', 'luban', 'other'] as $vendorKey)
@php($vendor = $period['vendors'][$vendorKey])
<td>
@if ($vendor['comparable_amount'] === null)
<strong>{{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}%</strong>
<span class="is-muted">暂无预估</span>
@else
<strong>{{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}%</strong>
<span class="installation-company-value">¥{{ $money($vendor['comparable_amount']) }} · 单均 ¥{{ $money($vendor['comparable_unit_cost']) }}</span>
@endif
</td>
<td class="is-number">¥{{ $money($vendor['settled_amount']) }}</td>
<td class="is-number">¥{{ $money($vendor['unit_cost']) }}</td>
</tr>
@endif
@endforeach
@endforeach
@if (! $hasMonthlyRows)
@endforeach
<td class="is-number">
{{ $period['comparable_amount'] === null ? '—' : '¥' . $money($period['comparable_amount']) }}
</td>
<td class="is-number">
{{ $period['comparable_unit_cost'] === null ? '—' : '¥' . $money($period['comparable_unit_cost']) }}
</td>
<td class="is-number">
@if ($period['fee_change_rate'] === null)
—
@else
<span class="installation-company-impact {{ $period['fee_change_rate'] > 0 ? 'is-increase' : ($period['fee_change_rate'] < 0 ? 'is-saving' : 'is-neutral') }}">
{{ $period['fee_change_rate'] > 0 ? '+' : '' }}{{ $percent($period['fee_change_rate']) }}%
</span>
@endif
</td>
</tr>
@endif
@empty
<tr>
<td colspan="7" class="installation-company-empty">所选期间暂无安装公司数据。</td>
<td colspan="8" class="installation-company-empty">所选期间暂无安装公司数据。</td>
</tr>
@endif
@endforelse
</tbody>
</table>
</div>

View File

@ -569,17 +569,16 @@ class ManagementCrudTest extends FeatureTestCase
'range' => '6',
]))
->assertOk()
->assertSeeText('安装公司费用分析')
->assertSeeText('月度安装费对比')
->assertSeeText('万师傅')
->assertSeeText('鲁班系列')
->assertSeeText('供应商切换预估影响')
->assertSeeText('切换安装公司影响')
->assertSeeText('增加 ¥500.00')
->assertSeeText('同样单量全部使用万师傅的预估成本')
->assertSeeText('审核覆盖')
->assertSeeText('50.0%')
->assertSeeText('当前基准')
->assertSeeText('最终以审核结算为准')
->assertSeeText('逐月 · 各安装公司单量与已审核金额')
->assertSeeText('预估安装费')
->assertSeeText('安装费环比')
->assertSeeText('不再区分审核和未审核')
->assertSeeText('最终金额以结算为准')
->assertDontSeeText('审核覆盖')
->assertDontSeeText('平台安装费分析');
}