package model import ( "gorm.io/gorm" "hospital-open-api/global" "time" ) // UserPatient 用户-患者表 type UserPatient struct { PatientId int64 `gorm:"column:patient_id;type:bigint(19);primary_key;comment:主键id" json:"patient_id"` UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"` OpenId string `gorm:"column:open_id;type:varchar(100);comment:微信open_id" json:"open_id"` UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台唯一标识" json:"union_id"` WxSessionKey string `gorm:"column:wx_session_key;type:varchar(255);comment:微信会话密钥" json:"wx_session_key"` Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"` IdcardStatus int `gorm:"column:idcard_status;type:tinyint(1);default:0;comment:实名认证状态(0:未认证 1:认证通过 2:认证失败)" json:"idcard_status"` Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` DisableReason string `gorm:"column:disable_reason;type:varchar(255);comment:禁用理由" json:"disable_reason"` User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户 Model } func (m *UserPatient) TableName() string { return "gdxz_user_patient" } func (m *UserPatient) BeforeCreate(tx *gorm.DB) error { if m.PatientId == 0 { m.PatientId = global.Snowflake.Generate().Int64() } m.CreatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("CreatedAt", m.CreatedAt) m.UpdatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) return nil }