feat: 安装费汇总增加每月平均费用 (#1464)
This commit is contained in:
parent
b4767adb86
commit
063f5f1a67
@ -237,18 +237,12 @@ class InstallationDetailMirrorRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装公司使用趋势:发货月份统计使用单量,客服审核月份统计安装费。
|
||||
*
|
||||
* 单量按安装主单 SourceGuid 和发货时间归属;金额与安装费汇总共用
|
||||
* 客服审核时间和明细结算金额口径。两种指标使用各自独立的日期维度,
|
||||
* 避免未审核的新供应商单量被审核批次堆积掩盖。
|
||||
* 按客服审核月份汇总各安装公司的审核单量和结算明细金额。
|
||||
*
|
||||
* @return array{
|
||||
* ready:bool,
|
||||
* rows:list<array{period:string,installation_company:string,orders:int,amount:float}>,
|
||||
* totals:list<array{installation_company:string,orders:int,amount:float}>,
|
||||
* order_rows:list<array{period:string,installation_company:string,orders:int}>,
|
||||
* order_totals:list<array{installation_company:string,orders:int}>
|
||||
* totals:list<array{installation_company:string,orders:int,amount:float}>
|
||||
* }
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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<array{period:string,installation_company:string,orders:int,amount:float}> $rows
|
||||
* @param list<array{period:string,installation_company:string,orders:int}>|null $usageRows
|
||||
*/
|
||||
private function buildPeriods(
|
||||
string $fromMonth,
|
||||
string $toMonth,
|
||||
array $rows,
|
||||
?array $usageRows = null,
|
||||
): array
|
||||
/** @param list<array{period:string,installation_company:string,orders:int,amount:float}> $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<array{installation_company:string,orders:int,amount:float}> $feeTotals
|
||||
* @param list<array{installation_company:string,orders:int}>|null $usageTotals
|
||||
*/
|
||||
private function buildSummary(array $feeTotals, ?array $usageTotals, array $periods): array
|
||||
/** @param list<array{installation_company:string,orders:int,amount:float}> $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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 @@
|
||||
</label>
|
||||
<div class="installation-usage-static">
|
||||
<span>时间口径</span>
|
||||
<strong>单量看发货时间 · 费用看审核时间</strong>
|
||||
<strong>客服审核时间</strong>
|
||||
</div>
|
||||
<div class="installation-usage-static">
|
||||
<span>当前范围</span>
|
||||
@ -696,7 +493,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="installation-usage-actions">
|
||||
<span class="installation-usage-range">单量按发货月份 · 安装费按客服审核月份</span>
|
||||
<span class="installation-usage-range">安装费与平均费均按客服审核月份</span>
|
||||
<button type="submit" class="installation-usage-button is-primary">
|
||||
<span class="material-icons-outlined" aria-hidden="true">search</span>
|
||||
<span>查询</span>
|
||||
@ -716,41 +513,6 @@
|
||||
@endif
|
||||
|
||||
@if (! $error)
|
||||
<section class="installation-usage-switch" aria-labelledby="installation-usage-switch-title">
|
||||
<div class="installation-usage-switch__head">
|
||||
<div class="installation-usage-switch__title" id="installation-usage-switch-title">
|
||||
<span class="material-icons-outlined" aria-hidden="true">swap_horiz</span>
|
||||
<span>安装公司切换判断</span>
|
||||
</div>
|
||||
<span class="installation-usage-status">{{ $summary['switch_status'] ?? '暂无判断' }}</span>
|
||||
</div>
|
||||
<div class="installation-usage-switch__facts">
|
||||
<div class="installation-usage-fact">
|
||||
<span>最新有数据月份</span>
|
||||
<strong>{{ $summary['latest_period'] ?? '—' }}</strong>
|
||||
</div>
|
||||
<div class="installation-usage-fact">
|
||||
<span>主安装公司</span>
|
||||
<strong>{{ $summary['latest_primary'] ?? '—' }}</strong>
|
||||
</div>
|
||||
<div class="installation-usage-fact">
|
||||
<span>当月单量占比</span>
|
||||
<strong>{{ $percent($summary['latest_primary_share'] ?? 0) }}%</strong>
|
||||
</div>
|
||||
<div class="installation-usage-fact">
|
||||
<span>最近变化</span>
|
||||
<strong>
|
||||
@if (! empty($summary['last_transition']))
|
||||
{{ $summary['last_transition']['period'] }} · {{ $summary['last_transition']['from'] }} → {{ $summary['last_transition']['to'] }}
|
||||
@else
|
||||
期内未发生切换
|
||||
@endif
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
<p class="installation-usage-switch__note">{{ $summary['switch_note'] ?? '暂无安装单数据。' }}</p>
|
||||
</section>
|
||||
|
||||
<section class="installation-usage-kpis" aria-label="安装费汇总指标">
|
||||
<div class="installation-usage-kpi">
|
||||
<span>安装费合计</span>
|
||||
@ -758,55 +520,24 @@
|
||||
<small>客服审核口径 · 结算明细金额</small>
|
||||
</div>
|
||||
<div class="installation-usage-kpi">
|
||||
<span>安装单量</span>
|
||||
<strong>{{ number_format((int) ($summary['total_orders'] ?? 0)) }} 单</strong>
|
||||
<small>按发货月份 · 安装主单去重</small>
|
||||
<span>审核安装单量</span>
|
||||
<strong>{{ number_format((int) ($summary['total_fee_orders'] ?? 0)) }} 单</strong>
|
||||
<small>按客服审核月份 · 安装主单去重</small>
|
||||
</div>
|
||||
<div class="installation-usage-kpi">
|
||||
<span>平均审核单安装费</span>
|
||||
<span>平均每单安装费</span>
|
||||
<strong>¥{{ $money($summary['average_fee'] ?? 0) }}</strong>
|
||||
<small>审核安装费 ÷ {{ number_format((int) ($summary['total_fee_orders'] ?? 0)) }} 个审核单</small>
|
||||
</div>
|
||||
<div class="installation-usage-kpi">
|
||||
<span>最新月份</span>
|
||||
<strong>{{ $summary['latest_primary'] ?? '暂无安装单' }}</strong>
|
||||
<small>{{ $summary['latest_period'] ?? '所选期间无数据' }}{{ ($summary['latest_period'] ?? null) === $currentMonth ? ' · 截至当前' : '' }}</small>
|
||||
</div>
|
||||
</section>
|
||||
@endif
|
||||
|
||||
<section
|
||||
class="installation-usage-board"
|
||||
data-installation-fee-usage-board
|
||||
data-metric="orders"
|
||||
aria-labelledby="installation-usage-trend-title"
|
||||
>
|
||||
<section class="installation-usage-board" aria-labelledby="installation-usage-trend-title">
|
||||
<div class="installation-usage-board__head">
|
||||
<div class="installation-usage-board__title">
|
||||
<strong id="installation-usage-trend-title">安装公司使用趋势</strong>
|
||||
<span>单量按发货月份 · 切换判断看发货单量占比</span>
|
||||
<strong id="installation-usage-trend-title">每月平均安装费</strong>
|
||||
<span>按客服审核月份 · 单均结算金额</span>
|
||||
</div>
|
||||
<div class="installation-usage-metrics" role="group" aria-label="趋势指标">
|
||||
<button
|
||||
type="button"
|
||||
class="installation-usage-metric"
|
||||
data-installation-usage-metric="orders"
|
||||
aria-pressed="true"
|
||||
>安装单量</button>
|
||||
<button
|
||||
type="button"
|
||||
class="installation-usage-metric"
|
||||
data-installation-usage-metric="fee"
|
||||
aria-pressed="false"
|
||||
>审核安装费</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="installation-usage-legend" aria-label="趋势图例">
|
||||
<span class="installation-usage-legend__item"><i class="installation-usage-legend__swatch is-wan"></i>万师傅</span>
|
||||
<span class="installation-usage-legend__item"><i class="installation-usage-legend__swatch is-luban"></i>鲁班到家</span>
|
||||
<span class="installation-usage-legend__item"><i class="installation-usage-legend__swatch is-other"></i>其他安装公司</span>
|
||||
<span>鲁班大师与鲁班到家按同一系列统计</span>
|
||||
</div>
|
||||
|
||||
<div class="installation-usage-chart-scroll">
|
||||
@ -814,75 +545,53 @@
|
||||
class="installation-usage-chart"
|
||||
style="--period-count: {{ max(1, count($periods)) }}"
|
||||
role="img"
|
||||
aria-label="安装公司月度使用趋势图,{{ $rangeLabel }}"
|
||||
aria-label="每月平均安装费趋势图,{{ $rangeLabel }}"
|
||||
>
|
||||
<div class="installation-usage-chart__plot">
|
||||
<div class="installation-usage-chart__grid" aria-hidden="true">
|
||||
<span></span><span></span><span></span><span></span><span></span>
|
||||
</div>
|
||||
<span class="installation-usage-chart__axis" data-installation-usage-axis>安装单量</span>
|
||||
@if (collect($periods)->sum('total_orders') > 0)
|
||||
<span class="installation-usage-chart__axis">平均安装费(元/单)</span>
|
||||
@if (collect($periods)->sum('total_fee_orders') > 0)
|
||||
<div class="installation-usage-chart__columns">
|
||||
@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
|
||||
<div @class(['installation-usage-chart__column', 'is-current' => $period['period'] === $currentMonth])>
|
||||
<div
|
||||
class="installation-usage-chart__bar"
|
||||
style="--orders-height: {{ $cssPercent($ordersHeight) }}%; --fee-height: {{ $cssPercent($feeHeight) }}%"
|
||||
title="{{ $period['period'] }}:万师傅 {{ (int) $wan['orders'] }} 单/{{ $moneyWan($wan['amount']) }} 万;鲁班到家 {{ (int) $luban['orders'] }} 单/{{ $moneyWan($luban['amount']) }} 万;其他 {{ (int) $other['orders'] }} 单/{{ $moneyWan($other['amount']) }} 万"
|
||||
>
|
||||
<span
|
||||
class="installation-usage-chart__segment is-wan"
|
||||
style="--orders-share: {{ $cssPercent(((int) $wan['orders'] / $ordersTotal) * 100) }}%; --fee-share: {{ $cssPercent($positiveFeeTotal > 0 ? (max(0, (float) $wan['amount']) / $positiveFeeTotal) * 100 : 0) }}%"
|
||||
></span>
|
||||
<span
|
||||
class="installation-usage-chart__segment is-luban"
|
||||
style="--orders-share: {{ $cssPercent(((int) $luban['orders'] / $ordersTotal) * 100) }}%; --fee-share: {{ $cssPercent($positiveFeeTotal > 0 ? (max(0, (float) $luban['amount']) / $positiveFeeTotal) * 100 : 0) }}%"
|
||||
></span>
|
||||
<span
|
||||
class="installation-usage-chart__segment is-other"
|
||||
style="--orders-share: {{ $cssPercent(((int) $other['orders'] / $ordersTotal) * 100) }}%; --fee-share: {{ $cssPercent($positiveFeeTotal > 0 ? (max(0, (float) $other['amount']) / $positiveFeeTotal) * 100 : 0) }}%"
|
||||
></span>
|
||||
</div>
|
||||
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']) }} 单"
|
||||
></div>
|
||||
<span class="installation-usage-chart__label">{{ $period['short_label'] }}</span>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@else
|
||||
<div class="installation-usage-chart__empty">所选期间暂无发货安装单。</div>
|
||||
<div class="installation-usage-chart__empty">所选期间暂无已审核安装费。</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="installation-usage-note">
|
||||
口径:安装单量按安装主单去重,并按发货时间归属月份,用于判断安装公司使用切换;安装费取安装明细子表结算金额,
|
||||
按客服审核时间归属月份,未审核安装费不计入金额趋势。“鲁班大师”和“鲁班到家”合并为鲁班系列,其他安装公司合并展示。
|
||||
口径:平均安装费 = 当月客服审核通过的安装明细结算金额 ÷ 当月审核安装单量。未审核安装费不计入;
|
||||
当前月份标记为“截至当前”,金额会随审核进度继续增加。
|
||||
@if (! empty($summary['has_negative_fee']))
|
||||
存在负数安装费时,趋势图的费用高度只堆叠正数金额,表格合计仍按实际金额展示。
|
||||
存在负数安装费时,趋势图柱高只展示正数平均值,详情表仍按实际金额计算。
|
||||
@endif
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<div class="installation-usage-table-wrap" aria-label="安装公司月度趋势明细">
|
||||
<div class="installation-usage-table-wrap" aria-label="每月平均安装费明细">
|
||||
<table class="installation-usage-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<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">主安装公司</th>
|
||||
<th scope="col" class="is-number">平均安装费(元/单)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -894,57 +603,16 @@
|
||||
<span class="installation-usage-pill">截至当前</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="is-number">{{ number_format((int) $period['total_orders']) }}</td>
|
||||
<td class="is-number">{{ number_format((int) $period['total_fee_orders']) }}</td>
|
||||
<td class="is-number">{{ $moneyWan($period['total_amount']) }}</td>
|
||||
@foreach (['wan', 'luban', 'other'] as $vendorKey)
|
||||
@php($vendor = $period['vendors'][$vendorKey])
|
||||
<td class="installation-usage-table__vendor">
|
||||
<strong>{{ number_format((int) $vendor['orders']) }} 单 · {{ $percent($vendor['order_share']) }}%</strong>
|
||||
<span>审核 {{ number_format((int) $vendor['fee_orders']) }} 单 · {{ $moneyWan($vendor['amount']) }} 万元 · 费用占比 {{ $percent($vendor['amount_share']) }}%</span>
|
||||
</td>
|
||||
@endforeach
|
||||
<td class="installation-usage-table__primary">
|
||||
{{ $period['primary_label'] }}
|
||||
@if ($period['transition_from'] !== null)
|
||||
<span class="installation-usage-pill">切换</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="is-number">¥{{ $money($period['average_fee']) }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="7" class="installation-usage-empty">所选期间暂无安装公司趋势数据。</td>
|
||||
<td colspan="4" class="installation-usage-empty">所选期间暂无已审核安装费。</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var board = document.querySelector('[data-installation-fee-usage-board]');
|
||||
if (!board) { return; }
|
||||
|
||||
var buttons = Array.from(board.querySelectorAll('[data-installation-usage-metric]'));
|
||||
var axis = board.querySelector('[data-installation-usage-axis]');
|
||||
|
||||
function activate(metric) {
|
||||
board.dataset.metric = metric;
|
||||
buttons.forEach(function (button) {
|
||||
button.setAttribute(
|
||||
'aria-pressed',
|
||||
button.getAttribute('data-installation-usage-metric') === metric ? 'true' : 'false'
|
||||
);
|
||||
});
|
||||
if (axis) {
|
||||
axis.textContent = metric === 'fee' ? '审核安装费' : '发货单量';
|
||||
}
|
||||
}
|
||||
|
||||
buttons.forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
activate(button.getAttribute('data-installation-usage-metric'));
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<array{period:string,installation_company:string,orders:int,amount:float}> $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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user