更新
This commit is contained in:
@@ -72,6 +72,17 @@ class PerformanceDashboardLogic
|
||||
'page_size' => 100,
|
||||
], $adminId, $adminInfo);
|
||||
$todaySummary = is_array($todayOverview['summary'] ?? null) ? $todayOverview['summary'] : [];
|
||||
$yesterdayOverview = ConversionLogic::overview([
|
||||
'dimension' => 'dept',
|
||||
'time_type' => 'yesterday',
|
||||
'include_members' => 0,
|
||||
'include_filters' => 0,
|
||||
'page_no' => 1,
|
||||
'page_size' => 100,
|
||||
], $adminId, $adminInfo);
|
||||
$yesterdaySummary = is_array($yesterdayOverview['summary'] ?? null)
|
||||
? $yesterdayOverview['summary']
|
||||
: [];
|
||||
|
||||
// 业绩指标必须直接复用业绩页的权威聚合,不能使用 ConversionLogic 的“双审完成单”。
|
||||
$todayPerformanceOverview = YejiStatsLogic::overview([
|
||||
@@ -88,6 +99,23 @@ class PerformanceDashboardLogic
|
||||
], $adminId, $adminInfo);
|
||||
$trend = self::buildTrend($trendStart, $today, $visibleAdminIds, $orderDaily, $trendContext);
|
||||
$todayTrendIndex = max(0, count($trend['dates'] ?? []) - 1);
|
||||
$yesterdayTrendIndex = max(0, $todayTrendIndex - 1);
|
||||
|
||||
$todayAddFansCount = (int) ($trend['leads'][$todayTrendIndex] ?? 0);
|
||||
$yesterdayAddFansCount = (int) ($trend['leads'][$yesterdayTrendIndex] ?? 0);
|
||||
$todayAppointmentCount = (int) ($trend['appointments'][$todayTrendIndex] ?? 0);
|
||||
$yesterdayAppointmentCount = (int) ($trend['appointments'][$yesterdayTrendIndex] ?? 0);
|
||||
$todayInterviewCount = (int) ($todaySummary['interview_count'] ?? 0);
|
||||
$yesterdayInterviewCount = (int) ($yesterdaySummary['interview_count'] ?? 0);
|
||||
$todayOrderCount = (int) self::dailyMetric($orderDaily, $today, 'count');
|
||||
$yesterdayOrderCount = (int) self::dailyMetric($orderDaily, $yesterday, 'count');
|
||||
$todayOrderAmount = self::dailyMetric($orderDaily, $today, 'amount');
|
||||
$yesterdayOrderAmount = self::dailyMetric($orderDaily, $yesterday, 'amount');
|
||||
$todayPaidAppointmentRate = round((float) ($todaySummary['paid_appointment_rate'] ?? 0), 2);
|
||||
$yesterdayPaidAppointmentRate = round((float) ($yesterdaySummary['paid_appointment_rate'] ?? 0), 2);
|
||||
$todayInterviewReceiveRate = round((float) ($todaySummary['interview_receive_rate'] ?? 0), 2);
|
||||
$yesterdayInterviewReceiveRate = round((float) ($yesterdaySummary['interview_receive_rate'] ?? 0), 2);
|
||||
|
||||
$target = self::buildTargetProgress(
|
||||
$adminId,
|
||||
(int) ($scope['scope_value'] ?? DataScopeService::SCOPE_SELF),
|
||||
@@ -108,14 +136,32 @@ class PerformanceDashboardLogic
|
||||
'personal_month_amount' => round($personalMonthAmount, 2),
|
||||
],
|
||||
'today' => [
|
||||
'add_fans_count' => (int) ($trend['leads'][$todayTrendIndex] ?? 0),
|
||||
'appointment_total_count' => (int) ($trend['appointments'][$todayTrendIndex] ?? 0),
|
||||
'interview_count' => (int) ($todaySummary['interview_count'] ?? 0),
|
||||
'add_fans_count' => $todayAddFansCount,
|
||||
'appointment_total_count' => $todayAppointmentCount,
|
||||
'interview_count' => $todayInterviewCount,
|
||||
// 保留原响应字段名以兼容已发布前端,数值含义已统一为“计入业绩的业务订单”。
|
||||
'completed_order_count' => (int) self::dailyMetric($orderDaily, $today, 'count'),
|
||||
'completed_order_amount' => self::dailyMetric($orderDaily, $today, 'amount'),
|
||||
'paid_appointment_rate' => round((float) ($todaySummary['paid_appointment_rate'] ?? 0), 2),
|
||||
'interview_receive_rate' => round((float) ($todaySummary['interview_receive_rate'] ?? 0), 2),
|
||||
'completed_order_count' => $todayOrderCount,
|
||||
'completed_order_amount' => $todayOrderAmount,
|
||||
'paid_appointment_rate' => $todayPaidAppointmentRate,
|
||||
'interview_receive_rate' => $todayInterviewReceiveRate,
|
||||
'comparisons' => [
|
||||
'add_fans_count' => self::buildComparison($todayAddFansCount, $yesterdayAddFansCount),
|
||||
'appointment_total_count' => self::buildComparison(
|
||||
$todayAppointmentCount,
|
||||
$yesterdayAppointmentCount
|
||||
),
|
||||
'interview_count' => self::buildComparison($todayInterviewCount, $yesterdayInterviewCount),
|
||||
'completed_order_count' => self::buildComparison($todayOrderCount, $yesterdayOrderCount),
|
||||
'completed_order_amount' => self::buildComparison($todayOrderAmount, $yesterdayOrderAmount),
|
||||
'paid_appointment_rate' => self::buildComparison(
|
||||
$todayPaidAppointmentRate,
|
||||
$yesterdayPaidAppointmentRate
|
||||
),
|
||||
'interview_receive_rate' => self::buildComparison(
|
||||
$todayInterviewReceiveRate,
|
||||
$yesterdayInterviewReceiveRate
|
||||
),
|
||||
],
|
||||
],
|
||||
'rankings' => [
|
||||
'appointments' => $appointmentRanking,
|
||||
@@ -273,6 +319,23 @@ class PerformanceDashboardLogic
|
||||
return round((($current - $previous) / $previous) * 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{direction: string, rate: float|null, previous: float}
|
||||
*/
|
||||
private static function buildComparison(float $current, float $previous): array
|
||||
{
|
||||
$difference = $current - $previous;
|
||||
$direction = abs($difference) < 0.00001
|
||||
? 'flat'
|
||||
: ($difference > 0 ? 'up' : 'down');
|
||||
|
||||
return [
|
||||
'direction' => $direction,
|
||||
'rate' => self::relativeChange($current, $previous),
|
||||
'previous' => round($previous, 2),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $scope
|
||||
* @return array<string, mixed>
|
||||
|
||||
Reference in New Issue
Block a user