This commit is contained in:
Your Name
2026-04-23 15:56:01 +08:00
parent aabf2f3a38
commit f9c8b2a632
258 changed files with 489 additions and 367 deletions
@@ -70,6 +70,8 @@ class DiagnosisController extends BaseAdminController
public function add()
{
$params = (new DiagnosisValidate())->post()->goCheck('add');
// 诊单创建人(需表 zyt_tcm_diagnosis 已增加 admin_id 列,见 sql 脚本)
$params['admin_id'] = (int) $this->adminId;
$result = DiagnosisLogic::add($params);
if ($result) {
return $this->success('添加成功', ['id' => $result], 1, 1);
@@ -92,7 +92,16 @@ class DiagnosisLogic extends BaseLogic
if (isset($params['diagnosis_date'])) {
$params['diagnosis_date'] = strtotime($params['diagnosis_date']);
}
// 表未增加 admin_id 列时勿写入,避免 SQL 报错(见 sql/1.9.20260421/add_tcm_diagnosis_admin_id.sql
if (array_key_exists('admin_id', $params)) {
$diagM = new Diagnosis();
$fieldNames = $diagM->getConnection()->getTableFields($diagM->getTable());
if (! is_array($fieldNames) || ! in_array('admin_id', $fieldNames, true)) {
unset($params['admin_id']);
}
}
$model = Diagnosis::create($params);
// 自动为患者创建 TRTC 账号
@@ -13,6 +13,8 @@ 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;
@@ -32,6 +34,38 @@ class PrescriptionOrderLogic
return self::$error;
}
/**
* 部门自底向上链式名称,含父级(如:总部 / 华东 / 上海门诊)
*/
private static function buildDeptPath(int $deptId): string
{
if ($deptId <= 0) {
return '';
}
$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) {
break;
}
$data = $row->toArray();
array_unshift($names, (string) ($data['name'] ?? ''));
$pid = (int) ($data['pid'] ?? 0);
if ($pid <= 0) {
break;
}
$id = $pid;
}
if ($names === []) {
return '';
}
$names = array_filter($names, static fn (string $n): bool => $n !== '');
return implode(' / ', $names);
}
/**
* @param int[] $allowRoleIds
*/
@@ -607,6 +641,54 @@ class PrescriptionOrderLogic
unset($arr['prescription']['herbs']);
}
// 诊单医助 / 诊单创建人 及部门(多部门、含父级路径用「;」与「 / 」分隔);创建人为 tcm_diagnosis.admin_id
$arr['assistant_id'] = 0;
$arr['assistant_name'] = '';
$arr['assistant_dept_path'] = '';
$arr['diagnosis_creator_id'] = 0;
$arr['diagnosis_creator_name'] = '';
$arr['diagnosis_creator_dept_path'] = '';
$diagIdForMeta = (int) ($arr['diagnosis_id'] ?? 0);
if ($diagIdForMeta > 0) {
// 勿在 field 中写 admin_id:未执行建表补充列时会报 Unknown column
$dg = Diagnosis::where('id', $diagIdForMeta)->whereNull('delete_time')->find();
if ($dg !== null) {
$drow = $dg->toArray();
$astId = (int) ($drow['assistant_id'] ?? 0);
$arr['assistant_id'] = $astId;
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');
$pathSegments = [];
foreach ($deptIds as $did) {
$p = self::buildDeptPath((int) $did);
if ($p !== '') {
$pathSegments[] = $p;
}
}
$pathSegments = array_values(array_unique($pathSegments));
$arr['assistant_dept_path'] = $pathSegments === [] ? '' : implode('', $pathSegments);
}
$creId = (int) ($drow['admin_id'] ?? 0);
$arr['diagnosis_creator_id'] = $creId;
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);
}
}
}
return $arr;
}