This commit is contained in:
Your Name
2026-04-24 14:42:52 +08:00
parent a3e035b74b
commit aaba330f0d
7 changed files with 175 additions and 46 deletions
@@ -13,11 +13,10 @@ use app\common\model\tcm\PrescriptionOrder;
use app\common\model\tcm\PrescriptionOrderLog;
use app\common\model\tcm\PrescriptionOrderPayOrder;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminDept;
use app\common\model\dept\Dept;
use app\common\service\ExpressTrackService;
use app\common\service\gancao\GancaoScmRecipelService;
use think\facade\Config;
use think\facade\Db;
use think\facade\Log;
class PrescriptionOrderLogic
@@ -36,6 +35,7 @@ class PrescriptionOrderLogic
/**
* 部门自底向上链式名称,含父级(如:总部 / 华东 / 上海门诊)
* 使用 Db 直查 zyt_dept:避免 Dept 软删除全局作用域导致有 dept_id 仍拼不出路径
*/
private static function buildDeptPath(int $deptId): string
{
@@ -45,13 +45,13 @@ class PrescriptionOrderLogic
$names = [];
$id = $deptId;
for ($i = 0; $i < 50; $i++) {
$row = Dept::where('id', $id)->whereNull('delete_time')->field(['id', 'name', 'pid'])->find();
if ($row === null) {
$row = Db::name('dept')->where('id', $id)->field(['id', 'name', 'pid'])->find();
if (empty($row)) {
break;
}
$data = $row->toArray();
array_unshift($names, (string) ($data['name'] ?? ''));
$pid = (int) ($data['pid'] ?? 0);
$r = is_array($row) ? $row : $row->toArray();
array_unshift($names, (string) ($r['name'] ?? ''));
$pid = (int) ($r['pid'] ?? 0);
if ($pid <= 0) {
break;
}
@@ -66,6 +66,27 @@ class PrescriptionOrderLogic
return implode(' / ', $names);
}
/**
* 管理员在 zyt_admin_dept 中的部门路径(多部门用「;」、含父级「 / 」)
*/
private static function buildAdminDeptPathJoined(int $adminId): string
{
if ($adminId <= 0) {
return '';
}
$deptIds = Db::name('admin_dept')->where('admin_id', $adminId)->column('dept_id');
$pathSegmentsC = [];
foreach ($deptIds as $didC) {
$pc = self::buildDeptPath((int) $didC);
if ($pc !== '') {
$pathSegmentsC[] = $pc;
}
}
$pathSegmentsC = array_values(array_unique($pathSegmentsC));
return $pathSegmentsC === [] ? '' : implode('', $pathSegmentsC);
}
/**
* @param int[] $allowRoleIds
*/
@@ -641,7 +662,7 @@ class PrescriptionOrderLogic
unset($arr['prescription']['herbs']);
}
// 诊单医助 / 诊单创建人 及部门(多部门、含父级路径用「;」与「 / 」分隔);创建人为 tcm_diagnosis.admin_id
// 诊单医助 / 诊单创建人姓名(tcm_diagnosis.admin_id);部门见下方:优先业务订单 creator_id
$arr['assistant_id'] = 0;
$arr['assistant_name'] = '';
$arr['assistant_dept_path'] = '';
@@ -659,7 +680,7 @@ class PrescriptionOrderLogic
if ($astId > 0) {
$an = Admin::where('id', $astId)->whereNull('delete_time')->value('name');
$arr['assistant_name'] = $an !== null && (string) $an !== '' ? (string) $an : '';
$deptIds = AdminDept::where('admin_id', $astId)->column('dept_id');
$deptIds = Db::name('admin_dept')->where('admin_id', $astId)->column('dept_id');
$pathSegments = [];
foreach ($deptIds as $did) {
$p = self::buildDeptPath((int) $did);
@@ -675,19 +696,18 @@ class PrescriptionOrderLogic
if ($creId > 0) {
$cn = Admin::where('id', $creId)->whereNull('delete_time')->value('name');
$arr['diagnosis_creator_name'] = $cn !== null && (string) $cn !== '' ? (string) $cn : '';
$deptIdsC = AdminDept::where('admin_id', $creId)->column('dept_id');
$pathSegmentsC = [];
foreach ($deptIdsC as $didC) {
$pc = self::buildDeptPath((int) $didC);
if ($pc !== '') {
$pathSegmentsC[] = $pc;
}
}
$pathSegmentsC = array_values(array_unique($pathSegmentsC));
$arr['diagnosis_creator_dept_path'] = $pathSegmentsC === [] ? '' : implode('', $pathSegmentsC);
}
}
}
// 「创建人所属部门」:优先 zyt_tcm_prescription_order.creator_id;无部门时再试诊单 admin_id(非处方开方人)
$deptPath = self::buildAdminDeptPathJoined((int) ($arr['creator_id'] ?? 0));
if ($deptPath === '') {
$dgAdmin = (int) ($arr['diagnosis_creator_id'] ?? 0);
if ($dgAdmin > 0) {
$deptPath = self::buildAdminDeptPathJoined($dgAdmin);
}
}
$arr['diagnosis_creator_dept_path'] = $deptPath;
return $arr;
}