Files
zyt/APPOINTMENT_PERIOD_FIX.md
T
2026-03-04 15:32:30 +08:00

81 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 预约系统 Period 字段修复指南
## 问题描述
1. 数据库 `period` 字段是 ENUM 类型,只支持 'morning' 和 'afternoon',不支持 'all'
2. 已预约的时间段没有正确标记为不可用(时间格式不匹配)
## 解决方案
### 1. 修改数据库表结构
执行以下 SQL 语句修改 `period` 字段:
```sql
-- 方法1:修改为 VARCHAR 类型(推荐)
ALTER TABLE `la_doctor_appointment`
MODIFY COLUMN `period` varchar(20) NOT NULL DEFAULT 'all'
COMMENT '时段:morning=上午,afternoon=下午,all=全天';
-- 方法2:如果不想改表结构,可以在后端存储时使用默认值
-- 不执行 SQL,只在代码中处理
```
### 2. 后端代码修复
已修复以下问题:
#### AppointmentLogic.php - getAvailableSlots()
- 修复时间格式匹配问题
- 将数据库返回的 `HH:MM:SS` 格式统一转换为 `HH:MM` 格式
- 确保已预约时间段正确标记为不可用
#### AppointmentLogic.php - create()
- 统一时间格式为 `HH:MM:SS` 存储到数据库
- 修复 period 字段存储问题
#### AppointmentValidate.php
- 允许 period 值为 'morning'、'afternoon' 或 'all'
- 将 period 改为可选字段
### 3. 执行步骤
1. **执行 SQL 更新**(推荐):
```bash
# 在数据库中执行
mysql -u your_user -p your_database < server/sql/update_appointment_period.sql
```
2. **或者使用临时方案**(不修改表结构):
在 `AppointmentLogic.php` 的 `create()` 方法中,将 period 改为固定值:
```php
'period' => 'morning', // 临时使用固定值
```
### 4. 验证修复
1. 打开预约界面
2. 选择医生和日期
3. 查看时间段列表(应该显示 9:00-18:00 的所有15分钟时段)
4. 预约一个时间段
5. 刷新页面,确认该时间段显示为灰色"已约"状态
6. 尝试再次预约同一时间段,应该提示"该时间段已被预约"
## 技术细节
### 时间格式处理
- 前端发送:`09:00`HH:MM
- 数据库存储:`09:00:00`HH:MM:SSTIME 类型)
- 后端查询返回:`09:00:00` 或 `09:00`(取决于数据库驱动)
- 后端比对:统一转换为 `HH:MM` 格式
### Period 字段说明
- `morning`:上午时段(保留,兼容旧数据)
- `afternoon`:下午时段(保留,兼容旧数据)
- `all`:全天时段(新增,用于 9:00-18:00 连续预约)
## 注意事项
1. 如果选择不修改数据库表结构,需要在代码中使用固定的 period 值
2. 建议修改表结构以支持更灵活的时段类型
3. 修改表结构后,旧数据不受影响(morning 和 afternoon 仍然有效)