diff --git a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php index 1dbc3a15..c3d003d3 100644 --- a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php @@ -225,7 +225,7 @@ class InstallationDetailMirrorRepository } /** - * 按发货月份和安装公司汇总安装单量,并返回已审核结算金额。 + * 按客服审核月份和安装公司汇总实际安装单量及结算明细金额。 * * @return array{ * ready:bool, @@ -233,12 +233,11 @@ class InstallationDetailMirrorRepository * period:string, * installation_company:string, * orders:int, - * reviewed_orders:int, - * settled_amount:float + * amount:float * }> * } */ - public function installationCompanyFeeUsageTrend(string $fromMonth, string $toMonth): array + public function installationCompanyActualFeeTrend(string $fromMonth, string $toMonth): array { $dataset = $this->datasets->get(self::DATASET); $items = $this->datasets->get(self::ITEM_DATASET); @@ -257,40 +256,23 @@ class InstallationDetailMirrorRepository $endExclusive = \Illuminate\Support\Carbon::parse($toMonth . '-01') ->addMonth() ->toDateString(); - $latest = $connection->table($dataset->targetTable()) - ->selectRaw('MAX(Id) AS id') - ->groupBy('SourceGuid'); - $main = $connection->table($dataset->targetTable() . ' AS install_main') - ->joinSub($latest, 'latest', static fn ($join) => - $join->on('latest.id', '=', 'install_main.Id')) - ->select([ - 'install_main.SourceGuid', - 'install_main.ShipTIme', - 'install_main.shop_name', - 'install_main.installCompanyName', - ]) - ->whereNotNull('install_main.ShipTIme') - ->where('install_main.ShipTIme', '>=', $start) - ->where('install_main.ShipTIme', '<', $endExclusive); - - $itemReview = $connection->table($items->targetTable() . ' AS item') - ->selectRaw('item.guid') - ->selectRaw('ROUND(SUM(CAST(item.settleItemAmount AS DECIMAL(18,2))), 2) AS settled_amount') - ->selectRaw('MAX(CASE WHEN item.kfshTime IS NOT NULL THEN 1 ELSE 0 END) AS reviewed') - ->groupBy('item.guid'); - + $main = $this->latestFeeMainQuery($connection, $dataset); $periodSql = $connection->getDriverName() === 'sqlite' - ? "strftime('%Y-%m', install_main.ShipTIme)" - : "DATE_FORMAT(install_main.ShipTIme, '%Y-%m')"; + ? "strftime('%Y-%m', i.kfshTime)" + : "DATE_FORMAT(i.kfshTime, '%Y-%m')"; $companySql = "COALESCE(NULLIF(TRIM(install_main.installCompanyName), ''), '未填写安装公司')"; - $rows = (clone $main) - ->leftJoinSub($itemReview, 'item_review', static fn ($join) => - $join->on('item_review.guid', '=', 'install_main.SourceGuid')) + $base = $connection->table($items->targetTable() . ' AS i') + ->joinSub($main, 'install_main', static fn ($join) => + $join->on('install_main.SourceGuid', '=', 'i.guid')) + ->whereNotNull('i.kfshTime') + ->where('i.kfshTime', '>=', $start) + ->where('i.kfshTime', '<', $endExclusive); + + $rows = (clone $base) ->selectRaw($periodSql . ' AS period') ->selectRaw($companySql . ' AS installation_company') - ->selectRaw('COUNT(*) AS orders') - ->selectRaw('SUM(CASE WHEN item_review.reviewed = 1 THEN 1 ELSE 0 END) AS reviewed_orders') - ->selectRaw('ROUND(COALESCE(SUM(item_review.settled_amount), 0), 2) AS settled_amount') + ->selectRaw('COUNT(DISTINCT install_main.SourceGuid) AS orders') + ->selectRaw('ROUND(SUM(CAST(i.settleItemAmount AS DECIMAL(18,2))), 2) AS amount') ->groupByRaw($periodSql . ', ' . $companySql) ->orderByRaw($periodSql) ->orderByRaw($companySql) @@ -299,8 +281,7 @@ class InstallationDetailMirrorRepository 'period' => trim((string) ($row->period ?? '')), 'installation_company' => trim((string) ($row->installation_company ?? '未填写安装公司')), 'orders' => (int) ($row->orders ?? 0), - 'reviewed_orders' => (int) ($row->reviewed_orders ?? 0), - 'settled_amount' => round((float) ($row->settled_amount ?? 0), 2), + 'amount' => round((float) ($row->amount ?? 0), 2), ]) ->filter(static fn (array $row): bool => preg_match('/^\d{4}-\d{2}$/', $row['period']) === 1) diff --git a/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php b/modules/EcommerceFinance/View/InstallationFeeUsagePageData.php index 19e35d5d..054d0f29 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 = [ @@ -31,7 +31,7 @@ class InstallationFeeUsagePageData $rangeLabel = $fromMonth . ' 至 ' . $toMonth; try { - $result = $this->repository->installationCompanyFeeUsageTrend($fromMonth, $toMonth); + $result = $this->repository->installationCompanyActualFeeTrend($fromMonth, $toMonth); } catch (Throwable $exception) { report($exception); @@ -42,7 +42,7 @@ class InstallationFeeUsagePageData $toMonth, $this->emptyPeriods($fromMonth, $toMonth), [], - '安装费安装公司分析暂时无法读取,请稍后重试。', + '安装费月度分析暂时无法读取,请稍后重试。', ); } @@ -59,8 +59,6 @@ class InstallationFeeUsagePageData } $periods = $this->buildPeriods($fromMonth, $toMonth, $result['rows']); - $summary = $this->buildSummary($periods); - $periods = $this->applyComparableCosts($periods, $summary['benchmark_rates']); return $this->payload( $range, @@ -68,7 +66,7 @@ class InstallationFeeUsagePageData $fromMonth, $toMonth, $periods, - $summary, + $this->buildSummary($periods), ); } @@ -90,8 +88,7 @@ class InstallationFeeUsagePageData * period:string, * installation_company:string, * orders:int, - * reviewed_orders:int, - * settled_amount:float + * amount:float * }> $rows */ private function buildPeriods(string $fromMonth, string $toMonth, array $rows): array @@ -110,31 +107,39 @@ class InstallationFeeUsagePageData $index = $indexes[$period]; $vendorKey = $this->vendorKey($row['installation_company']); - $orders = (int) $row['orders']; - $reviewedOrders = (int) $row['reviewed_orders']; - $settledAmount = (float) $row['settled_amount']; - - $periods[$index]['total_orders'] += $orders; - $periods[$index]['reviewed_orders'] += $reviewedOrders; - $periods[$index]['settled_amount'] += $settledAmount; - $periods[$index]['vendors'][$vendorKey]['orders'] += $orders; - $periods[$index]['vendors'][$vendorKey]['reviewed_orders'] += $reviewedOrders; - $periods[$index]['vendors'][$vendorKey]['settled_amount'] += $settledAmount; + $periods[$index]['total_orders'] += (int) $row['orders']; + $periods[$index]['total_amount'] += (float) $row['amount']; + $periods[$index]['vendors'][$vendorKey]['orders'] += (int) $row['orders']; + $periods[$index]['vendors'][$vendorKey]['amount'] += (float) $row['amount']; } + $previousAmount = null; + $previousOrders = null; foreach ($periods as &$period) { - $period['settled_amount'] = round((float) $period['settled_amount'], 2); - $period['review_rate'] = $this->ratio($period['reviewed_orders'], $period['total_orders']); - $period['unit_cost'] = $this->unitCost($period['settled_amount'], $period['reviewed_orders']); - + $period['total_amount'] = round((float) $period['total_amount'], 2); + $period['average_fee'] = $period['total_orders'] > 0 + ? round($period['total_amount'] / $period['total_orders'], 2) + : 0.0; foreach ($period['vendors'] as &$vendor) { - $vendor['settled_amount'] = round((float) $vendor['settled_amount'], 2); - $vendor['review_rate'] = $this->ratio($vendor['reviewed_orders'], $vendor['orders']); - $vendor['unit_cost'] = $this->unitCost($vendor['settled_amount'], $vendor['reviewed_orders']); + $vendor['amount'] = round((float) $vendor['amount'], 2); $vendor['order_share'] = $this->ratio($vendor['orders'], $period['total_orders']); + $vendor['average_fee'] = $vendor['orders'] > 0 + ? round($vendor['amount'] / $vendor['orders'], 2) + : 0.0; } unset($vendor); + $period['fee_change_rate'] = $period['total_orders'] > 0 && $previousAmount !== null && $previousAmount > 0 + ? round((($period['total_amount'] - $previousAmount) / $previousAmount) * 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['total_orders'] > 0) { + $previousAmount = $period['total_amount']; + $previousOrders = $period['total_orders']; + } } unset($period); @@ -151,10 +156,10 @@ class InstallationFeeUsagePageData 'period' => $cursor->format('Y-m'), 'short_label' => $cursor->format('n') . '月', 'total_orders' => 0, - 'reviewed_orders' => 0, - 'review_rate' => 0.0, - 'settled_amount' => 0.0, - 'unit_cost' => 0.0, + 'total_amount' => 0.0, + 'average_fee' => 0.0, + 'fee_change_rate' => null, + 'order_change_rate' => null, 'vendors' => $this->emptyVendors(), ]; $cursor->addMonthNoOverflow(); @@ -170,140 +175,56 @@ class InstallationFeeUsagePageData 'key' => 'wan', 'label' => '万师傅', 'orders' => 0, - 'reviewed_orders' => 0, - 'settled_amount' => 0.0, - 'review_rate' => 0.0, - 'unit_cost' => 0.0, + 'amount' => 0.0, 'order_share' => 0.0, + 'average_fee' => 0.0, ], 'luban' => [ 'key' => 'luban', 'label' => '鲁班系列', 'orders' => 0, - 'reviewed_orders' => 0, - 'settled_amount' => 0.0, - 'review_rate' => 0.0, - 'unit_cost' => 0.0, + 'amount' => 0.0, 'order_share' => 0.0, + 'average_fee' => 0.0, ], 'other' => [ 'key' => 'other', 'label' => '其他安装公司', 'orders' => 0, - 'reviewed_orders' => 0, - 'settled_amount' => 0.0, - 'review_rate' => 0.0, - 'unit_cost' => 0.0, + 'amount' => 0.0, 'order_share' => 0.0, + 'average_fee' => 0.0, ], ]; } private function buildSummary(array $periods): array { - $nonEmptyIndexes = []; - foreach ($periods as $index => $period) { - if ($period['total_orders'] > 0) { - $nonEmptyIndexes[] = $index; - } - } - - if ($nonEmptyIndexes === []) { + $nonEmpty = array_values(array_filter( + $periods, + static fn (array $period): bool => $period['total_orders'] > 0, + )); + if ($nonEmpty === []) { return $this->emptySummary(); } - $currentIndex = end($nonEmptyIndexes); - $previousIndex = count($nonEmptyIndexes) > 1 - ? $nonEmptyIndexes[count($nonEmptyIndexes) - 2] - : null; - $current = $periods[$currentIndex]; - $previous = $previousIndex === null ? null : $periods[$previousIndex]; - - $benchmarkIndexes = []; - for ($index = $currentIndex - 1; $index >= 0; $index--) { - if ($this->isCompleteReviewPeriod($periods[$index])) { - $benchmarkIndexes[] = $index; - if (count($benchmarkIndexes) === 2) { - break; - } - } - } - if ($benchmarkIndexes === [] && $previousIndex !== null) { - $benchmarkIndexes[] = $previousIndex; - } - - $benchmarkPeriods = array_map( - static fn (int $index): string => $periods[$index]['period'], - $benchmarkIndexes, - ); - sort($benchmarkPeriods, SORT_STRING); - $benchmarkRates = $this->benchmarkRates($periods, $benchmarkIndexes); - $previousVendors = collect($previous['vendors'] ?? [])->keyBy('key'); - - $wanOrders = (int) $current['vendors']['wan']['orders']; - $lubanOrders = (int) $current['vendors']['luban']['orders']; - $switchOrders = $wanOrders + $lubanOrders; - $wanRate = $benchmarkRates['wan'] ?? null; - $lubanRate = $benchmarkRates['luban'] ?? null; - - $vendorRows = []; - $estimatedMixedAmount = 0.0; - $estimatedAllWanAmount = 0.0; - foreach ($current['vendors'] as $vendor) { - $rate = $benchmarkRates[$vendor['key']] ?? null; - $estimatedAmount = $rate === null ? null : $vendor['orders'] * $rate; - if ($vendor['key'] !== 'other' && $estimatedAmount !== null) { - $estimatedMixedAmount += $estimatedAmount; - } - if ($vendor['key'] === 'wan' && $rate !== null) { - $estimatedAllWanAmount = $switchOrders * $rate; - } - - $prior = $previousVendors->get($vendor['key']); - $vendorRows[] = [ - ...$vendor, - 'benchmark_rate' => $rate, - 'estimated_amount' => $estimatedAmount === null ? null : round($estimatedAmount, 2), - 'previous_orders' => (int) ($prior['orders'] ?? 0), - 'previous_reviewed_orders' => (int) ($prior['reviewed_orders'] ?? 0), - 'previous_review_rate' => (float) ($prior['review_rate'] ?? 0), - 'previous_settled_amount' => (float) ($prior['settled_amount'] ?? 0), - 'previous_unit_cost' => (float) ($prior['unit_cost'] ?? 0), - ]; - } - - $switchImpact = $switchOrders > 0 && $wanRate !== null && $lubanRate !== null - ? round($estimatedMixedAmount - $estimatedAllWanAmount, 2) - : null; + $current = end($nonEmpty); + $previous = count($nonEmpty) > 1 ? $nonEmpty[count($nonEmpty) - 2] : null; return [ 'latest_period' => $current['period'], 'previous_period' => $previous['period'] ?? null, 'current_orders' => (int) $current['total_orders'], - 'current_reviewed_orders' => (int) $current['reviewed_orders'], - 'current_review_rate' => (float) $current['review_rate'], - 'current_confirmed_amount' => (float) $current['settled_amount'], - 'current_confirmed_unit_cost' => (float) $current['unit_cost'], + 'current_amount' => (float) $current['total_amount'], + 'current_average_fee' => (float) $current['average_fee'], + 'current_fee_change_rate' => $current['fee_change_rate'], + 'current_order_change_rate' => $current['order_change_rate'], 'previous_orders' => (int) ($previous['total_orders'] ?? 0), - 'previous_reviewed_orders' => (int) ($previous['reviewed_orders'] ?? 0), - 'previous_review_rate' => (float) ($previous['review_rate'] ?? 0), - 'previous_confirmed_amount' => (float) ($previous['settled_amount'] ?? 0), - 'previous_confirmed_unit_cost' => (float) ($previous['unit_cost'] ?? 0), - 'benchmark_periods' => $benchmarkPeriods, - 'benchmark_label' => $benchmarkPeriods === [] - ? null - : $benchmarkPeriods[0] . ' 至 ' . $benchmarkPeriods[count($benchmarkPeriods) - 1], - 'benchmark_rates' => $benchmarkRates, - 'estimated_orders' => $switchOrders, - 'estimated_mixed_amount' => round($estimatedMixedAmount, 2), - 'estimated_all_wan_amount' => round($estimatedAllWanAmount, 2), - 'estimated_mixed_unit_cost' => $this->unitCost($estimatedMixedAmount, $switchOrders), - 'estimated_all_wan_unit_cost' => $this->unitCost($estimatedAllWanAmount, $switchOrders), - 'switch_impact' => $switchImpact, - 'switch_impact_rate' => $estimatedAllWanAmount > 0.004 && $switchImpact !== null - ? round(($switchImpact / $estimatedAllWanAmount) * 100, 1) - : null, - 'vendors' => $vendorRows, + 'previous_amount' => (float) ($previous['total_amount'] ?? 0), + 'previous_average_fee' => (float) ($previous['average_fee'] ?? 0), + 'has_negative_amount' => collect($periods)->contains( + static fn (array $period): bool => (float) $period['total_amount'] < -0.004, + ), ]; } @@ -313,119 +234,14 @@ class InstallationFeeUsagePageData 'latest_period' => null, 'previous_period' => null, 'current_orders' => 0, - 'current_reviewed_orders' => 0, - 'current_review_rate' => 0.0, - 'current_confirmed_amount' => 0.0, - 'current_confirmed_unit_cost' => 0.0, + 'current_amount' => 0.0, + 'current_average_fee' => 0.0, + 'current_fee_change_rate' => null, + 'current_order_change_rate' => null, 'previous_orders' => 0, - 'previous_reviewed_orders' => 0, - 'previous_review_rate' => 0.0, - 'previous_confirmed_amount' => 0.0, - 'previous_confirmed_unit_cost' => 0.0, - 'benchmark_periods' => [], - 'benchmark_label' => null, - 'benchmark_rates' => [], - 'estimated_orders' => 0, - 'estimated_mixed_amount' => 0.0, - 'estimated_all_wan_amount' => 0.0, - 'estimated_mixed_unit_cost' => 0.0, - 'estimated_all_wan_unit_cost' => 0.0, - 'switch_impact' => null, - 'switch_impact_rate' => null, - 'vendors' => [], - ]; - } - - /** @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) { - return false; - } - - foreach (['wan', 'luban'] as $vendorKey) { - $vendor = $period['vendors'][$vendorKey]; - if ($vendor['orders'] <= 0 || $vendor['review_rate'] < 70) { - return false; - } - } - - return true; - } - - /** @param list $periodIndexes */ - private function benchmarkRates(array $periods, array $periodIndexes): array - { - $rates = [ - 'wan' => ['reviewed_orders' => 0, 'settled_amount' => 0.0], - 'luban' => ['reviewed_orders' => 0, 'settled_amount' => 0.0], - ]; - foreach ($periodIndexes as $periodIndex) { - foreach ($rates as $vendorKey => &$rate) { - $vendor = $periods[$periodIndex]['vendors'][$vendorKey]; - $rate['reviewed_orders'] += (int) $vendor['reviewed_orders']; - $rate['settled_amount'] += (float) $vendor['settled_amount']; - } - unset($rate); - } - - return [ - 'wan' => $rates['wan']['reviewed_orders'] > 0 - ? $this->unitCost($rates['wan']['settled_amount'], $rates['wan']['reviewed_orders']) - : null, - 'luban' => $rates['luban']['reviewed_orders'] > 0 - ? $this->unitCost($rates['luban']['settled_amount'], $rates['luban']['reviewed_orders']) - : null, + 'previous_amount' => 0.0, + 'previous_average_fee' => 0.0, + 'has_negative_amount' => false, ]; } @@ -448,11 +264,6 @@ class InstallationFeeUsagePageData : 0.0; } - private function unitCost(int|float $amount, int $orders): float - { - return $orders > 0 ? round((float) $amount / $orders, 2) : 0.0; - } - private function payload( string $range, string $rangeLabel, 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 b6f8bac7..16a622f9 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 @@ -10,24 +10,6 @@ $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); - $impact = static function (mixed $value): array { - if ($value === null) { - return ['text' => '—', 'class' => 'is-empty']; - } - - $amount = (float) $value; - if (abs($amount) < 0.005) { - return ['text' => '基本持平', 'class' => 'is-neutral']; - } - - return [ - 'text' => ($amount > 0 ? '增加 ' : '节省 ') . '¥' . number_format(abs($amount), 2), - 'class' => $amount > 0 ? 'is-increase' : 'is-saving', - ]; - }; - $switchImpact = $summary['switch_impact'] ?? null; - $switchImpactDisplay = $impact($switchImpact); - $hasBenchmark = ! empty($summary['benchmark_periods']); @endphp
@@ -474,36 +456,31 @@
{{ $currentPeriod ?? '当前月' }} 安装单量 {{ number_format((int) ($summary['current_orders'] ?? 0)) }} 单 - 万师傅 {{ number_format((int) ($summary['vendors'][0]['orders'] ?? 0)) }} 单 · 鲁班 {{ number_format((int) ($summary['vendors'][1]['orders'] ?? 0)) }} 单 + 较上月 {{ $summary['current_order_change_rate'] === null ? '—' : (($summary['current_order_change_rate'] > 0 ? '+' : '') . $percent($summary['current_order_change_rate']) . '%') }}
- {{ $currentPeriod ?? '当前月' }} 预估安装费 - ¥{{ $moneyWan($summary['estimated_mixed_amount'] ?? 0) }} 万 - 按安装公司基准单均折算全部发货单 + {{ $currentPeriod ?? '当前月' }} 实际安装费 + ¥{{ $moneyWan($summary['current_amount'] ?? 0) }} 万 + {{ $previousPeriod ?? '上月' }}:¥{{ $moneyWan($summary['previous_amount'] ?? 0) }} 万
- {{ $currentPeriod ?? '当前月' }} 预估单均 - ¥{{ $money($summary['estimated_mixed_unit_cost'] ?? 0) }} - 预估安装费 ÷ 可识别安装单量 + {{ $currentPeriod ?? '当前月' }} 实际单均 + ¥{{ $money($summary['current_average_fee'] ?? 0) }} + {{ $previousPeriod ?? '上月' }}:¥{{ $money($summary['previous_average_fee'] ?? 0) }}
- 切换安装公司影响 - {{ $switchImpactDisplay['text'] }} - - @if ($hasBenchmark) - 全万师傅预估 ¥{{ $moneyWan($summary['estimated_all_wan_amount'] ?? 0) }} 万 - · 基准 {{ $summary['benchmark_label'] }} - @else - 暂无可用基准 - @endif - + 安装费环比 + + {{ $summary['current_fee_change_rate'] === null ? '—' : (($summary['current_fee_change_rate'] > 0 ? '+' : '') . $percent($summary['current_fee_change_rate']) . '%') }} + + 与 {{ $previousPeriod ?? '上月' }} 实际安装费比较

