修复bug
This commit is contained in:
@@ -221,7 +221,9 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
|
||||
/**
|
||||
* 非「业务订单全量」角色:默认仅本人创建;若持有 viewOrdersForOwnPrescription 则包含关联处方开方人为本人的订单
|
||||
* 非「业务订单全量」角色:默认仅本人创建;若持有 viewOrdersForOwnPrescription 则包含关联处方开方人为本人的订单;
|
||||
* 另含「关联诊单医助为本人」以便医助跟进出单与履约。
|
||||
* 显式筛选 assistant_id 时:若该医助落在当前账号数据域内,则允许按「诊单医助 / 订单创建人」命中(与 applyDoctorAssistantFilters 一致)。
|
||||
*/
|
||||
private function applyCreatorOrOwnPrescriptionVisibility($query): void
|
||||
{
|
||||
@@ -229,19 +231,60 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
return;
|
||||
}
|
||||
$adminId = (int) $this->adminId;
|
||||
if (PrescriptionOrderLogic::canViewOrdersForOwnPrescription($this->adminInfo)) {
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
$query->where(function ($q) use ($poTbl, $rxTbl, $adminId) {
|
||||
$q->where('creator_id', $adminId);
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$rxTbl}` rx WHERE rx.`id` = `{$poTbl}`.`prescription_id`"
|
||||
. " AND rx.`delete_time` IS NULL AND rx.`creator_id` = {$adminId})"
|
||||
);
|
||||
});
|
||||
} else {
|
||||
$query->where('creator_id', $adminId);
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
|
||||
$explicitAssistant = (int) ($this->params['assistant_id'] ?? 0);
|
||||
$allowExplicitAssistantVisibility = false;
|
||||
if ($explicitAssistant > 0) {
|
||||
if (!$this->dataScopeShouldApply()) {
|
||||
$allowExplicitAssistantVisibility = true;
|
||||
} else {
|
||||
$visibleIds = $this->getDataScopeVisibleAdminIds();
|
||||
if ($visibleIds === null || in_array($explicitAssistant, $visibleIds, true)) {
|
||||
$allowExplicitAssistantVisibility = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query->where(function ($q) use (
|
||||
$poTbl,
|
||||
$rxTbl,
|
||||
$diagTbl,
|
||||
$adminId,
|
||||
$explicitAssistant,
|
||||
$allowExplicitAssistantVisibility
|
||||
) {
|
||||
if (PrescriptionOrderLogic::canViewOrdersForOwnPrescription($this->adminInfo)) {
|
||||
$q->where(function ($qq) use ($poTbl, $rxTbl, $diagTbl, $adminId) {
|
||||
$qq->where('creator_id', $adminId);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$rxTbl}` rx WHERE rx.`id` = `{$poTbl}`.`prescription_id`"
|
||||
. " AND rx.`delete_time` IS NULL AND rx.`creator_id` = {$adminId})"
|
||||
);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$adminId})"
|
||||
);
|
||||
});
|
||||
} else {
|
||||
$q->where(function ($qq) use ($poTbl, $diagTbl, $adminId) {
|
||||
$qq->where('creator_id', $adminId);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$adminId})"
|
||||
);
|
||||
});
|
||||
}
|
||||
if ($allowExplicitAssistantVisibility) {
|
||||
$q->whereOr('creator_id', $explicitAssistant);
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$explicitAssistant})"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -813,7 +856,9 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
|
||||
/**
|
||||
* 按开方医生(关联处方 creator_id)/ 诊单医助(关联诊单 assistant_id)筛选
|
||||
* 按开方医生(关联处方 creator_id)/ 诊单医助筛选
|
||||
*
|
||||
* 医助:诊单 assistant_id 与业务订单 creator_id 并举——医助常代建单但诊单未写 assistant_id。
|
||||
*/
|
||||
private function applyDoctorAssistantFilters($query): void
|
||||
{
|
||||
@@ -828,7 +873,13 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
if (isset($this->params['assistant_id']) && (int) $this->params['assistant_id'] > 0) {
|
||||
$assistantId = (int) $this->params['assistant_id'];
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$diagTbl} dg WHERE dg.id = {$poTbl}.diagnosis_id AND dg.delete_time IS NULL AND dg.assistant_id = {$assistantId}");
|
||||
$query->where(function ($q) use ($poTbl, $diagTbl, $assistantId) {
|
||||
$q->where('creator_id', $assistantId);
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$assistantId})"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($this->params['assistant_dept_id']) && $this->params['assistant_dept_id'] !== '' && (int) $this->params['assistant_dept_id'] > 0) {
|
||||
@@ -845,10 +896,16 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$inList = implode(',', $deptIds);
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$adTbl = (new AdminDept())->getTable();
|
||||
$query->whereExists(
|
||||
"SELECT 1 FROM `{$adTbl}` ad INNER JOIN `{$diagTbl}` dg ON ad.admin_id = dg.assistant_id AND dg.delete_time IS NULL "
|
||||
. "WHERE dg.id = `{$poTbl}`.`diagnosis_id` AND ad.dept_id IN ({$inList})"
|
||||
);
|
||||
$query->where(function ($q) use ($poTbl, $diagTbl, $adTbl, $inList) {
|
||||
$q->whereExists(
|
||||
"SELECT 1 FROM `{$adTbl}` ad INNER JOIN `{$diagTbl}` dg ON ad.admin_id = dg.assistant_id AND dg.delete_time IS NULL "
|
||||
. "WHERE dg.`id` = `{$poTbl}`.`diagnosis_id` AND ad.dept_id IN ({$inList})"
|
||||
);
|
||||
$q->whereExists(
|
||||
"SELECT 1 FROM `{$adTbl}` adc WHERE adc.`admin_id` = `{$poTbl}`.`creator_id` AND adc.`dept_id` IN ({$inList})",
|
||||
'OR'
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -536,18 +536,22 @@ class DiagnosisLogic extends BaseLogic
|
||||
*/
|
||||
public static function assignLogList(int $diagnosisId): array
|
||||
{
|
||||
$rows = DiagnosisAssignLog::where('diagnosis_id', $diagnosisId)
|
||||
// Db 直查:避免 AssignLog 模型未维护 schema / fields_strict 时 toArray 丢列,导致前后端「医助」为空
|
||||
$rows = Db::name('tcm_diagnosis_assign_log')
|
||||
->where('diagnosis_id', $diagnosisId)
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$adminIds = [];
|
||||
foreach ($rows as $r) {
|
||||
if (!empty($r['from_assistant_id'])) {
|
||||
$adminIds[] = (int) $r['from_assistant_id'];
|
||||
$fid = (int) ($r['from_assistant_id'] ?? 0);
|
||||
$tid = (int) ($r['to_assistant_id'] ?? 0);
|
||||
if ($fid > 0) {
|
||||
$adminIds[] = $fid;
|
||||
}
|
||||
if (!empty($r['to_assistant_id'])) {
|
||||
$adminIds[] = (int) $r['to_assistant_id'];
|
||||
if ($tid > 0) {
|
||||
$adminIds[] = $tid;
|
||||
}
|
||||
$rcp = (int) ($r['related_po_creator_id'] ?? 0);
|
||||
if ($rcp > 0) {
|
||||
@@ -557,7 +561,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds)));
|
||||
$nameMap = [];
|
||||
if ($adminIds !== []) {
|
||||
$nameMap = \app\common\model\auth\Admin::whereIn('id', $adminIds)->column('name', 'id');
|
||||
$nameMap = Admin::whereIn('id', $adminIds)->column('name', 'id');
|
||||
}
|
||||
|
||||
foreach ($rows as &$r) {
|
||||
@@ -583,7 +587,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
unset($r);
|
||||
|
||||
return $rows;
|
||||
return array_values($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\DataScope\DataScopeService;
|
||||
use app\common\service\ExpressTrackService;
|
||||
use app\common\service\gancao\GancaoScmRecipelService;
|
||||
use think\facade\Config;
|
||||
@@ -136,6 +137,30 @@ class PrescriptionOrderLogic
|
||||
return $cid === $adminId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 PrescriptionOrderLists 数据域一致:创建人或关联诊单医助属于当前账号可见 admin 集合
|
||||
*/
|
||||
private static function orderWithinDataScopeOwners(PrescriptionOrder $row, int $adminId, array $adminInfo): bool
|
||||
{
|
||||
if (!DataScopeService::isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
$ids = DataScopeService::getVisibleAdminIds($adminId, $adminInfo);
|
||||
if ($ids === null || $ids === []) {
|
||||
return false;
|
||||
}
|
||||
if (in_array((int) $row->creator_id, $ids, true)) {
|
||||
return true;
|
||||
}
|
||||
$did = (int) $row->diagnosis_id;
|
||||
if ($did <= 0) {
|
||||
return false;
|
||||
}
|
||||
$da = (int) Diagnosis::where('id', $did)->whereNull('delete_time')->value('assistant_id');
|
||||
|
||||
return $da > 0 && in_array($da, $ids, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PrescriptionOrder $row
|
||||
*/
|
||||
@@ -147,8 +172,20 @@ class PrescriptionOrderLogic
|
||||
if ((int) $row->creator_id === $adminId) {
|
||||
return true;
|
||||
}
|
||||
$did = (int) $row->diagnosis_id;
|
||||
if ($did > 0) {
|
||||
$da = (int) Diagnosis::where('id', $did)->whereNull('delete_time')->value('assistant_id');
|
||||
if ($da === $adminId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (self::canViewOrdersForOwnPrescription($adminInfo)) {
|
||||
return self::isPrescriptionOrderPrescriber((int) $row->prescription_id, $adminId);
|
||||
if (self::isPrescriptionOrderPrescriber((int) $row->prescription_id, $adminId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (self::orderWithinDataScopeOwners($row, $adminId, $adminInfo)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -47,10 +47,15 @@ trait ListsSearchTrait
|
||||
case 'in':
|
||||
foreach ($whereFields as $whereField) {
|
||||
$paramsName = substr_symbol_behind($whereField);
|
||||
if (!isset($this->params[$paramsName]) || $this->params[$paramsName] == '') {
|
||||
if (!isset($this->params[$paramsName])) {
|
||||
continue;
|
||||
}
|
||||
$where[] = [$whereField, $whereType, $this->params[$paramsName]];
|
||||
$paramVal = $this->params[$paramsName];
|
||||
// 勿用 == '':PHP 中 0 == '' 为 true,会误跳过 prescription_audit_status=0 等合法筛选
|
||||
if ($paramVal === '' || $paramVal === null) {
|
||||
continue;
|
||||
}
|
||||
$where[] = [$whereField, $whereType, $paramVal];
|
||||
}
|
||||
break;
|
||||
case '%like%':
|
||||
@@ -95,10 +100,14 @@ trait ListsSearchTrait
|
||||
case 'find_in_set': // find_in_set查询
|
||||
foreach ($whereFields as $whereField) {
|
||||
$paramsName = substr_symbol_behind($whereField);
|
||||
if (!isset($this->params[$paramsName]) || $this->params[$paramsName] == '') {
|
||||
if (!isset($this->params[$paramsName])) {
|
||||
continue;
|
||||
}
|
||||
$where[] = [$whereField, 'find in set', $this->params[$paramsName]];
|
||||
$paramVal = $this->params[$paramsName];
|
||||
if ($paramVal === '' || $paramVal === null) {
|
||||
continue;
|
||||
}
|
||||
$where[] = [$whereField, 'find in set', $paramVal];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user