更新
This commit is contained in:
@@ -26,8 +26,9 @@ class MyPatientLogic
|
||||
|
||||
/**
|
||||
* @param Query $query 以 d 作为 zyt_tcm_diagnosis 别名的查询
|
||||
* @param int[]|null $currentRoleIds 可选:调用方已从 DB 当前读核验的有效角色;禁止使用请求参数
|
||||
*/
|
||||
public static function applyScope(Query $query, int $adminId, array $adminInfo): void
|
||||
public static function applyScope(Query $query, int $adminId, array $adminInfo, ?array $currentRoleIds = null): void
|
||||
{
|
||||
if ($adminId <= 0) {
|
||||
$query->whereRaw('0 = 1');
|
||||
@@ -39,9 +40,12 @@ class MyPatientLogic
|
||||
return;
|
||||
}
|
||||
|
||||
$roleIds = self::roleIds($adminId);
|
||||
$roleIds = $currentRoleIds === null ? self::roleIds($adminId) : self::normalizeIds($currentRoleIds);
|
||||
$appointmentTable = (new Appointment())->getTable();
|
||||
$statusList = implode(',', self::EFFECTIVE_APPOINTMENT_STATUSES);
|
||||
// 新授权入口已显式要求当前读时,预约子查询也必须使用当前读。
|
||||
// 仅外层 FOR UPDATE 不会把 EXISTS 内部从 MySQL RR 旧快照切换出来。
|
||||
$appointmentLock = $currentRoleIds !== null && $query->getConfig('type') === 'mysql' ? ' FOR UPDATE' : '';
|
||||
|
||||
// 管理角色按系统的数据范围查看“范围内医助归属或医生接诊”的患者。
|
||||
if (array_intersect($roleIds, self::TEAM_ROLE_IDS) !== []) {
|
||||
@@ -61,7 +65,7 @@ class MyPatientLogic
|
||||
. " OR EXISTS (SELECT 1 FROM {$appointmentTable} scope_apt"
|
||||
. ' WHERE scope_apt.patient_id = d.id'
|
||||
. " AND scope_apt.status IN ({$statusList})"
|
||||
. " AND scope_apt.doctor_id IN ({$ids})))"
|
||||
. " AND scope_apt.doctor_id IN ({$ids}){$appointmentLock}))"
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -76,7 +80,7 @@ class MyPatientLogic
|
||||
$conditions[] = "EXISTS (SELECT 1 FROM {$appointmentTable} scope_apt"
|
||||
. ' WHERE scope_apt.patient_id = d.id'
|
||||
. " AND scope_apt.status IN ({$statusList})"
|
||||
. " AND scope_apt.doctor_id = {$adminId})";
|
||||
. " AND scope_apt.doctor_id = {$adminId}{$appointmentLock})";
|
||||
}
|
||||
|
||||
// 未知/异常角色按本人医助或本人医生关系收窄,拒绝意外放大全库。
|
||||
@@ -85,7 +89,7 @@ class MyPatientLogic
|
||||
$conditions[] = "EXISTS (SELECT 1 FROM {$appointmentTable} scope_apt"
|
||||
. ' WHERE scope_apt.patient_id = d.id'
|
||||
. " AND scope_apt.status IN ({$statusList})"
|
||||
. " AND scope_apt.doctor_id = {$adminId})";
|
||||
. " AND scope_apt.doctor_id = {$adminId}{$appointmentLock})";
|
||||
}
|
||||
|
||||
$query->whereRaw('(' . implode(' OR ', $conditions) . ')');
|
||||
|
||||
Reference in New Issue
Block a user