- 单量按发货月份汇总,安装公司分为万师傅、鲁班系列和其他安装公司。为了让每个月可以横向比较, - 安装费统一按最近两个完整月份的公司单均乘以当月各公司实际单量进行预估,不再区分审核和未审核。 - 切换影响是当前供应商占比与“全部使用万师傅”的预估差额,最终金额以结算为准。 + 按客服审核月份实际归集:安装单量按安装主单去重,安装费取安装明细的实际结算金额。 + 安装公司分为万师傅、鲁班系列和其他安装公司,不展示预估金额,也不拆分审核状态。 + 负数安装费按实际金额保留。

@@ -520,7 +497,7 @@ 万师傅 鲁班系列 其他安装公司 - 预估安装费 + 实际安装费 单均 安装费环比 @@ -539,20 +516,15 @@ @foreach (['wan', 'luban', 'other'] as $vendorKey) @php($vendor = $period['vendors'][$vendorKey]) - @if ($vendor['comparable_amount'] === null) - {{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}% - 暂无预估 - @else - {{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}% - ¥{{ $money($vendor['comparable_amount']) }} · 单均 ¥{{ $money($vendor['comparable_unit_cost']) }} - @endif + {{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}% + ¥{{ $money($vendor['amount']) }} · 单均 ¥{{ $money($vendor['average_fee']) }} @endforeach - {{ $period['comparable_amount'] === null ? '—' : '¥' . $money($period['comparable_amount']) }} + ¥{{ $money($period['total_amount']) }} - {{ $period['comparable_unit_cost'] === null ? '—' : '¥' . $money($period['comparable_unit_cost']) }} + ¥{{ $money($period['average_fee']) }} @if ($period['fee_change_rate'] === null) diff --git a/tests/Feature/Business/ManagementCrudTest.php b/tests/Feature/Business/ManagementCrudTest.php index 03815fa2..ad8d3b5a 100644 --- a/tests/Feature/Business/ManagementCrudTest.php +++ b/tests/Feature/Business/ManagementCrudTest.php @@ -491,71 +491,37 @@ class ManagementCrudTest extends FeatureTestCase ->assertJsonPath('change_rate', 25.0); } - public function testInstallationFeeUsagePageShowsCompanyCostAndSwitchImpact(): void + public function testInstallationFeeUsagePageShowsActualCompanyMonthlyComparison(): void { $previousMonth = now()->subMonthNoOverflow()->format('Y-m'); $currentMonth = now()->format('Y-m'); - $benchmarkB = now()->subMonthsNoOverflow(3)->format('Y-m'); - $benchmarkA = now()->subMonthsNoOverflow(2)->format('Y-m'); $mirror = Mockery::mock(InstallationDetailMirrorRepository::class); - $mirror->shouldReceive('installationCompanyFeeUsageTrend')->once()->andReturn([ + $mirror->shouldReceive('installationCompanyActualFeeTrend')->once()->andReturn([ 'ready' => true, 'rows' => [ - [ - 'period' => $benchmarkB, - 'installation_company' => '万师傅', - 'orders' => 80, - 'reviewed_orders' => 80, - 'settled_amount' => 6400.00, - ], - [ - 'period' => $benchmarkB, - 'installation_company' => '鲁班到家', - 'orders' => 20, - 'reviewed_orders' => 20, - 'settled_amount' => 1800.00, - ], - [ - 'period' => $benchmarkA, - 'installation_company' => '万师傅', - 'orders' => 80, - 'reviewed_orders' => 80, - 'settled_amount' => 6400.00, - ], - [ - 'period' => $benchmarkA, - 'installation_company' => '鲁班到家', - 'orders' => 20, - 'reviewed_orders' => 20, - 'settled_amount' => 1800.00, - ], [ 'period' => $previousMonth, 'installation_company' => '万师傅', - 'orders' => 80, - 'reviewed_orders' => 80, - 'settled_amount' => 6400.00, + 'orders' => 60, + 'amount' => 4800.00, ], [ 'period' => $previousMonth, 'installation_company' => '鲁班到家', - 'orders' => 20, - 'reviewed_orders' => 0, - 'settled_amount' => 0.00, + 'orders' => 40, + 'amount' => 3600.00, ], [ 'period' => $currentMonth, 'installation_company' => '万师傅', 'orders' => 50, - 'reviewed_orders' => 50, - 'settled_amount' => 4000.00, + 'amount' => 4000.00, ], [ 'period' => $currentMonth, 'installation_company' => '鲁班到家', 'orders' => 50, - 'reviewed_orders' => 0, - 'settled_amount' => 0.00, + 'amount' => 5000.00, ], ], ]); @@ -572,12 +538,14 @@ class ManagementCrudTest extends FeatureTestCase ->assertSeeText('月度安装费对比') ->assertSeeText('万师傅') ->assertSeeText('鲁班系列') - ->assertSeeText('切换安装公司影响') - ->assertSeeText('增加 ¥500.00') - ->assertSeeText('预估安装费') + ->assertSeeText('实际安装费') + ->assertSeeText('¥0.90 万') + ->assertSeeText('¥90.00') + ->assertSeeText('+7.1%') ->assertSeeText('安装费环比') - ->assertSeeText('不再区分审核和未审核') - ->assertSeeText('最终金额以结算为准') + ->assertSeeText('不展示预估金额') + ->assertSeeText('负数安装费按实际金额保留') + ->assertDontSeeText('预估安装费') ->assertDontSeeText('审核覆盖') ->assertDontSeeText('平台安装费分析'); } diff --git a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php index 39d4b10e..7af858eb 100644 --- a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php @@ -166,7 +166,7 @@ class InstallationDetailMirrorRepositoryTest extends TestCase $this->assertSame(100.0,$result['change_rate']); } - public function test_installation_company_fee_usage_trend_counts_orders_and_reviewed_amounts(): void + public function test_installation_company_actual_fee_trend_counts_orders_and_amounts(): void { DB::connection('business_mirror')->table('fixture_install')->insert([ ['Id'=>210,'SourceGuid'=>'trend-wan-1','OrderNum'=>'WAN-1','shop_name'=>'天猫-测试店','SubmitTime'=>'2026-06-01','ShipTIme'=>'2026-06-02','installCompanyName'=>'万师傅'], @@ -187,22 +187,20 @@ class InstallationDetailMirrorRepositoryTest extends TestCase ['Id'=>316,'guid'=>'trend-luban-3','shopproid'=>'P7','kfshTime'=>'2026-07-12 10:00:00','settleItemAmount'=>30.00], ]); - $result = $this->repository->installationCompanyFeeUsageTrend('2026-06', '2026-07'); + $result = $this->repository->installationCompanyActualFeeTrend('2026-06', '2026-07'); $rows = collect($result['rows'])->keyBy( static fn (array $row): string => $row['period'] . '|' . $row['installation_company'], ); $this->assertTrue($result['ready']); $this->assertSame(2, $rows['2026-06|万师傅']['orders']); - $this->assertSame(2, $rows['2026-06|万师傅']['reviewed_orders']); - $this->assertSame(70.0, $rows['2026-06|万师傅']['settled_amount']); + $this->assertSame(70.0, $rows['2026-06|万师傅']['amount']); $this->assertSame(1, $rows['2026-06|鲁班到家']['orders']); - $this->assertSame(25.0, $rows['2026-06|鲁班到家']['settled_amount']); - $this->assertSame(2, $rows['2026-07|鲁班到家']['orders']); - $this->assertSame(1, $rows['2026-07|鲁班到家']['reviewed_orders']); - $this->assertSame(20.0, $rows['2026-07|鲁班到家']['settled_amount']); - $this->assertSame(1, $rows['2026-07|鲁班大师']['reviewed_orders']); - $this->assertSame(30.0, $rows['2026-07|鲁班大师']['settled_amount']); + $this->assertSame(25.0, $rows['2026-06|鲁班到家']['amount']); + $this->assertSame(1, $rows['2026-07|鲁班到家']['orders']); + $this->assertSame(20.0, $rows['2026-07|鲁班到家']['amount']); + $this->assertSame(1, $rows['2026-07|鲁班大师']['orders']); + $this->assertSame(30.0, $rows['2026-07|鲁班大师']['amount']); } public function test_monthly_settlement_buckets_only_include_approved_customer_reviews(): void