更新
This commit is contained in:
@@ -39,7 +39,13 @@ class DoctorDailyStatsLogic
|
||||
*
|
||||
* @return array{start_date:string,end_date:string,rows:array,total:array<string,mixed>}
|
||||
*/
|
||||
public static function overview(array $params, int $viewerAdminId = 0, array $viewerAdminInfo = []): array
|
||||
public static function overview(
|
||||
array $params,
|
||||
int $viewerAdminId = 0,
|
||||
array $viewerAdminInfo = [],
|
||||
?array $trustedDoctorIds = null,
|
||||
?array $trustedAssistantIds = null
|
||||
): array
|
||||
{
|
||||
// dept_ids 透传至共享上下文:未传时仍按默认「中心」树解析(仅用于挂号率默认 0 等兜底);
|
||||
// 显式传入时由下方 $deptScopedAdminIds 分支用 adminToPrimary 取出医助集合,并下推到三类聚合作为「经手医助」筛选。
|
||||
@@ -57,7 +63,9 @@ class DoctorDailyStatsLogic
|
||||
$filterDoctorId = (int) ($params['doctor_id'] ?? 0);
|
||||
$deptFilterActive = self::hasExplicitDeptIds($params['dept_ids'] ?? null);
|
||||
|
||||
$doctorIds = self::resolveDoctorAdminIdsForStats($viewerAdminId, $viewerAdminInfo);
|
||||
$doctorIds = $trustedDoctorIds === null
|
||||
? self::resolveDoctorAdminIdsForStats($viewerAdminId, $viewerAdminInfo)
|
||||
: self::resolveTrustedDoctorIds($trustedDoctorIds);
|
||||
|
||||
if ($filterDoctorId > 0) {
|
||||
$doctorIds = in_array($filterDoctorId, $doctorIds, true) ? [$filterDoctorId] : [];
|
||||
@@ -65,8 +73,10 @@ class DoctorDailyStatsLogic
|
||||
|
||||
// 部门下医助集合(含全部子级展开后的 admin_dept 命中者);未显式选部门时不参与筛选 → null。
|
||||
// 显式选部门但集合为空 ⇒ 该部门下无可见医助,直接返回空结果。
|
||||
$deptScopedAdminIds = null;
|
||||
if ($deptFilterActive) {
|
||||
$deptScopedAdminIds = $trustedAssistantIds === null
|
||||
? null
|
||||
: self::normalizePositiveIds($trustedAssistantIds);
|
||||
if ($trustedAssistantIds === null && $deptFilterActive) {
|
||||
$deptScopedAdminIds = array_values(array_unique(array_map(
|
||||
'intval',
|
||||
array_keys($ctx['adminToPrimary'] ?? [])
|
||||
@@ -159,7 +169,7 @@ class DoctorDailyStatsLogic
|
||||
}
|
||||
|
||||
// 显式部门筛选时隐藏「该部门无任何关联」的医生,避免列出大量全 0 行。
|
||||
if ($deptFilterActive) {
|
||||
if ($deptFilterActive || $trustedAssistantIds !== null) {
|
||||
$rows = array_values(array_filter($rows, static function (array $r): bool {
|
||||
return (int) ($r['system_prescription_count'] ?? 0) > 0
|
||||
|| (int) ($r['manual_prescription_count'] ?? 0) > 0
|
||||
@@ -243,6 +253,37 @@ class DoctorDailyStatsLogic
|
||||
return $doctorIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅供服务端内部聚合页传入已经过权限计算的医生集合;仍再次校验医生角色与软删除状态。
|
||||
* HTTP 参数不会进入此分支。
|
||||
*
|
||||
* @param array<int|string,mixed> $trustedDoctorIds
|
||||
* @return int[]
|
||||
*/
|
||||
private static function resolveTrustedDoctorIds(array $trustedDoctorIds): array
|
||||
{
|
||||
$ids = self::normalizePositiveIds($trustedDoctorIds);
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::normalizePositiveIds(Db::name('admin_role')->alias('ar')
|
||||
->join('admin a', 'a.id = ar.admin_id')
|
||||
->where('ar.role_id', 1)
|
||||
->whereIn('ar.admin_id', $ids)
|
||||
->whereNull('a.delete_time')
|
||||
->column('ar.admin_id'));
|
||||
}
|
||||
|
||||
/** @param array<int|string,mixed> $ids @return int[] */
|
||||
private static function normalizePositiveIds(array $ids): array
|
||||
{
|
||||
return array_values(array_unique(array_filter(array_map(
|
||||
'intval',
|
||||
$ids
|
||||
), static fn (int $id): bool => $id > 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, float|int|null>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user