更新
This commit is contained in:
@@ -157,6 +157,8 @@ class YejiStatsLogic
|
||||
/**
|
||||
* 按角色「数据范围」收窄业绩看板上下文(adminToPrimary、tableRowDeptIds)。
|
||||
* 与 DataScopeService / 列表 HasDataScopeFilter 一致:ALL 不处理;SELF/本部门/本部门及下级 仅保留可见 admin_id。
|
||||
*
|
||||
* 表格仍保持默认「中心」层级(图1);合计业绩等数值在聚合层按 dataScopeVisibleAdminIds 收窄。
|
||||
*/
|
||||
private static function applyYejiDataScope(array &$c, int $adminId, array $adminInfo): void
|
||||
{
|
||||
@@ -178,6 +180,17 @@ class YejiStatsLogic
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self::narrowYejiContextTableRowsByVisibleAdmins($c, $visibleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在现有展示行(默认中心层级)上按可见 admin 收窄表格行与台账归属。
|
||||
*
|
||||
* @param int[] $visibleIds
|
||||
*/
|
||||
private static function narrowYejiContextTableRowsByVisibleAdmins(array &$c, array $visibleIds): void
|
||||
{
|
||||
$flip = array_flip($visibleIds);
|
||||
$filtered = [];
|
||||
foreach ($c['adminToPrimary'] as $aid => $pid) {
|
||||
@@ -402,7 +415,10 @@ class YejiStatsLogic
|
||||
null,
|
||||
null,
|
||||
$tableRowDeptIds,
|
||||
$deptById
|
||||
$deptById,
|
||||
null,
|
||||
[],
|
||||
$dataScopeAdminIds
|
||||
)
|
||||
: null;
|
||||
// 业绩:部门行「合计业绩」与列表部门摊行一致;「{渠道}业绩」同列表摊行 + 渠道 EXISTS(与抽屉一致)
|
||||
@@ -417,7 +433,8 @@ class YejiStatsLogic
|
||||
$tableRowDeptIds,
|
||||
$deptById,
|
||||
$listAlignedPack !== null ? $listAlignedPack['amount'] : null,
|
||||
$channelInfo
|
||||
$channelInfo,
|
||||
$dataScopeAdminIds
|
||||
);
|
||||
$performance = $perfBoth['all'];
|
||||
$channelPerformance = $perfBoth['scoped'];
|
||||
@@ -470,7 +487,8 @@ class YejiStatsLogic
|
||||
}
|
||||
|
||||
@set_time_limit(120);
|
||||
$revisitPack = DeptLogic::getErCenterRevisitRollupIndexedByDept($startTs, $endTs);
|
||||
$revisitCreatorFilter = self::resolveYejiRevisitCreatorFilter($c);
|
||||
$revisitPack = DeptLogic::getErCenterRevisitRollupIndexedByDept($startTs, $endTs, $revisitCreatorFilter);
|
||||
$revisitTotals = $revisitPack['totals'];
|
||||
$revisitSlotsByDept = $revisitPack['slots'];
|
||||
|
||||
@@ -807,7 +825,10 @@ class YejiStatsLogic
|
||||
|
||||
$erCenterDeptSet = DeptLogic::getErCenterSubtreeDeptIdSet();
|
||||
/** 医助排行榜复诊:按订单创建人归属(与诊金 / 接诊诊单同口径),不再用 dg.assistant_id */
|
||||
$revisitByAssistant = DeptLogic::getErCenterRevisitCountsByCreator($startTs, $endTs);
|
||||
$revisitCreatorFilter = ($dataScopeRestricted && $dataScopeAdminIds !== null && $dataScopeAdminIds !== [])
|
||||
? $dataScopeAdminIds
|
||||
: null;
|
||||
$revisitByAssistant = DeptLogic::getErCenterRevisitCountsByCreator($startTs, $endTs, $revisitCreatorFilter);
|
||||
|
||||
$assistantIdRows = Db::name('admin_role')->where('role_id', 2)->column('admin_id');
|
||||
$assistantSet = [];
|
||||
@@ -1938,7 +1959,8 @@ class YejiStatsLogic
|
||||
$tableRowDeptIds,
|
||||
$deptById,
|
||||
$pack[0],
|
||||
$pack[1]
|
||||
$pack[1],
|
||||
$dataScopeAdminIds
|
||||
);
|
||||
$scopedByDept = $scopedAligned['count'];
|
||||
} else {
|
||||
@@ -3011,25 +3033,16 @@ class YejiStatsLogic
|
||||
return $out;
|
||||
}
|
||||
|
||||
$revisitCreatorFilter = self::resolveYejiRevisitCreatorFilter($c);
|
||||
$pack = DeptLogic::getErCenterRevisitAssistantBreakdownForDept(
|
||||
$deptId,
|
||||
$revisitSlot,
|
||||
(int) $c['startTs'],
|
||||
(int) $c['endTs']
|
||||
(int) $c['endTs'],
|
||||
$revisitCreatorFilter
|
||||
);
|
||||
$rows = $pack['rows'];
|
||||
|
||||
if (!empty($c['dataScopeRestricted']) && isset($c['dataScopeVisibleAdminIds'])) {
|
||||
$flip = array_flip($c['dataScopeVisibleAdminIds']);
|
||||
$filtered = [];
|
||||
foreach ($rows as $rw) {
|
||||
if (isset($flip[(int) ($rw['admin_id'] ?? 0)])) {
|
||||
$filtered[] = $rw;
|
||||
}
|
||||
}
|
||||
$rows = $filtered;
|
||||
}
|
||||
|
||||
$out['rows'] = $rows;
|
||||
if ($rows === []) {
|
||||
$out['note'] = '当前部门与区间下无符合条件的复诊业务订单(口径与看板「二中心复诊」列一致)。';
|
||||
@@ -3038,6 +3051,28 @@ class YejiStatsLogic
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二中心复诊统计:数据范围下仅统计可见创建人的复诊笔数(与合计业绩一致)。
|
||||
*
|
||||
* @param array<string, mixed> $c
|
||||
*
|
||||
* @return int[]|null null=不限制;[]=无可见创建人
|
||||
*/
|
||||
private static function resolveYejiRevisitCreatorFilter(array $c): ?array
|
||||
{
|
||||
if (empty($c['dataScopeRestricted']) || !isset($c['dataScopeVisibleAdminIds'])) {
|
||||
return null;
|
||||
}
|
||||
if (!\is_array($c['dataScopeVisibleAdminIds']) || $c['dataScopeVisibleAdminIds'] === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter(
|
||||
array_map('intval', $c['dataScopeVisibleAdminIds']),
|
||||
static fn (int $v): bool => $v > 0
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 sumPerformance 对应,按 admin 维度返回全量/渠道业绩金额(不按部门折叠)。
|
||||
* 归属固定为 sqlPerformanceAttributionAdminExpr()——按订单创建人。
|
||||
@@ -3711,7 +3746,8 @@ class YejiStatsLogic
|
||||
array $tableRowDeptIds = [],
|
||||
array $deptById = [],
|
||||
?array $precomputedListAlignedAmountByDept = null,
|
||||
?array $channelInfo = null
|
||||
?array $channelInfo = null,
|
||||
?array $dataScopeAdminIds = null
|
||||
): array {
|
||||
if ($adminToPrimary === []) {
|
||||
return ['all' => [], 'scoped' => []];
|
||||
@@ -3730,7 +3766,10 @@ class YejiStatsLogic
|
||||
null,
|
||||
null,
|
||||
$tableRowDeptIds,
|
||||
$deptById
|
||||
$deptById,
|
||||
null,
|
||||
[],
|
||||
$dataScopeAdminIds
|
||||
);
|
||||
$allByDept = [];
|
||||
foreach ($aligned['amount'] as $deptId => $v) {
|
||||
@@ -3770,7 +3809,8 @@ class YejiStatsLogic
|
||||
$tableRowDeptIds,
|
||||
$deptById,
|
||||
$pack[0],
|
||||
$pack[1]
|
||||
$pack[1],
|
||||
$dataScopeAdminIds
|
||||
);
|
||||
$scopedByDept = [];
|
||||
foreach ($scopedAligned['amount'] as $deptId => $v) {
|
||||
@@ -4085,7 +4125,8 @@ class YejiStatsLogic
|
||||
array $tableRowDeptIds,
|
||||
array $deptById,
|
||||
?string $channelScopedExistsSql = null,
|
||||
array $channelScopedExistsBindings = []
|
||||
array $channelScopedExistsBindings = [],
|
||||
?array $dataScopeAdminIds = null
|
||||
): array {
|
||||
if ($tagDiagIds !== null && $tagDiagIds === []) {
|
||||
return ['count' => [], 'amount' => []];
|
||||
@@ -4115,6 +4156,9 @@ class YejiStatsLogic
|
||||
$in = implode(',', $ids);
|
||||
$query->whereRaw("o.creator_id IN ({$in})");
|
||||
}
|
||||
if ($dataScopeAdminIds !== null && $dataScopeAdminIds !== []) {
|
||||
$query->whereIn('o.creator_id', $dataScopeAdminIds);
|
||||
}
|
||||
if ($channelScopedExistsSql !== null && $channelScopedExistsSql !== '') {
|
||||
$query->whereRaw($channelScopedExistsSql, $channelScopedExistsBindings);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user