This commit is contained in:
lingxiao865
2026-02-10 09:30:37 +08:00
commit 13d1175057
15 changed files with 1728 additions and 0 deletions

61
models/models.go Normal file
View File

@@ -0,0 +1,61 @@
package models
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Phone string `gorm:"size:20;uniqueIndex;not null" json:"phone"`
Nickname string `gorm:"size:100" json:"nickname"`
Role string `gorm:"size:20;default:user" json:"role"` // user, admin
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TimeSlot 时间槽模型
type TimeSlot struct {
ID uint `gorm:"primaryKey" json:"id"`
Date time.Time `gorm:"not null;index" json:"date"`
StartTime time.Time `gorm:"not null" json:"start_time"`
EndTime time.Time `gorm:"not null" json:"end_time"`
MaxPeople int `gorm:"not null;default:1" json:"max_people"` // 每个时间段最多预约人数
CurrentPeople int `gorm:"not null;default:0" json:"current_people"` // 当前已预约人数
IsActive bool `gorm:"default:true" json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
type Appointment struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"not null" json:"user_id"`
TimeSlotID uint `gorm:"not null" json:"time_slot_id"`
PeopleCount int `gorm:"not null;default:1" json:"people_count"` // 预约人数
Status string `gorm:"size:20;default:pending" json:"status"` // pending, confirmed, cancelled, completed
Notes string `gorm:"size:500" json:"notes"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
TimeSlot TimeSlot `gorm:"foreignKey:TimeSlotID" json:"time_slot,omitempty"`
}
// 预约状态枚举
const (
AppointmentPending = "pending"
AppointmentConfirmed = "confirmed"
AppointmentCancelled = "cancelled"
AppointmentCompleted = "completed"
)
// 用户角色枚举
const (
RoleUser = "user"
RoleAdmin = "admin"
)