更新
This commit is contained in:
@@ -19,11 +19,15 @@ use app\common\lists\ListsExcelInterface;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\ListsSortInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\auth\SystemRole;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Jobs;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
@@ -32,6 +36,7 @@ use app\common\model\dept\Jobs;
|
||||
*/
|
||||
class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, ListsSearchInterface, ListsSortInterface,ListsExcelInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
/**
|
||||
* @notes 设置导出字段
|
||||
* @return string[]
|
||||
@@ -116,9 +121,37 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
|
||||
|
||||
if ($progressBoard) {
|
||||
// 面诊进度:固定只拉「医生」角色且未禁用,忽略客户端篡改的 role_id
|
||||
$adminIds = AdminRole::where('role_id', 1)->column('admin_id');
|
||||
$adminIds = array_map('intval', AdminRole::where('role_id', 1)->column('admin_id'));
|
||||
|
||||
// 数据范围:医生与业务/医助通常不在同一部门,按 admin id 直接取交集会全空。
|
||||
// 这里改为「按当前账号可见的挂号反查涉及的医生」,与 AppointmentLists 的可见性一致:
|
||||
// 可见挂号 = a.doctor_id ∈ visible OR diagnosis.assistant_id ∈ visible
|
||||
$visibleIds = $this->getDataScopeVisibleAdminIds();
|
||||
if ($visibleIds !== null) {
|
||||
if ($visibleIds === [] || $adminIds === []) {
|
||||
$adminIds = [];
|
||||
} else {
|
||||
$aTbl = (new Appointment())->getTable();
|
||||
$dTbl = (new Diagnosis())->getTable();
|
||||
$inList = implode(',', array_map('intval', $visibleIds));
|
||||
$rows = Db::query(
|
||||
"SELECT DISTINCT a.doctor_id FROM `{$aTbl}` a "
|
||||
. "LEFT JOIN `{$dTbl}` u ON a.patient_id = u.id "
|
||||
. "WHERE (a.doctor_id IN ({$inList}) "
|
||||
. " OR (u.id IS NOT NULL AND u.delete_time IS NULL AND u.assistant_id IN ({$inList})))"
|
||||
);
|
||||
$apptDoctorIds = array_filter(array_map(static function ($r): int {
|
||||
return (int) ($r['doctor_id'] ?? 0);
|
||||
}, $rows ?: []));
|
||||
$adminIds = array_values(array_intersect($adminIds, $apptDoctorIds));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($adminIds)) {
|
||||
$where[] = ['id', 'in', $adminIds];
|
||||
} else {
|
||||
// 数据范围下没有可见医生:强制空集
|
||||
$where[] = ['id', '=', 0];
|
||||
}
|
||||
$where[] = ['disable', '=', 0];
|
||||
} else {
|
||||
@@ -134,6 +167,19 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
|
||||
}
|
||||
}
|
||||
|
||||
// 数据范围:仅当调用方主动传 apply_data_scope=1 时启用
|
||||
// (管理员表被多场景共用:医生/医助选择器、看板、组织架构等;不主动启用避免误伤)
|
||||
if ((int) ($this->params['apply_data_scope'] ?? 0) === 1) {
|
||||
$visibleIds = $this->getDataScopeVisibleAdminIds();
|
||||
if ($visibleIds !== null) {
|
||||
if ($visibleIds === []) {
|
||||
$where[] = ['id', '=', 0]; // 强制空
|
||||
} else {
|
||||
$where[] = ['id', 'in', $visibleIds];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class RoleLists extends BaseAdminDataLists
|
||||
public function lists(): array
|
||||
{
|
||||
$lists = SystemRole::with(['role_menu_index'])
|
||||
->field('id,name,desc,sort,create_time')
|
||||
->field('id,name,desc,sort,data_scope,create_time')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
|
||||
@@ -9,6 +9,7 @@ use app\common\model\tcm\Prescription;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
|
||||
/**
|
||||
* 医生预约列表
|
||||
@@ -17,6 +18,31 @@ use app\common\lists\ListsSearchInterface;
|
||||
*/
|
||||
class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
|
||||
/**
|
||||
* 数据隔离:医生或医助(u.assistant_id = diag.assistant_id)命中可见集合;progress_board 场景放开(看板跨医生查看)
|
||||
*/
|
||||
private function applyDataScopeForAppointment($query, bool $progressBoard): void
|
||||
{
|
||||
if ($progressBoard) {
|
||||
return;
|
||||
}
|
||||
if (!$this->dataScopeShouldApply()) {
|
||||
return;
|
||||
}
|
||||
$ids = $this->getDataScopeVisibleAdminIds();
|
||||
if ($ids === null) {
|
||||
return;
|
||||
}
|
||||
if ($ids === []) {
|
||||
$query->whereRaw('0 = 1');
|
||||
|
||||
return;
|
||||
}
|
||||
$inList = implode(',', $ids);
|
||||
$query->whereRaw("(a.doctor_id IN ({$inList}) OR u.assistant_id IN ({$inList}))");
|
||||
}
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return array
|
||||
@@ -114,6 +140,8 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
}
|
||||
}
|
||||
|
||||
$this->applyDataScopeForAppointment($query, $progressBoard);
|
||||
|
||||
// 诊单软删除后不再展示对应挂号(leftJoin 时无诊单或诊单未删)
|
||||
$query->whereRaw('(u.id IS NULL OR u.delete_time IS NULL)');
|
||||
|
||||
@@ -269,6 +297,8 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
}
|
||||
}
|
||||
|
||||
$this->applyDataScopeForAppointment($query, $progressBoard);
|
||||
|
||||
$query->whereRaw('(u.id IS NULL OR u.delete_time IS NULL)');
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace app\adminapi\lists\order;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\auth\AdminRole;
|
||||
|
||||
@@ -16,6 +17,7 @@ use app\common\model\auth\AdminRole;
|
||||
*/
|
||||
class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
/**
|
||||
* 将列表「创建时间」参数规范为可解析的日期时间(datetimerange 已是 Y-m-d H:i:s,不能再去拼接 00:00:00,否则会变成非法字符串)
|
||||
*/
|
||||
@@ -214,7 +216,9 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
|
||||
$this->appendCreateTimeWhere($where);
|
||||
|
||||
return Order::where($where)
|
||||
$query = Order::where($where);
|
||||
$this->applyDataScopeByOwner($query, 'creator_id');
|
||||
return $query
|
||||
->with(['patient', 'creator'])
|
||||
->order(['create_time' => 'desc'])
|
||||
->limit($this->limitOffset, $this->pageSize)
|
||||
@@ -251,6 +255,8 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
|
||||
$this->appendCreateTimeWhere($where);
|
||||
|
||||
return Order::where($where)->count();
|
||||
$query = Order::where($where);
|
||||
$this->applyDataScopeByOwner($query, 'creator_id');
|
||||
return $query->count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminDept;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
|
||||
/**
|
||||
* 中医辨房病因诊单列表
|
||||
@@ -33,6 +34,7 @@ use app\common\lists\ListsSearchInterface;
|
||||
*/
|
||||
class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return array
|
||||
@@ -70,6 +72,10 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->where('assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
if (!$pendingAssign) {
|
||||
$this->applyDataScopeByOwner($query, 'assistant_id');
|
||||
}
|
||||
|
||||
// 关键字搜索:支持患者姓名或手机号(模糊匹配)
|
||||
if (isset($this->params['keyword']) && trim((string) $this->params['keyword']) !== '') {
|
||||
$keyword = trim((string) $this->params['keyword']);
|
||||
@@ -459,6 +465,10 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->where('assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
if (!$pendingAssign) {
|
||||
$this->applyDataScopeByOwner($query, 'assistant_id');
|
||||
}
|
||||
|
||||
// 关键字搜索:支持患者姓名或手机号(模糊匹配)
|
||||
if (isset($this->params['keyword']) && trim((string) $this->params['keyword']) !== '') {
|
||||
$keyword = trim((string) $this->params['keyword']);
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use app\adminapi\logic\tcm\PrescriptionLogic;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
@@ -15,6 +16,7 @@ use app\common\model\tcm\PrescriptionOrder;
|
||||
*/
|
||||
class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
/**
|
||||
* @notes 搜索条件
|
||||
*/
|
||||
@@ -138,6 +140,7 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$this->applySourceFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
$this->applyDataScopeByOwnerColumns($query, ['creator_id', 'assistant_id']);
|
||||
|
||||
$lists = $query
|
||||
->whereNull('delete_time')
|
||||
@@ -231,6 +234,7 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$this->applySourceFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
$this->applyDataScopeByOwnerColumns($query, ['creator_id', 'assistant_id']);
|
||||
|
||||
return $query->whereNull('delete_time')->count();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use app\adminapi\logic\dept\DeptLogic;
|
||||
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\auth\AdminDept;
|
||||
@@ -21,6 +22,8 @@ use think\db\Query;
|
||||
|
||||
class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
@@ -76,6 +79,36 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
});
|
||||
}
|
||||
$this->applyDataScopeForPrescriptionOrder($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据隔离:创建者 ∈ 可见 admin,或 关联诊单医助 ∈ 可见 admin
|
||||
*/
|
||||
private function applyDataScopeForPrescriptionOrder($query): void
|
||||
{
|
||||
if (!$this->dataScopeShouldApply()) {
|
||||
return;
|
||||
}
|
||||
$ids = $this->getDataScopeVisibleAdminIds();
|
||||
if ($ids === null) {
|
||||
return;
|
||||
}
|
||||
if ($ids === []) {
|
||||
$query->whereRaw('0 = 1');
|
||||
|
||||
return;
|
||||
}
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$inList = implode(',', $ids);
|
||||
$query->where(function ($q) use ($poTbl, $diagTbl, $inList) {
|
||||
$q->whereIn('creator_id', explode(',', $inList));
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id` "
|
||||
. "AND dg.`delete_time` IS NULL AND dg.`assistant_id` IN ({$inList}))"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,12 +133,14 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$this->applyDoctorAssistantFilters($query);
|
||||
$this->applyPatientKeywordFilter($query);
|
||||
if (PrescriptionOrderLogic::canViewOrderListStatsAllScope($this->adminInfo)) {
|
||||
$this->applyDataScopeForPrescriptionOrder($query);
|
||||
return $query;
|
||||
}
|
||||
$assistantRid = (int) Config::get('project.prescription_order_stats_assistant_role_id', 2);
|
||||
$myRoles = array_map('intval', $this->adminInfo['role_id'] ?? []);
|
||||
if ($assistantRid > 0 && in_array($assistantRid, $myRoles, true)) {
|
||||
$this->applyAssistantDiagnosisOnlyFilter($query);
|
||||
$this->applyDataScopeForPrescriptionOrder($query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
@@ -118,6 +153,7 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
});
|
||||
}
|
||||
$this->applyDataScopeForPrescriptionOrder($query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user