更新
This commit is contained in:
@@ -7,6 +7,7 @@ use app\common\model\doctor\Appointment;
|
||||
use app\common\model\doctor\Roster;
|
||||
use app\common\service\doctor\RosterSegmentService;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\DiagnosisGuahaoLog;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\api\logic\ChatNotifyLogic;
|
||||
use app\adminapi\logic\tcm\PrescriptionLogic;
|
||||
@@ -183,7 +184,7 @@ class AppointmentLogic extends BaseLogic
|
||||
* @param array $params
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function create(array $params)
|
||||
public static function create(array $params, int $operatorAdminId = 0, array $operatorAdminInfo = [])
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
@@ -244,6 +245,25 @@ class AppointmentLogic extends BaseLogic
|
||||
$appointment = Appointment::create($data);
|
||||
|
||||
Db::commit();
|
||||
|
||||
$doctorName = (string) (Admin::where('id', (int) $params['doctor_id'])->value('name') ?? '');
|
||||
$hm = substr((string) $appointmentTime, 0, 5);
|
||||
$summary = sprintf(
|
||||
'挂号 #%d:医生「%s」,%s %s',
|
||||
(int) $appointment->id,
|
||||
$doctorName !== '' ? $doctorName : ('ID:' . (int) $params['doctor_id']),
|
||||
(string) $params['appointment_date'],
|
||||
$hm
|
||||
);
|
||||
self::appendDiagnosisGuahaoLog(
|
||||
(int) $params['patient_id'],
|
||||
(int) $appointment->id,
|
||||
$operatorAdminId,
|
||||
$operatorAdminInfo,
|
||||
'create',
|
||||
$summary
|
||||
);
|
||||
|
||||
return ['id' => $appointment->id];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
@@ -257,7 +277,7 @@ class AppointmentLogic extends BaseLogic
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public static function cancel(array $params)
|
||||
public static function cancel(array $params, int $operatorAdminId = 0, array $operatorAdminInfo = [])
|
||||
{
|
||||
try {
|
||||
$appointment = Appointment::findOrEmpty($params['id']);
|
||||
@@ -279,10 +299,34 @@ class AppointmentLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
$diagId = (int) $appointment->patient_id;
|
||||
$aptId = (int) $appointment->id;
|
||||
$doctorId = (int) $appointment->doctor_id;
|
||||
$aptDate = (string) ($appointment->appointment_date ?? '');
|
||||
$aptTimeRaw = (string) ($appointment->appointment_time ?? '');
|
||||
$hm = strlen($aptTimeRaw) >= 5 ? substr($aptTimeRaw, 0, 5) : $aptTimeRaw;
|
||||
|
||||
$appointment->status = 2; // 已取消
|
||||
$appointment->update_time = time();
|
||||
$appointment->save();
|
||||
|
||||
$doctorName = (string) (Admin::where('id', $doctorId)->value('name') ?? '');
|
||||
$summary = sprintf(
|
||||
'取消挂号 #%d:医生「%s」,%s %s',
|
||||
$aptId,
|
||||
$doctorName !== '' ? $doctorName : ('ID:' . $doctorId),
|
||||
$aptDate,
|
||||
$hm
|
||||
);
|
||||
self::appendDiagnosisGuahaoLog(
|
||||
$diagId,
|
||||
$aptId,
|
||||
$operatorAdminId,
|
||||
$operatorAdminInfo,
|
||||
'cancel',
|
||||
$summary
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
@@ -444,4 +488,37 @@ class AppointmentLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊单列表维度:记录谁在后台发起挂号 / 取消挂号(写入失败不影响主流程)
|
||||
*/
|
||||
private static function appendDiagnosisGuahaoLog(
|
||||
int $diagnosisId,
|
||||
int $appointmentId,
|
||||
int $adminId,
|
||||
array $adminInfo,
|
||||
string $action,
|
||||
string $summary
|
||||
): void {
|
||||
if ($diagnosisId <= 0) {
|
||||
return;
|
||||
}
|
||||
$adminName = (string) ($adminInfo['name'] ?? '');
|
||||
if ($adminName === '' && $adminId > 0) {
|
||||
$adminName = (string) (Admin::where('id', $adminId)->value('name') ?? '');
|
||||
}
|
||||
try {
|
||||
$log = new DiagnosisGuahaoLog();
|
||||
$log->diagnosis_id = $diagnosisId;
|
||||
$log->appointment_id = $appointmentId;
|
||||
$log->admin_id = $adminId;
|
||||
$log->admin_name = mb_substr($adminName, 0, 64);
|
||||
$log->action = mb_substr($action, 0, 32);
|
||||
$log->summary = mb_substr($summary, 0, 500);
|
||||
$log->create_time = time();
|
||||
$log->save();
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('诊单挂号日志写入失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user