更新
This commit is contained in:
@@ -189,6 +189,7 @@ class AppointmentLogic extends BaseLogic
|
||||
$slots[] = [
|
||||
'time' => $time,
|
||||
'available' => true,
|
||||
'has_appointment' => false,
|
||||
'quota' => 1,
|
||||
'period' => $roster['period'] ?? 'segment',
|
||||
];
|
||||
@@ -224,28 +225,39 @@ class AppointmentLogic extends BaseLogic
|
||||
'last_3_slots' => array_slice($slots, -3),
|
||||
]);
|
||||
|
||||
// 4. 查询已预约的时间段
|
||||
$appointmentTimes = Appointment::where([
|
||||
// 4. 查询当天所有挂号记录。
|
||||
// available 只由当前有效预约(status=1)决定;has_appointment 保留历史挂号事实,
|
||||
// 避免预约在完成、过号或取消后被误显示为“空号”。
|
||||
$appointmentRows = Appointment::where([
|
||||
'doctor_id' => $doctorId,
|
||||
'appointment_date' => $date,
|
||||
'status' => 1 // 只查询有效预约
|
||||
])->column('appointment_time');
|
||||
])->field(['appointment_time', 'status'])->select()->toArray();
|
||||
|
||||
// 将时间格式统一为 HH:MM(去掉秒)
|
||||
$appointments = array_map(function($time) {
|
||||
// 如果是 HH:MM:SS 格式,截取前5位
|
||||
return substr($time, 0, 5);
|
||||
}, $appointmentTimes);
|
||||
$appointmentMap = [];
|
||||
$activeAppointmentMap = [];
|
||||
foreach ($appointmentRows as $appointmentRow) {
|
||||
// 将 HH:MM:SS 统一为 HH:MM
|
||||
$appointmentTime = substr((string) ($appointmentRow['appointment_time'] ?? ''), 0, 5);
|
||||
if ($appointmentTime === '') {
|
||||
continue;
|
||||
}
|
||||
$appointmentMap[$appointmentTime] = true;
|
||||
if ((int) ($appointmentRow['status'] ?? 0) === 1) {
|
||||
$activeAppointmentMap[$appointmentTime] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 标记已占用的时间段
|
||||
// 5. 分别标记历史挂号与当前占用状态
|
||||
foreach ($slots as &$slot) {
|
||||
if (in_array($slot['time'], $appointments)) {
|
||||
$slot['has_appointment'] = isset($appointmentMap[$slot['time']]);
|
||||
if (isset($activeAppointmentMap[$slot['time']])) {
|
||||
$slot['available'] = false;
|
||||
$slot['quota'] = 0;
|
||||
}
|
||||
}
|
||||
unset($slot);
|
||||
|
||||
// 5. 按时间排序
|
||||
// 6. 按时间排序
|
||||
usort($slots, function($a, $b) {
|
||||
return strcmp($a['time'], $b['time']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user