package model import ( "database/sql/driver" "encoding/json" "fmt" "time" ) // JSON 类型,用于 custom_fields type JSON map[string]interface{} func (j JSON) Value() (driver.Value, error) { if j == nil { return nil, nil } b, err := json.Marshal(j) return string(b), err } func (j *JSON) Scan(value interface{}) error { if value == nil { *j = nil return nil } var bytes []byte switch v := value.(type) { case string: bytes = []byte(v) case []byte: bytes = v default: return fmt.Errorf("cannot scan type %T into JSON", value) } return json.Unmarshal(bytes, j) } // Base 公共字段 type Base struct { ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `gorm:"index" json:"-"` } // TenantBase 含租户隔离的公共字段 type TenantBase struct { Base HotelID uint64 `gorm:"not null;index" json:"hotel_id"` }