From 063f5f1a6796dd7380565afe576aad6fddccb663 Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Thu, 26 Nov 2026 15:41:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=89=E8=A3=85=E8=B4=B9=E6=B1=87?= =?UTF-8?q?=E6=80=BB=E5=A2=9E=E5=8A=A0=E6=AF=8F=E6=9C=88=E5=B9=B3=E5=9D=87?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=20(#1464)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InstallationDetailMirrorRepository.php | 57 +-- .../View/InstallationFeeUsagePageData.php | 248 +---------- .../installation-fee-usage.blade.php | 408 ++---------------- tests/Feature/Business/ManagementCrudTest.php | 54 +-- ...InstallationDetailMirrorRepositoryTest.php | 24 +- 5 files changed, 85 insertions(+), 706 deletions(-) diff --git a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php index 433bc303..2bb6b6e4 100644 --- a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php @@ -237,18 +237,12 @@ class InstallationDetailMirrorRepository } /** - * 安装公司使用趋势:发货月份统计使用单量,客服审核月份统计安装费。 - * - * 单量按安装主单 SourceGuid 和发货时间归属;金额与安装费汇总共用 - * 客服审核时间和明细结算金额口径。两种指标使用各自独立的日期维度, - * 避免未审核的新供应商单量被审核批次堆积掩盖。 + * 按客服审核月份汇总各安装公司的审核单量和结算明细金额。 * * @return array{ * ready:bool, * rows:list, - * totals:list, - * order_rows:list, - * order_totals:list + * totals:list * } */ public function feeUsageTrend(string $fromMonth, string $toMonth): array @@ -302,33 +296,6 @@ class InstallationDetailMirrorRepository ->values() ->all(); - $usagePeriodSql = $connection->getDriverName() === 'sqlite' - ? "strftime('%Y-%m', v.ShipTIme)" - : "DATE_FORMAT(v.ShipTIme, '%Y-%m')"; - $usageCompanySql = "COALESCE(NULLIF(TRIM(v.installCompanyName), ''), '未填写安装公司')"; - $usageBase = (clone $main) - ->select(['v.SourceGuid', 'v.ShipTIme', 'v.installCompanyName']) - ->whereNotNull('v.ShipTIme') - ->where('v.ShipTIme', '>=', $start) - ->where('v.ShipTIme', '<', $endExclusive); - $orderRows = (clone $usageBase) - ->selectRaw($usagePeriodSql . ' AS period') - ->selectRaw($usageCompanySql . ' AS installation_company') - ->selectRaw('COUNT(DISTINCT v.SourceGuid) AS orders') - ->groupByRaw($usagePeriodSql . ', ' . $usageCompanySql) - ->orderByRaw($usagePeriodSql) - ->orderByRaw($usageCompanySql) - ->get() - ->map(static fn (object $row): array => [ - 'period' => trim((string) ($row->period ?? '')), - 'installation_company' => trim((string) ($row->installation_company ?? '未填写安装公司')), - 'orders' => (int) ($row->orders ?? 0), - ]) - ->filter(static fn (array $row): bool => - preg_match('/^\d{4}-\d{2}$/', $row['period']) === 1) - ->values() - ->all(); - $totals = (clone $base) ->selectRaw($companySql . ' AS installation_company') ->selectRaw('COUNT(DISTINCT install_main.SourceGuid) AS orders') @@ -344,25 +311,7 @@ class InstallationDetailMirrorRepository ->values() ->all(); - $orderTotals = []; - foreach ($orderRows as $row) { - $company = $row['installation_company']; - $orderTotals[$company] ??= [ - 'installation_company' => $company, - 'orders' => 0, - ]; - $orderTotals[$company]['orders'] += (int) $row['orders']; - } - ksort($orderTotals, SORT_STRING); - $orderTotals = array_values($orderTotals); - - return [ - 'ready' => true, - 'rows' => $rows, - 'totals' => $totals, - 'order_rows' => $orderRows, - 'order_totals' => $orderTotals, - ]; + return ['ready' => true, 'rows' => $rows, 'totals' => $totals]; } /** diff --git a/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php b/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php index 956c92c8..ccba5333 100644 --- a/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php +++ b/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php @@ -6,7 +6,7 @@ use Illuminate\Support\Carbon; use Modules\EcommerceFinance\Repositories\InstallationDetailMirrorRepository; use Throwable; -/** 安装费汇总:发货月份判断使用切换,客服审核月份归集安装费。 */ +/** 安装费汇总:按客服审核月份展示安装费和平均每单安装费。 */ class InstallationFeeUsagePageData { public const RANGE_OPTIONS = [ @@ -42,7 +42,6 @@ class InstallationFeeUsagePageData $toMonth, $this->emptyPeriods($fromMonth, $toMonth), [], - null, '安装公司趋势暂时无法读取,请稍后重试。', ); } @@ -55,22 +54,17 @@ class InstallationFeeUsagePageData $toMonth, $this->emptyPeriods($fromMonth, $toMonth), [], - null, '安装明细共享镜像尚未完成首次同步。', ); } - $usageRows = array_key_exists('order_rows', $result) ? $result['order_rows'] : null; - $usageTotals = array_key_exists('order_totals', $result) ? $result['order_totals'] : null; - return $this->payload( $range, $rangeLabel, $fromMonth, $toMonth, - $this->buildPeriods($fromMonth, $toMonth, $result['rows'], $usageRows), + $this->buildPeriods($fromMonth, $toMonth, $result['rows']), $result['totals'], - $usageTotals, ); } @@ -87,16 +81,8 @@ class InstallationFeeUsagePageData return [$from->format('Y-m'), $current->format('Y-m')]; } - /** - * @param list $rows - * @param list|null $usageRows - */ - private function buildPeriods( - string $fromMonth, - string $toMonth, - array $rows, - ?array $usageRows = null, - ): array + /** @param list $rows */ + private function buildPeriods(string $fromMonth, string $toMonth, array $rows): array { $periods = $this->emptyPeriods($fromMonth, $toMonth); $periodIndex = []; @@ -110,54 +96,16 @@ class InstallationFeeUsagePageData continue; } - $key = $this->vendorKey($row['installation_company']); $index = $periodIndex[$period]; - $periods[$index]['vendors'][$key]['fee_orders'] += (int) $row['orders']; - $periods[$index]['vendors'][$key]['amount'] += (float) $row['amount']; - $periods[$index]['source_companies'][$row['installation_company']] = true; + $periods[$index]['total_fee_orders'] += (int) $row['orders']; + $periods[$index]['total_amount'] += (float) $row['amount']; } - foreach ($usageRows ?? $rows as $row) { - $period = $row['period']; - if (! isset($periodIndex[$period])) { - continue; - } - - $key = $this->vendorKey($row['installation_company']); - $index = $periodIndex[$period]; - $periods[$index]['vendors'][$key]['orders'] += (int) $row['orders']; - $periods[$index]['source_companies'][$row['installation_company']] = true; - } - - $previousPrimaryKey = null; - $previousPrimaryLabel = null; foreach ($periods as &$period) { - $period['total_orders'] = (int) array_sum(array_column($period['vendors'], 'orders')); - $period['total_fee_orders'] = (int) array_sum(array_column($period['vendors'], 'fee_orders')); - $period['total_amount'] = round(array_sum(array_column($period['vendors'], 'amount')), 2); - $period['source_companies'] = array_keys($period['source_companies']); - - foreach ($period['vendors'] as &$vendor) { - $vendor['amount'] = round((float) $vendor['amount'], 2); - $vendor['order_share'] = $this->share((int) $vendor['orders'], $period['total_orders']); - $vendor['amount_share'] = $this->share((float) $vendor['amount'], $period['total_amount']); - } - unset($vendor); - - $primary = $this->primaryVendor($period['vendors']); - $period['primary_key'] = $primary['key']; - $period['primary_label'] = $primary['label']; - $period['primary_orders'] = $primary['orders']; - $period['primary_share'] = $primary['share']; - $period['transition_from'] = null; - - if ($period['total_orders'] > 0) { - if ($previousPrimaryKey !== null && $primary['key'] !== $previousPrimaryKey) { - $period['transition_from'] = $previousPrimaryLabel; - } - $previousPrimaryKey = $primary['key']; - $previousPrimaryLabel = $primary['label']; - } + $period['total_amount'] = round((float) $period['total_amount'], 2); + $period['average_fee'] = $period['total_fee_orders'] > 0 + ? round($period['total_amount'] / $period['total_fee_orders'], 2) + : 0.0; } unset($period); @@ -173,20 +121,9 @@ class InstallationFeeUsagePageData $periods[] = [ 'period' => $cursor->format('Y-m'), 'short_label' => $cursor->format('m') . '月', - 'total_orders' => 0, 'total_fee_orders' => 0, 'total_amount' => 0.0, - 'vendors' => [ - 'wan' => ['key' => 'wan', 'label' => '万师傅', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - 'luban' => ['key' => 'luban', 'label' => '鲁班到家', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - 'other' => ['key' => 'other', 'label' => '其他安装公司', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - ], - 'source_companies' => [], - 'primary_key' => '', - 'primary_label' => '无安装单', - 'primary_orders' => 0, - 'primary_share' => 0.0, - 'transition_from' => null, + 'average_fee' => 0.0, ]; $cursor->addMonthNoOverflow(); } @@ -194,107 +131,16 @@ class InstallationFeeUsagePageData return $periods; } - /** - * @param list $feeTotals - * @param list|null $usageTotals - */ - private function buildSummary(array $feeTotals, ?array $usageTotals, array $periods): array + /** @param list $feeTotals */ + private function buildSummary(array $feeTotals, array $periods): array { - $vendors = $this->vendorDefinition(); - foreach ($feeTotals as $row) { - $key = $this->vendorKey($row['installation_company']); - $vendors[$key]['fee_orders'] += (int) $row['orders']; - $vendors[$key]['amount'] += (float) $row['amount']; - } - foreach ($usageTotals ?? $feeTotals as $row) { - $key = $this->vendorKey($row['installation_company']); - $vendors[$key]['orders'] += (int) $row['orders']; - } - - $totalOrders = (int) array_sum(array_column($vendors, 'orders')); - $totalFeeOrders = (int) array_sum(array_column($vendors, 'fee_orders')); - $totalAmount = round(array_sum(array_column($vendors, 'amount')), 2); - foreach ($vendors as &$vendor) { - $vendor['amount'] = round((float) $vendor['amount'], 2); - $vendor['order_share'] = $this->share((int) $vendor['orders'], $totalOrders); - $vendor['amount_share'] = $this->share((float) $vendor['amount'], $totalAmount); - } - unset($vendor); - - $nonEmptyPeriods = array_values(array_filter( - $periods, - static fn (array $period): bool => $period['total_orders'] > 0, - )); - $latest = $nonEmptyPeriods === [] ? null : end($nonEmptyPeriods); - $previous = count($nonEmptyPeriods) < 2 - ? null - : $nonEmptyPeriods[count($nonEmptyPeriods) - 2]; - - $transitions = []; - foreach ($periods as $period) { - if ($period['transition_from'] !== null) { - $transitions[] = [ - 'period' => $period['period'], - 'from' => $period['transition_from'], - 'to' => $period['primary_label'], - ]; - } - } - $lastTransition = $transitions === [] ? null : end($transitions); - - $latestKey = (string) ($latest['primary_key'] ?? ''); - $latestLabel = (string) ($latest['primary_label'] ?? '无安装单'); - if ($latestKey === 'luban') { - $switchStatus = $lastTransition && $lastTransition['from'] === '万师傅' - ? '已切换至鲁班到家' - : '鲁班到家当前主导'; - } elseif ($latestKey === 'wan') { - $switchStatus = $lastTransition && $lastTransition['from'] === '鲁班到家' - ? '已切回万师傅' - : '仍以万师傅为主'; - } elseif ($latestKey === 'tie') { - $switchStatus = '两家当前并列'; - } elseif ($latestKey === 'other') { - $switchStatus = '其他安装公司主导'; - } else { - $switchStatus = '所选期间暂无安装单'; - } - - $latestWan = $latest['vendors']['wan'] ?? ['orders' => 0, 'order_share' => 0.0]; - $latestLuban = $latest['vendors']['luban'] ?? ['orders' => 0, 'order_share' => 0.0]; - $switchNote = $latest === null - ? '所选期间没有发货安装单,无法判断安装公司切换。' - : sprintf( - '%s 主安装公司为%s,单量占比 %s%%;万师傅 %s%%、鲁班到家 %s%%。', - $latest['period'], - $latestLabel, - $this->percent($latest['primary_share']), - $this->percent($latestWan['order_share']), - $this->percent($latestLuban['order_share']), - ); - if ($lastTransition !== null) { - $switchNote .= sprintf( - '最近一次变化:%s 从%s切到%s。', - $lastTransition['period'], - $lastTransition['from'], - $lastTransition['to'], - ); - } + $totalFeeOrders = (int) array_sum(array_column($feeTotals, 'orders')); + $totalAmount = round(array_sum(array_column($feeTotals, 'amount')), 2); return [ - 'total_orders' => $totalOrders, 'total_fee_orders' => $totalFeeOrders, 'total_amount' => $totalAmount, 'average_fee' => $totalFeeOrders > 0 ? round($totalAmount / $totalFeeOrders, 2) : 0.0, - 'vendors' => array_values($vendors), - 'latest_period' => $latest['period'] ?? null, - 'latest_primary' => $latestLabel, - 'latest_primary_share' => $latest['primary_share'] ?? 0.0, - 'previous_period' => $previous['period'] ?? null, - 'previous_primary' => $previous['primary_label'] ?? null, - 'switch_status' => $switchStatus, - 'switch_note' => $switchNote, - 'last_transition' => $lastTransition, 'has_negative_fee' => collect($periods)->contains( static fn (array $period): bool => (float) $period['total_amount'] < -0.004, ), @@ -308,7 +154,6 @@ class InstallationFeeUsagePageData string $toMonth, array $periods, array $totals, - ?array $usageTotals = null, ?string $error = null, ): array { return [ @@ -320,70 +165,9 @@ class InstallationFeeUsagePageData 'installationFeeUsageToMonth' => $toMonth, 'installationFeeUsagePeriods' => $periods, 'installationFeeUsageSummary' => $error === null - ? $this->buildSummary($totals, $usageTotals, $periods) + ? $this->buildSummary($totals, $periods) : [], 'installationFeeUsageError' => $error, ]; } - - private function vendorKey(string $company): string - { - if (str_contains($company, '万师傅')) { - return 'wan'; - } - if (str_contains($company, '鲁班')) { - return 'luban'; - } - - return 'other'; - } - - private function vendorDefinition(): array - { - return [ - 'wan' => ['key' => 'wan', 'label' => '万师傅', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - 'luban' => ['key' => 'luban', 'label' => '鲁班到家', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - 'other' => ['key' => 'other', 'label' => '其他安装公司', 'orders' => 0, 'fee_orders' => 0, 'amount' => 0.0], - ]; - } - - /** @return array{key:string,label:string,orders:int,share:float} */ - private function primaryVendor(array $vendors): array - { - $ordered = array_values($vendors); - usort($ordered, static fn (array $left, array $right): int => - [$right['orders'], $right['amount']] <=> [$left['orders'], $left['amount']]); - $first = $ordered[0]; - if ((int) $first['orders'] === 0) { - return ['key' => '', 'label' => '无安装单', 'orders' => 0, 'share' => 0.0]; - } - - $second = $ordered[1]; - $firstTwoKeys = [$first['key'], $second['key']]; - sort($firstTwoKeys); - if ((int) $second['orders'] === (int) $first['orders'] - && $firstTwoKeys === ['luban', 'wan']) { - return ['key' => 'tie', 'label' => '万师傅 / 鲁班到家并列', 'orders' => (int) $first['orders'], 'share' => 50.0]; - } - - $total = array_sum(array_column($ordered, 'orders')); - return [ - 'key' => (string) $first['key'], - 'label' => (string) $first['label'], - 'orders' => (int) $first['orders'], - 'share' => $this->share((int) $first['orders'], (int) $total), - ]; - } - - private function share(int|float $value, int|float $total): float - { - return abs((float) $total) > 0.00001 - ? round(((float) $value / (float) $total) * 100, 1) - : 0.0; - } - - private function percent(float $value): string - { - return number_format($value, 1); - } } diff --git a/resources/views/business/pages/financial-operations/installation-fee-usage.blade.php b/resources/views/business/pages/financial-operations/installation-fee-usage.blade.php index ab38f99e..c9a5ade5 100644 --- a/resources/views/business/pages/financial-operations/installation-fee-usage.blade.php +++ b/resources/views/business/pages/financial-operations/installation-fee-usage.blade.php @@ -6,16 +6,10 @@ $rangeLabel = $installationFeeUsageRangeLabel ?? ''; $error = $installationFeeUsageError ?? null; $currentMonth = now()->format('Y-m'); - $latestPeriod = $summary['latest_period'] ?? null; - $latestPeriodData = $latestPeriod === null - ? null - : collect($periods)->firstWhere('period', $latestPeriod); - $maxOrders = max(1, (int) collect($periods)->max('total_orders')); - $maxFee = max(1.0, (float) collect($periods)->max(static fn (array $period): float => - max(0, (float) $period['total_amount']))); + $maxAverageFee = max(1.0, (float) collect($periods)->max(static fn (array $period): float => + max(0, (float) $period['average_fee']))); $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); $cssPercent = static fn (mixed $value): string => number_format(max(0, (float) $value), 3, '.', ''); @endphp @@ -129,8 +123,7 @@ color: #ffffff; } - .installation-usage-button:focus-visible, - .installation-usage-metric:focus-visible { + .installation-usage-button:focus-visible { outline: 3px solid rgba(133, 102, 50, 0.2); outline-offset: 1px; } @@ -151,85 +144,9 @@ font-size: 0.75rem; } - .installation-usage-switch { - margin-top: 0.75rem; - padding: 1rem; - border: 1px solid var(--usage-border); - border-left: 3px solid var(--usage-accent); - border-radius: 0.5rem; - background: var(--usage-soft); - } - - .installation-usage-switch__head { - display: flex; - align-items: center; - justify-content: space-between; - gap: 1rem; - flex-wrap: wrap; - } - - .installation-usage-switch__title { - display: inline-flex; - align-items: center; - gap: 0.45rem; - font-size: 0.8125rem; - font-weight: 700; - } - - .installation-usage-switch__title .material-icons-outlined { - color: var(--usage-accent-dark); - font-size: 1.15rem; - } - - .installation-usage-status { - display: inline-flex; - min-height: 1.75rem; - align-items: center; - padding: 0 0.65rem; - border: 1px solid rgba(133, 102, 50, 0.42); - border-radius: 999px; - background: #ffffff; - color: var(--usage-accent-dark); - font-size: 0.75rem; - font-weight: 700; - } - - .installation-usage-switch__facts { - display: grid; - grid-template-columns: repeat(4, minmax(8rem, 1fr)); - gap: 0.75rem; - margin-top: 0.85rem; - } - - .installation-usage-fact { - display: flex; - min-width: 0; - flex-direction: column; - gap: 0.18rem; - } - - .installation-usage-fact span { - color: var(--usage-muted); - font-size: 0.6875rem; - } - - .installation-usage-fact strong { - color: var(--usage-ink); - font-size: 0.875rem; - font-weight: 700; - font-variant-numeric: tabular-nums; - } - - .installation-usage-switch__note { - margin: 0.85rem 0 0; - color: var(--usage-muted); - font-size: 0.75rem; - line-height: 1.65; - } - .installation-usage-kpis { display: grid; - grid-template-columns: repeat(4, minmax(0, 1fr)); + grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0.75rem; border: 1px solid var(--usage-border); border-radius: 0.5rem; @@ -308,67 +225,6 @@ font-size: 0.6875rem; } - .installation-usage-metrics { - display: inline-flex; - padding: 0.18rem; - border: 1px solid var(--usage-border); - border-radius: 0.5rem; - background: #f7f4ed; - } - - .installation-usage-metric { - height: 1.85rem; - padding: 0 0.7rem; - border: 0; - border-radius: 0.35rem; - background: transparent; - color: var(--usage-muted); - cursor: pointer; - font: inherit; - font-size: 0.6875rem; - font-weight: 600; - } - - .installation-usage-metric[aria-pressed="true"] { - background: #ffffff; - color: var(--usage-accent-dark); - box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08); - } - - .installation-usage-legend { - display: flex; - align-items: center; - gap: 1rem; - flex-wrap: wrap; - padding: 0.7rem 1rem 0; - color: var(--usage-muted); - font-size: 0.6875rem; - } - - .installation-usage-legend__item { - display: inline-flex; - align-items: center; - gap: 0.35rem; - } - - .installation-usage-legend__swatch { - width: 0.65rem; - height: 0.65rem; - border-radius: 2px; - } - - .installation-usage-legend__swatch.is-wan { - background: #856632; - } - - .installation-usage-legend__swatch.is-luban { - background: #b9954f; - } - - .installation-usage-legend__swatch.is-other { - background: #8f8b82; - } - .installation-usage-chart-scroll { overflow-x: auto; overscroll-behavior-inline: contain; @@ -463,32 +319,14 @@ transition: height 160ms ease; } - .installation-usage-board[data-metric="fee"] .installation-usage-chart__bar { - height: var(--fee-height); - } - - .installation-usage-chart__segment { - width: 100%; - height: var(--orders-share); + .installation-usage-chart__bar.is-average { + height: var(--average-height); min-height: 0; - flex: 0 0 auto; - transition: height 160ms ease; - } - - .installation-usage-board[data-metric="fee"] .installation-usage-chart__segment { - height: var(--fee-share); - } - - .installation-usage-chart__segment.is-wan { - background: #856632; - } - - .installation-usage-chart__segment.is-luban { background: #b9954f; } - .installation-usage-chart__segment.is-other { - background: #8f8b82; + .installation-usage-chart__column.is-current .installation-usage-chart__bar.is-average { + background: var(--usage-accent-dark); } .installation-usage-chart__label { @@ -534,7 +372,7 @@ .installation-usage-table { width: 100%; - min-width: 58rem; + min-width: 42rem; border-collapse: collapse; font-size: 0.75rem; font-variant-numeric: tabular-nums; @@ -574,27 +412,6 @@ white-space: nowrap; } - .installation-usage-table__vendor { - min-width: 10rem; - } - - .installation-usage-table__vendor strong, - .installation-usage-table__vendor span { - display: block; - } - - .installation-usage-table__vendor strong { - color: var(--usage-ink); - font-weight: 600; - } - - .installation-usage-table__vendor span { - margin-top: 0.12rem; - color: var(--usage-muted); - font-size: 0.6875rem; - white-space: nowrap; - } - .installation-usage-pill { display: inline-flex; align-items: center; @@ -609,11 +426,6 @@ white-space: nowrap; } - .installation-usage-table__primary { - min-width: 11rem; - white-space: nowrap; - } - .installation-usage-empty { padding: 3rem 1rem; color: var(--usage-muted); @@ -621,25 +433,11 @@ } @media (prefers-reduced-motion: reduce) { - .installation-usage-chart__bar, - .installation-usage-chart__segment { - transition: none; - } + .installation-usage-chart__bar { transition: none; } } @media (max-width: 900px) { - .installation-usage-switch__facts, - .installation-usage-kpis { - grid-template-columns: repeat(2, minmax(0, 1fr)); - } - - .installation-usage-kpi:nth-child(2) { - border-right: 0; - } - - .installation-usage-kpi:nth-child(-n + 2) { - border-bottom: 1px solid var(--usage-border); - } + .installation-usage-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } } @media (max-width: 600px) { @@ -660,7 +458,6 @@ flex: 1 1 auto; } - .installation-usage-switch__facts, .installation-usage-kpis { grid-template-columns: 1fr; } @@ -688,7 +485,7 @@
时间口径 - 单量看发货时间 · 费用看审核时间 + 客服审核时间
当前范围 @@ -696,7 +493,7 @@
- 单量按发货月份 · 安装费按客服审核月份 + 安装费与平均费均按客服审核月份 - -
- - -
- 万师傅 - 鲁班到家 - 其他安装公司 - 鲁班大师与鲁班到家按同一系列统计
@@ -814,75 +545,53 @@ class="installation-usage-chart" style="--period-count: {{ max(1, count($periods)) }}" role="img" - aria-label="安装公司月度使用趋势图,{{ $rangeLabel }}" + aria-label="每月平均安装费趋势图,{{ $rangeLabel }}" >
- 安装单量 - @if (collect($periods)->sum('total_orders') > 0) + 平均安装费(元/单) + @if (collect($periods)->sum('total_fee_orders') > 0)
@foreach ($periods as $period) @php - $positiveFeeTotal = max(0, (float) $period['total_amount']); - $ordersHeight = ((int) $period['total_orders'] / $maxOrders) * 100; - $feeHeight = (max(0, (float) $period['total_amount']) / $maxFee) * 100; - $wan = $period['vendors']['wan']; - $luban = $period['vendors']['luban']; - $other = $period['vendors']['other']; - $ordersTotal = max(1, (int) $period['total_orders']); + $averageHeight = (max(0, (float) $period['average_fee']) / $maxAverageFee) * 100; @endphp
$period['period'] === $currentMonth])>
- - - -
+ class="installation-usage-chart__bar is-average" + style="--average-height: {{ $cssPercent($averageHeight) }}%" + title="{{ $period['period'] }}:平均安装费 ¥{{ $money($period['average_fee']) }}/单;审核安装费 {{ $moneyWan($period['total_amount']) }} 万;审核 {{ number_format((int) $period['total_fee_orders']) }} 单" + >
{{ $period['short_label'] }}
@endforeach
@else -
所选期间暂无发货安装单。
+
所选期间暂无已审核安装费。
@endif

