Merge branch 'long-consultation-desk'
This commit is contained in:
@@ -147,4 +147,18 @@ class AppointmentController extends BaseAdminController
|
||||
$params = (new AppointmentValidate())->goCheck('doctorNotes');
|
||||
return $this->data(DoctorNoteLogic::getByDiagnosis((int) $params['diagnosis_id']));
|
||||
}
|
||||
|
||||
public function deleteDoctorNoteImage()
|
||||
{
|
||||
$params = (new AppointmentValidate())->post()->goCheck('deleteDoctorNoteImage');
|
||||
$result = DoctorNoteLogic::deleteImage(
|
||||
(int) $params['note_id'],
|
||||
$params['image_type'],
|
||||
$params['image_path']
|
||||
);
|
||||
if ($result === false) {
|
||||
return $this->fail(DoctorNoteLogic::getError());
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class DoctorNoteLogic extends BaseLogic
|
||||
->find();
|
||||
|
||||
$newContent = trim($params['content'] ?? '');
|
||||
$newImages = self::parseJsonArray($params['tongue_images'] ?? []);
|
||||
$newReports = self::parseJsonArray($params['report_files'] ?? []);
|
||||
$newImages = array_map([self::class, 'toRelativePath'], self::parseJsonArray($params['tongue_images'] ?? []));
|
||||
$newReports = array_map([self::class, 'toRelativePath'], self::parseJsonArray($params['report_files'] ?? []));
|
||||
|
||||
if ($existing) {
|
||||
$data = [];
|
||||
@@ -108,6 +108,91 @@ class DoctorNoteLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除备注中的单张图片
|
||||
*/
|
||||
public static function deleteImage(int $noteId, string $imageType, string $imagePath): bool
|
||||
{
|
||||
try {
|
||||
$note = DoctorNote::where('id', $noteId)->whereNull('delete_time')->find();
|
||||
if (!$note) {
|
||||
self::setError('记录不存在');
|
||||
return false;
|
||||
}
|
||||
if (!in_array($imageType, ['tongue_images', 'report_files'])) {
|
||||
self::setError('类型无效');
|
||||
return false;
|
||||
}
|
||||
$images = self::parseJsonArray($note->$imageType);
|
||||
// 统一转为相对路径再匹配
|
||||
$targetPath = self::toRelativePath($imagePath);
|
||||
$images = array_values(array_filter($images, fn($url) => self::toRelativePath($url) !== $targetPath));
|
||||
$note->$imageType = empty($images) ? null : json_encode($images, JSON_UNESCAPED_UNICODE);
|
||||
$note->save();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合某诊单所有备注中的图片(供 DiagnosisLogic::detail 使用)
|
||||
*/
|
||||
public static function getAggregatedImages(int $diagnosisId): array
|
||||
{
|
||||
$records = DoctorNote::where('diagnosis_id', $diagnosisId)
|
||||
->whereNull('delete_time')
|
||||
->select();
|
||||
|
||||
$tongueImages = [];
|
||||
$reportFiles = [];
|
||||
foreach ($records as $r) {
|
||||
$tongueImages = array_merge($tongueImages, self::parseJsonArray($r->tongue_images));
|
||||
$reportFiles = array_merge($reportFiles, self::parseJsonArray($r->report_files));
|
||||
}
|
||||
|
||||
return [
|
||||
'tongue_images' => array_map(
|
||||
fn($u) => empty($u) ? $u : FileService::getFileUrl($u),
|
||||
array_values(array_unique($tongueImages))
|
||||
),
|
||||
'report_files' => array_map(
|
||||
fn($u) => empty($u) ? $u : FileService::getFileUrl($u),
|
||||
array_values(array_unique($reportFiles))
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果 URL 的域名是当前配置的存储域名则去掉,否则原样保留
|
||||
*/
|
||||
private static function toRelativePath(string $url): string
|
||||
{
|
||||
if (empty($url)) return $url;
|
||||
if (stripos($url, 'http://') !== 0 && stripos($url, 'https://') !== 0) {
|
||||
return $url;
|
||||
}
|
||||
// 获取当前存储域名
|
||||
$domain = self::getStorageDomain();
|
||||
if ($domain && stripos($url, rtrim($domain, '/')) === 0) {
|
||||
$relative = substr($url, strlen(rtrim($domain, '/')));
|
||||
return ltrim($relative, '/');
|
||||
}
|
||||
// 非当前存储域名,保留完整 URL
|
||||
return $url;
|
||||
}
|
||||
|
||||
private static function getStorageDomain(): string
|
||||
{
|
||||
$default = \app\common\service\ConfigService::get('storage', 'default', 'local');
|
||||
if ($default === 'local') {
|
||||
return request()->domain() . '/';
|
||||
}
|
||||
$storage = \app\common\service\ConfigService::get('storage', $default);
|
||||
return $storage ? ($storage['domain'] ?? '') : '';
|
||||
}
|
||||
|
||||
private static function parseJsonArray($value): array
|
||||
{
|
||||
if (is_array($value)) return $value;
|
||||
|
||||
@@ -80,23 +80,19 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
// 处理舌苔照片(JSON数组)
|
||||
if (isset($params['tongue_images']) && is_array($params['tongue_images'])) {
|
||||
$params['tongue_images'] = json_encode($params['tongue_images'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 处理检查报告(JSON数组)
|
||||
if (isset($params['report_files']) && is_array($params['report_files'])) {
|
||||
$params['report_files'] = json_encode($params['report_files'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 图片字段迁移至 doctor_note,从 params 中提取后再写入备注表
|
||||
$newTongueImages = isset($params['tongue_images']) && is_array($params['tongue_images'])
|
||||
? $params['tongue_images'] : [];
|
||||
$newReportFiles = isset($params['report_files']) && is_array($params['report_files'])
|
||||
? $params['report_files'] : [];
|
||||
unset($params['tongue_images'], $params['report_files']);
|
||||
|
||||
// 处理诊断日期
|
||||
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)
|
||||
// 注意:Model::getConnection() 在 think-orm 中返回连接名(string),须用 Db 查询对象取字段
|
||||
if (array_key_exists('admin_id', $params)) {
|
||||
$fieldNames = Db::name('tcm_diagnosis')->getTableFields();
|
||||
if (! is_array($fieldNames) || ! in_array('admin_id', $fieldNames, true)) {
|
||||
@@ -105,10 +101,19 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
|
||||
$model = Diagnosis::create($params);
|
||||
|
||||
|
||||
// 图片写入 doctor_note 表
|
||||
if (!empty($newTongueImages) || !empty($newReportFiles)) {
|
||||
DoctorNoteLogic::addOrAppend([
|
||||
'diagnosis_id' => (int) $model->id,
|
||||
'tongue_images' => $newTongueImages,
|
||||
'report_files' => $newReportFiles,
|
||||
]);
|
||||
}
|
||||
|
||||
// 自动为患者创建 TRTC 账号
|
||||
self::createPatientTrtcAccount($model->id);
|
||||
|
||||
|
||||
return $model->id;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
@@ -179,46 +184,16 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
// 处理舌苔照片(JSON数组)
|
||||
if (isset($params['tongue_images']) && is_array($params['tongue_images'])) {
|
||||
$params['tongue_images'] = json_encode($params['tongue_images'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 处理检查报告(JSON数组)
|
||||
if (isset($params['report_files']) && is_array($params['report_files'])) {
|
||||
$params['report_files'] = json_encode($params['report_files'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
// 图片字段已迁移至 doctor_note 表管理,不再写入 tcm_diagnosis
|
||||
unset($params['tongue_images'], $params['report_files']);
|
||||
|
||||
// 处理诊断日期
|
||||
if (isset($params['diagnosis_date'])) {
|
||||
$params['diagnosis_date'] = strtotime($params['diagnosis_date']);
|
||||
}
|
||||
|
||||
// 保存前记录旧的检查报告,用于对比新增
|
||||
$oldReportFiles = [];
|
||||
if (isset($params['report_files'])) {
|
||||
$old = Diagnosis::where('id', $params['id'])->value('report_files');
|
||||
if ($old) {
|
||||
$oldReportFiles = is_string($old) ? (json_decode($old, true) ?: []) : (array) $old;
|
||||
}
|
||||
}
|
||||
|
||||
Diagnosis::update($params);
|
||||
|
||||
// 检查报告有新增时同步到医生备注
|
||||
if (isset($params['report_files'])) {
|
||||
$newReportFiles = is_string($params['report_files'])
|
||||
? (json_decode($params['report_files'], true) ?: [])
|
||||
: (array) $params['report_files'];
|
||||
$added = array_values(array_diff($newReportFiles, $oldReportFiles));
|
||||
if (!empty($added)) {
|
||||
DoctorNoteLogic::addOrAppend([
|
||||
'diagnosis_id' => (int) $params['id'],
|
||||
'report_files' => $added,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是编辑,也确保患者有 TRTC 账号
|
||||
$diagnosis = Diagnosis::find($params['id']);
|
||||
if ($diagnosis) {
|
||||
@@ -280,33 +255,36 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
|
||||
|
||||
if (!empty($diagnosis['tongue_images'])) {
|
||||
$files = json_decode($diagnosis['tongue_images'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['tongue_images'] = $files;
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = array_filter(explode(',', $diagnosis['tongue_images'])) ?: [];
|
||||
}
|
||||
$diagnosis['tongue_images'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $diagnosis['tongue_images']);
|
||||
// 从 doctor_note 聚合图片(已迁移至备注表统一管理)
|
||||
$noteImages = DoctorNoteLogic::getAggregatedImages((int) $diagnosis['id']);
|
||||
if (!empty($noteImages['tongue_images']) || !empty($noteImages['report_files'])) {
|
||||
$diagnosis['tongue_images'] = $noteImages['tongue_images'];
|
||||
$diagnosis['report_files'] = $noteImages['report_files'];
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
// Fallback: 未迁移的旧数据仍从 tcm_diagnosis 读取
|
||||
if (!empty($diagnosis['tongue_images'])) {
|
||||
$files = json_decode($diagnosis['tongue_images'], true);
|
||||
if (!is_array($files)) {
|
||||
$files = array_filter(explode(',', $diagnosis['tongue_images'])) ?: [];
|
||||
}
|
||||
$diagnosis['tongue_images'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $files);
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
}
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
$files = json_decode($diagnosis['report_files'], true);
|
||||
if (!is_array($files)) {
|
||||
$files = array_filter(explode(',', $diagnosis['report_files'])) ?: [];
|
||||
}
|
||||
$diagnosis['report_files'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $files);
|
||||
} else {
|
||||
$diagnosis['report_files'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
$files = json_decode($diagnosis['report_files'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['report_files'] = $files;
|
||||
} else {
|
||||
$diagnosis['report_files'] = array_filter(explode(',', $diagnosis['report_files'])) ?: [];
|
||||
}
|
||||
$diagnosis['report_files'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $diagnosis['report_files']);
|
||||
} else {
|
||||
$diagnosis['report_files'] = [];
|
||||
}
|
||||
// 处理诊断日期格式
|
||||
if (!empty($diagnosis['diagnosis_date'])) {
|
||||
$diagnosis['diagnosis_date'] = date('Y-m-d', $diagnosis['diagnosis_date']);
|
||||
@@ -2788,12 +2766,13 @@ class DiagnosisLogic extends BaseLogic
|
||||
$params[$field] = implode(',', $params[$field]);
|
||||
}
|
||||
}
|
||||
if (isset($params['tongue_images']) && is_array($params['tongue_images'])) {
|
||||
$params['tongue_images'] = json_encode($params['tongue_images'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (isset($params['report_files']) && is_array($params['report_files'])) {
|
||||
$params['report_files'] = json_encode($params['report_files'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
// 图片字段迁移至 doctor_note 表
|
||||
$cardTongueImages = isset($params['tongue_images']) && is_array($params['tongue_images'])
|
||||
? $params['tongue_images'] : [];
|
||||
$cardReportFiles = isset($params['report_files']) && is_array($params['report_files'])
|
||||
? $params['report_files'] : [];
|
||||
unset($params['tongue_images'], $params['report_files']);
|
||||
|
||||
if (isset($params['diagnosis_date'])) {
|
||||
$params['diagnosis_date'] = is_numeric($params['diagnosis_date']) ? $params['diagnosis_date'] : strtotime($params['diagnosis_date']);
|
||||
}
|
||||
@@ -2801,6 +2780,15 @@ class DiagnosisLogic extends BaseLogic
|
||||
$model = Diagnosis::create($params);
|
||||
self::createPatientTrtcAccount($model->patient_id);
|
||||
|
||||
// 图片写入 doctor_note
|
||||
if (!empty($cardTongueImages) || !empty($cardReportFiles)) {
|
||||
DoctorNoteLogic::addOrAppend([
|
||||
'diagnosis_id' => (int) $model->id,
|
||||
'tongue_images' => $cardTongueImages,
|
||||
'report_files' => $cardReportFiles,
|
||||
]);
|
||||
}
|
||||
|
||||
// 关联 diagnosis_view_records,便于用户通过 User::with('diagnosis') 获取就诊卡
|
||||
if ($userId) {
|
||||
$now = time();
|
||||
@@ -2906,8 +2894,6 @@ class DiagnosisLogic extends BaseLogic
|
||||
// 临床信息
|
||||
'symptoms' => $params['symptoms'] ?? '',
|
||||
'tongue_coating' => $params['tongue_coating'] ?? '',
|
||||
'tongue_images' => $params['tongue_images'] ?? '',
|
||||
'report_files' => $params['report_files'] ?? '',
|
||||
'pulse' => $params['pulse'] ?? '',
|
||||
'treatment_principle' => $params['treatment_principle'] ?? '',
|
||||
'prescription' => $params['prescription'] ?? '',
|
||||
@@ -2920,14 +2906,25 @@ class DiagnosisLogic extends BaseLogic
|
||||
if (!empty($params['diagnosis_date'])) {
|
||||
$updateData['diagnosis_date'] = strtotime($params['diagnosis_date']);
|
||||
} elseif (!empty($params['local_hospital_visit_date'])) {
|
||||
// 如果没有diagnosis_date但有local_hospital_visit_date,则使用local_hospital_visit_date
|
||||
$updateData['diagnosis_date'] = strtotime($params['local_hospital_visit_date']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 执行更新
|
||||
$diagnosis->save($updateData);
|
||||
|
||||
// 图片写入 doctor_note 表
|
||||
$cardTongueImages = isset($params['tongue_images']) && is_array($params['tongue_images'])
|
||||
? $params['tongue_images'] : [];
|
||||
$cardReportFiles = isset($params['report_files']) && is_array($params['report_files'])
|
||||
? $params['report_files'] : [];
|
||||
if (!empty($cardTongueImages) || !empty($cardReportFiles)) {
|
||||
DoctorNoteLogic::addOrAppend([
|
||||
'diagnosis_id' => (int) $diagnosisId,
|
||||
'tongue_images' => $cardTongueImages,
|
||||
'report_files' => $cardReportFiles,
|
||||
]);
|
||||
}
|
||||
|
||||
\think\facade\Log::info('诊单更新成功 - diagnosis_id: ' . $diagnosisId . ', patient_id: ' . $patientId);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -25,6 +25,9 @@ class AppointmentValidate extends BaseValidate
|
||||
'appointment_time' => 'require',
|
||||
'appointment_type' => 'in:video,text,phone',
|
||||
'channel_source' => 'require',
|
||||
'note_id' => 'require|integer',
|
||||
'image_type' => 'require|in:tongue_images,report_files',
|
||||
'image_path' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -115,4 +118,9 @@ class AppointmentValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['diagnosis_id']);
|
||||
}
|
||||
|
||||
public function sceneDeleteDoctorNoteImage()
|
||||
{
|
||||
return $this->only(['note_id', 'image_type', 'image_path']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class DiagnosisValidate extends BaseValidate
|
||||
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'patient_name', 'id_card', 'phone', 'gender', 'age', 'diagnosis_date', 'diagnosis_type', 'syndrome_type', 'marital_status', 'height', 'weight', 'region', 'systolic_pressure', 'diastolic_pressure', 'fasting_blood_sugar', 'diabetes_discovery_year', 'local_hospital_diagnosis', 'local_hospital_name', 'past_history', 'symptoms', 'tongue_coating', 'pulse', 'treatment_principle', 'prescription', 'doctor_advice', 'remark', 'current_medications', 'status', 'tongue_images', 'report_files']);
|
||||
return $this->only(['id', 'patient_name', 'id_card', 'phone', 'gender', 'age', 'diagnosis_date', 'diagnosis_type', 'syndrome_type', 'marital_status', 'height', 'weight', 'region', 'systolic_pressure', 'diastolic_pressure', 'fasting_blood_sugar', 'diabetes_discovery_year', 'local_hospital_diagnosis', 'local_hospital_name', 'past_history', 'symptoms', 'tongue_coating', 'pulse', 'treatment_principle', 'prescription', 'doctor_advice', 'remark', 'current_medications', 'status']);
|
||||
}
|
||||
|
||||
public function sceneId()
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 将 tcm_diagnosis 中的 tongue_images / report_files 迁移到 zyt_doctor_note 表
|
||||
*
|
||||
* 使用方法:
|
||||
* php think migrate:images-to-doctor-note
|
||||
* php think migrate:images-to-doctor-note --dry-run # 仅统计不实际写入
|
||||
*/
|
||||
class MigrateImagesToDoctorNote extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('migrate:images-to-doctor-note')
|
||||
->addOption('dry-run', null, \think\console\input\Option::VALUE_NONE, '仅统计,不实际写入')
|
||||
->setDescription('迁移诊单舌苔照片/检查报告到医生备注表');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$dryRun = $input->getOption('dry-run');
|
||||
|
||||
$output->writeln('开始扫描 tcm_diagnosis 中有图片数据的记录...');
|
||||
|
||||
$query = Db::name('tcm_diagnosis')
|
||||
->whereNull('delete_time')
|
||||
->where(function ($q) {
|
||||
$q->whereRaw("tongue_images IS NOT NULL AND tongue_images != '' AND tongue_images != '[]'")
|
||||
->whereOr(function ($q2) {
|
||||
$q2->whereRaw("report_files IS NOT NULL AND report_files != '' AND report_files != '[]'");
|
||||
});
|
||||
})
|
||||
->field('id, patient_id, create_time, tongue_images, report_files');
|
||||
|
||||
$total = $query->count();
|
||||
$output->writeln("找到 {$total} 条需要迁移的诊单记录");
|
||||
|
||||
if ($total === 0) {
|
||||
$output->writeln('<info>无需迁移</info>');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($dryRun) {
|
||||
$output->writeln('<comment>[dry-run] 不执行实际写入</comment>');
|
||||
return;
|
||||
}
|
||||
|
||||
$migrated = 0;
|
||||
$skipped = 0;
|
||||
$errors = 0;
|
||||
|
||||
$query->chunk(100, function ($rows) use ($output, &$migrated, &$skipped, &$errors) {
|
||||
foreach ($rows as $row) {
|
||||
try {
|
||||
$diagnosisId = (int) $row['id'];
|
||||
$noteDate = $row['create_time'] > 0
|
||||
? date('Y-m-d', (int) $row['create_time'])
|
||||
: date('Y-m-d');
|
||||
|
||||
$tongueImages = array_map([$this, 'toRelativePath'], $this->parseJson($row['tongue_images']));
|
||||
$reportFiles = array_map([$this, 'toRelativePath'], $this->parseJson($row['report_files']));
|
||||
$tongueImages = array_values(array_filter($tongueImages));
|
||||
$reportFiles = array_values(array_filter($reportFiles));
|
||||
|
||||
if (empty($tongueImages) && empty($reportFiles)) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing = Db::name('doctor_note')
|
||||
->where('diagnosis_id', $diagnosisId)
|
||||
->where('note_date', $noteDate)
|
||||
->whereNull('delete_time')
|
||||
->find();
|
||||
|
||||
if ($existing) {
|
||||
$data = [];
|
||||
if (!empty($tongueImages)) {
|
||||
$prev = $this->parseJson($existing['tongue_images']);
|
||||
$merged = array_values(array_unique(array_merge($prev, $tongueImages)));
|
||||
$data['tongue_images'] = json_encode($merged, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (!empty($reportFiles)) {
|
||||
$prev = $this->parseJson($existing['report_files']);
|
||||
$merged = array_values(array_unique(array_merge($prev, $reportFiles)));
|
||||
$data['report_files'] = json_encode($merged, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (!empty($data)) {
|
||||
$data['update_time'] = time();
|
||||
Db::name('doctor_note')->where('id', $existing['id'])->update($data);
|
||||
}
|
||||
} else {
|
||||
Db::name('doctor_note')->insert([
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'doctor_id' => 0,
|
||||
'note_date' => $noteDate,
|
||||
'content' => null,
|
||||
'tongue_images' => !empty($tongueImages)
|
||||
? json_encode($tongueImages, JSON_UNESCAPED_UNICODE)
|
||||
: null,
|
||||
'report_files' => !empty($reportFiles)
|
||||
? json_encode($reportFiles, JSON_UNESCAPED_UNICODE)
|
||||
: null,
|
||||
'create_time' => (int) $row['create_time'],
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
$migrated++;
|
||||
} catch (\Exception $e) {
|
||||
$errors++;
|
||||
$output->writeln("<error>诊单 ID={$row['id']} 迁移失败: {$e->getMessage()}</error>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$output->writeln('');
|
||||
$output->writeln('<info>迁移完成</info>');
|
||||
$output->writeln(" 成功: {$migrated}");
|
||||
$output->writeln(" 跳过(空数据): {$skipped}");
|
||||
$output->writeln(" 失败: {$errors}");
|
||||
}
|
||||
|
||||
private function parseJson($value): array
|
||||
{
|
||||
if (empty($value)) return [];
|
||||
if (is_array($value)) return $value;
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function toRelativePath(string $url): string
|
||||
{
|
||||
if (empty($url)) return $url;
|
||||
if (stripos($url, 'http://') !== 0 && stripos($url, 'https://') !== 0) {
|
||||
return $url;
|
||||
}
|
||||
// 只去掉当前配置的存储域名,其他域名保留完整 URL
|
||||
$default = \app\common\service\ConfigService::get('storage', 'default', 'local');
|
||||
if ($default === 'local') {
|
||||
$domain = request()->domain() . '/';
|
||||
} else {
|
||||
$storage = \app\common\service\ConfigService::get('storage', $default);
|
||||
$domain = $storage ? ($storage['domain'] ?? '') : '';
|
||||
}
|
||||
if ($domain && stripos($url, rtrim($domain, '/')) === 0) {
|
||||
$relative = substr($url, strlen(rtrim($domain, '/')));
|
||||
return ltrim($relative, '/');
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user