更新
This commit is contained in:
@@ -2115,19 +2115,34 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
/**
|
||||
* @notes 获取医助列表
|
||||
* @param int $adminId 当前管理员 id(用于数据范围;0 表示不过滤)
|
||||
* @param array|null $adminInfo 当前管理员信息(用于数据范围;null 表示不过滤)
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssistants()
|
||||
public static function getAssistants(int $adminId = 0, ?array $adminInfo = null)
|
||||
{
|
||||
try {
|
||||
// 这里不要用 Admin 模型查询,否则会触发其 append(role_id/dept_id/jobs_id)
|
||||
// 每行再发多次查询,形成严重 N+1,统计页会被拖慢到十几秒。
|
||||
$assistants = \think\facade\Db::name('admin')
|
||||
$query = \think\facade\Db::name('admin')
|
||||
->alias('a')
|
||||
->join('admin_role ar', 'a.id = ar.admin_id')
|
||||
->where('ar.role_id', 2)
|
||||
->where('a.disable', 0)
|
||||
->whereNull('a.delete_time')
|
||||
->whereNull('a.delete_time');
|
||||
|
||||
// 数据范围:仅展示当前管理员可见的医助;null = 全部不过滤
|
||||
if ($adminInfo !== null && $adminId > 0) {
|
||||
$visibleIds = \app\common\service\DataScope\DataScopeService::getVisibleAdminIds($adminId, $adminInfo);
|
||||
if ($visibleIds !== null) {
|
||||
if ($visibleIds === []) {
|
||||
return [];
|
||||
}
|
||||
$query->whereIn('a.id', $visibleIds);
|
||||
}
|
||||
}
|
||||
|
||||
$assistants = $query
|
||||
->field(['a.id', 'a.name', 'a.account'])
|
||||
->order('a.id', 'asc')
|
||||
->distinct(true)
|
||||
@@ -3105,10 +3120,15 @@ class DiagnosisLogic extends BaseLogic
|
||||
* @param array $params start_time, end_time, days(可选,默认7)
|
||||
* @return array
|
||||
*/
|
||||
public static function assistantDiagnosisStats(array $params = [])
|
||||
public static function assistantDiagnosisStats(array $params = [], int $adminId = 0, ?array $adminInfo = null)
|
||||
{
|
||||
$days = isset($params['days']) ? (int)$params['days'] : 7;
|
||||
|
||||
// 数据范围:当前用户可见 admin id 集合;null 表示全部
|
||||
$visibleAdminIds = ($adminInfo !== null && $adminId > 0)
|
||||
? \app\common\service\DataScope\DataScopeService::getVisibleAdminIds($adminId, $adminInfo)
|
||||
: null;
|
||||
|
||||
$endTime = !empty($params['end_time']) ? strtotime($params['end_time']) : time();
|
||||
if ($days === 0) {
|
||||
$startTime = strtotime(date('Y-m-d'));
|
||||
@@ -3127,6 +3147,13 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
$assistantIds = \app\common\model\auth\AdminRole::where('role_id', 2)
|
||||
->column('admin_id');
|
||||
// 数据范围交集:仅展示「医助 ∩ 当前用户可见」
|
||||
if ($visibleAdminIds !== null) {
|
||||
$assistantIds = array_values(array_intersect(
|
||||
array_map('intval', $assistantIds),
|
||||
array_map('intval', $visibleAdminIds)
|
||||
));
|
||||
}
|
||||
if (empty($assistantIds)) {
|
||||
return [
|
||||
'date_range' => [date('Y-m-d', $startTime), date('Y-m-d', $endTime)],
|
||||
@@ -3192,6 +3219,9 @@ class DiagnosisLogic extends BaseLogic
|
||||
usort($todayRanking, fn($a, $b) => $b['count'] <=> $a['count']);
|
||||
$todayRanking = array_values(array_filter($todayRanking, fn($a) => $a['count'] > 0));
|
||||
|
||||
// 数据范围启用时(非 root/全部范围),无可见成员的部门不渲染
|
||||
$hideEmptyDept = $visibleAdminIds !== null;
|
||||
|
||||
$deptData = [];
|
||||
$assignedAdminIds = [];
|
||||
foreach ($depts as $deptId => $deptName) {
|
||||
@@ -3208,6 +3238,9 @@ class DiagnosisLogic extends BaseLogic
|
||||
'count' => $cnt,
|
||||
];
|
||||
}
|
||||
if ($hideEmptyDept && $assistants === []) {
|
||||
continue;
|
||||
}
|
||||
$deptData[] = [
|
||||
'dept_id' => (int)$deptId,
|
||||
'dept_name' => $deptName,
|
||||
|
||||
Reference in New Issue
Block a user