- 口径:安装单量按安装主单去重,并按发货时间归属月份,用于判断安装公司使用切换;安装费取安装明细子表结算金额, - 按客服审核时间归属月份,未审核安装费不计入金额趋势。“鲁班大师”和“鲁班到家”合并为鲁班系列,其他安装公司合并展示。 + 口径:平均安装费 = 当月客服审核通过的安装明细结算金额 ÷ 当月审核安装单量。未审核安装费不计入; + 当前月份标记为“截至当前”,金额会随审核进度继续增加。 @if (! empty($summary['has_negative_fee'])) - 存在负数安装费时,趋势图的费用高度只堆叠正数金额,表格合计仍按实际金额展示。 + 存在负数安装费时,趋势图柱高只展示正数平均值,详情表仍按实际金额计算。 @endif

-
+
- + - - - - + @@ -894,57 +603,16 @@ 截至当前 @endif - + - @foreach (['wan', 'luban', 'other'] as $vendorKey) - @php($vendor = $period['vendors'][$vendorKey]) - - @endforeach - + @empty - + @endforelse
月份发货单量审核安装单量 审核安装费(万元)万师傅鲁班到家其他安装公司主安装公司平均安装费(元/单)
{{ number_format((int) $period['total_orders']) }}{{ number_format((int) $period['total_fee_orders']) }} {{ $moneyWan($period['total_amount']) }} - {{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}% - 审核 {{ number_format((int) $vendor['fee_orders']) }} 单 · {{ $moneyWan($vendor['amount']) }} 万元 · 费用占比 {{ $percent($vendor['amount_share']) }}% - - {{ $period['primary_label'] }} - @if ($period['transition_from'] !== null) - 切换 - @endif - ¥{{ $money($period['average_fee']) }}
所选期间暂无安装公司趋势数据。所选期间暂无已审核安装费。
- - diff --git a/tests/Feature/Business/ManagementCrudTest.php b/tests/Feature/Business/ManagementCrudTest.php index a6e2a231..e14010b9 100644 --- a/tests/Feature/Business/ManagementCrudTest.php +++ b/tests/Feature/Business/ManagementCrudTest.php @@ -491,7 +491,7 @@ class ManagementCrudTest extends FeatureTestCase ->assertJsonPath('change_rate', 25.0); } - public function testInstallationFeeUsagePageShowsVendorSwitchTrend(): void + public function testInstallationFeeUsagePageShowsMonthlyAverageFee(): void { $previousMonth = now()->subMonthNoOverflow()->format('Y-m'); $currentMonth = now()->format('Y-m'); @@ -515,40 +515,13 @@ class ManagementCrudTest extends FeatureTestCase 'period' => $currentMonth, 'installation_company' => '万师傅', 'orders' => 2, - 'amount' => 200.00, + 'amount' => 400.00, ], ], 'totals' => [ - ['installation_company' => '万师傅', 'orders' => 10, 'amount' => 1000.00], + ['installation_company' => '万师傅', 'orders' => 10, 'amount' => 1200.00], ['installation_company' => '鲁班到家', 'orders' => 2, 'amount' => 200.00], ], - 'order_rows' => [ - [ - 'period' => $previousMonth, - 'installation_company' => '万师傅', - 'orders' => 8, - ], - [ - 'period' => $previousMonth, - 'installation_company' => '鲁班到家', - 'orders' => 2, - ], - [ - 'period' => $currentMonth, - 'installation_company' => '万师傅', - 'orders' => 2, - ], - [ - 'period' => $currentMonth, - 'installation_company' => '鲁班大师', - 'orders' => 8, - ], - ], - 'order_totals' => [ - ['installation_company' => '万师傅', 'orders' => 10], - ['installation_company' => '鲁班到家', 'orders' => 2], - ['installation_company' => '鲁班大师', 'orders' => 8], - ], ]); $this->app->instance(InstallationDetailMirrorRepository::class, $mirror); @@ -560,18 +533,17 @@ class ManagementCrudTest extends FeatureTestCase 'range' => '6', ])) ->assertOk() - ->assertSeeText('安装公司切换判断') - ->assertSeeText('已切换至鲁班到家') + ->assertDontSeeText('安装公司切换判断') + ->assertDontSeeText('最新月份') ->assertSeeText('安装费合计') - ->assertSeeText('安装公司使用趋势') - ->assertSeeText('万师傅') - ->assertSeeText('鲁班到家') - ->assertSeeText('鲁班大师与鲁班到家按同一系列统计') - ->assertSee('data-installation-fee-usage-board', false) - ->assertSee('data-installation-usage-metric="fee"', false) - ->assertSeeText('单量看发货时间') - ->assertSeeText('审核安装费') - ->assertSeeText('未审核安装费不计入金额趋势'); + ->assertSeeText('审核安装单量') + ->assertSeeText('每月平均安装费') + ->assertSeeText('平均每单安装费') + ->assertSeeText('¥100.00') + ->assertSeeText('¥200.00') + ->assertSeeText('12 单') + ->assertSeeText('客服审核时间') + ->assertSeeText('未审核安装费不计入'); } public function testLegacyStandaloneInstallationFeeSummaryRedirectsToSubpage(): void diff --git a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php index 0c8e1462..66ec7fef 100644 --- a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php @@ -175,7 +175,6 @@ class InstallationDetailMirrorRepositoryTest extends TestCase ['Id'=>213,'SourceGuid'=>'trend-wan-3','OrderNum'=>'WAN-3','shop_name'=>'测试店','SubmitTime'=>'2026-07-01','ShipTIme'=>'2026-07-02','installCompanyName'=>'万师傅'], ['Id'=>214,'SourceGuid'=>'trend-luban-2','OrderNum'=>'LUBAN-2','shop_name'=>'测试店','SubmitTime'=>'2026-07-03','ShipTIme'=>'2026-07-04','installCompanyName'=>'鲁班到家'], ['Id'=>215,'SourceGuid'=>'trend-luban-3','OrderNum'=>'LUBAN-3','shop_name'=>'测试店','SubmitTime'=>'2026-07-05','ShipTIme'=>'2026-07-06','installCompanyName'=>'鲁班大师'], - ['Id'=>216,'SourceGuid'=>'trend-luban-unreviewed','OrderNum'=>'LUBAN-4','shop_name'=>'测试店','SubmitTime'=>'2026-07-07','ShipTIme'=>'2026-07-08','installCompanyName'=>'鲁班到家'], ]); DB::connection('business_mirror')->table('fixture_items')->insert([ ['Id'=>310,'guid'=>'trend-wan-1','shopproid'=>'P1','kfshTime'=>'2026-06-10 10:00:00','settleItemAmount'=>10.00], @@ -192,10 +191,6 @@ class InstallationDetailMirrorRepositoryTest extends TestCase static fn (array $row): string => $row['period'] . '|' . $row['installation_company'], ); $totals = collect($result['totals'])->keyBy('installation_company'); - $orderRows = collect($result['order_rows'])->keyBy( - static fn (array $row): string => $row['period'] . '|' . $row['installation_company'], - ); - $orderTotals = collect($result['order_totals'])->keyBy('installation_company'); $this->assertTrue($result['ready']); $this->assertSame(2, $rows['2026-06|万师傅']['orders']); @@ -211,10 +206,21 @@ class InstallationDetailMirrorRepositoryTest extends TestCase $this->assertSame(45.0, $totals['鲁班到家']['amount']); $this->assertSame(1, $totals['鲁班大师']['orders']); $this->assertSame(30.0, $totals['鲁班大师']['amount']); - $this->assertSame(2, $orderRows['2026-07|鲁班到家']['orders']); - $this->assertSame(1, $orderRows['2026-07|鲁班大师']['orders']); - $this->assertSame(3, $orderTotals['鲁班到家']['orders']); - $this->assertSame(1, $orderTotals['鲁班大师']['orders']); + $this->assertSame(31.67, $this->installationFeeUsageAverageFee($result['rows'], '2026-06')); + $this->assertSame(26.67, $this->installationFeeUsageAverageFee($result['rows'], '2026-07')); + } + + /** @param list $rows */ + private function installationFeeUsageAverageFee(array $rows, string $period): float + { + $periodRows = array_values(array_filter( + $rows, + static fn (array $row): bool => $row['period'] === $period, + )); + $orders = array_sum(array_column($periodRows, 'orders')); + $amount = array_sum(array_column($periodRows, 'amount')); + + return round($amount / $orders, 2); } public function test_monthly_settlement_buckets_only_include_approved_customer_reviews(): void