修复bug

This commit is contained in:
Your Name
2026-05-08 10:49:32 +08:00
parent 8c640abb26
commit 43110e015d
6 changed files with 169 additions and 36 deletions
@@ -2,8 +2,16 @@
<div class="assign-log-panel">
<el-table v-loading="loading" :data="rows" border stripe empty-text="暂无指派记录">
<el-table-column label="操作时间" width="175" prop="create_time_text" />
<el-table-column label="原医助" min-width="120" prop="from_assistant_name" />
<el-table-column label="新医助" min-width="120" prop="to_assistant_name" />
<el-table-column label="原医助" min-width="120">
<template #default="{ row }">
{{ assistantLogCellText(row, 'from') }}
</template>
</el-table-column>
<el-table-column label="新医助" min-width="120">
<template #default="{ row }">
{{ assistantLogCellText(row, 'to') }}
</template>
</el-table-column>
<el-table-column label="操作人" width="110" prop="operator_name" />
<el-table-column label="操作账号" width="120" prop="operator_account" show-overflow-tooltip />
<el-table-column label="IP" width="130" prop="ip" show-overflow-tooltip />
@@ -22,12 +30,27 @@ const props = defineProps<{
const loading = ref(false)
const rows = ref<any[]>([])
function assistantLogCellText(row: Record<string, unknown>, side: 'from' | 'to'): string {
const nameKey = side === 'from' ? 'from_assistant_name' : 'to_assistant_name'
const idKey = side === 'from' ? 'from_assistant_id' : 'to_assistant_id'
const n = row[nameKey]
if (n != null && String(n).trim() !== '' && String(n) !== '—') {
return String(n)
}
const id = Number(row[idKey])
if (Number.isFinite(id) && id > 0) {
return `ID:${id}`
}
return '—'
}
const load = async () => {
if (!props.diagnosisId) return
loading.value = true
try {
const data = await tcmDiagnosisAssignLogList({ id: props.diagnosisId })
rows.value = Array.isArray(data) ? data : []
const list = Array.isArray(data) ? data : []
rows.value = list
} catch (e) {
console.error(e)
rows.value = []
+5 -2
View File
@@ -1446,10 +1446,13 @@ const handleEdit = (id: number) => {
editRef.value.open('edit', id)
}
/** 与预约列表开方一致:已通过且未作废 → 查看,否则开方 */
/** 与预约列表开方一致:已通过且未作废 → 查看,否则开方。(待分配医助 Tab 一律显示「开方」,避免误解为只读) */
function prescriptionActionLabel(row: any) {
if (formData.pending_assign === '1') {
return '开方'
}
if (
row?.prescription_audit_status === 1 &&
Number(row?.prescription_audit_status) === 1 &&
Number(row?.prescription_void_status) !== 1
) {
return '查看'
@@ -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;
+13 -4
View File
@@ -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;
}