47 lines
2.4 KiB
Go
47 lines
2.4 KiB
Go
package model
|
||
|
||
import (
|
||
"case-api/global"
|
||
"gorm.io/gorm"
|
||
"time"
|
||
)
|
||
|
||
// User 用户表
|
||
type User struct {
|
||
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
|
||
UserIden string `gorm:"column:user_iden;type:varchar(50);comment:第三方平台唯一标识" json:"user_iden"`
|
||
UserName string `gorm:"column:user_name;type:varchar(200);comment:用户名称" json:"user_name"`
|
||
UserMobile string `gorm:"column:user_mobile;type:varchar(20);comment:手机号" json:"user_mobile"`
|
||
MobileEncryption string `gorm:"column:mobile_encryption;type:varchar(100);comment:手机号加密" json:"mobile_encryption"`
|
||
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"`
|
||
RegisterSource int `gorm:"column:register_source;type:tinyint(1);default:1;comment:注册来源(1:未知 2:app用户 3:佳动例)" json:"register_source"`
|
||
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
|
||
UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台标识" json:"union_id"`
|
||
Sex int `gorm:"column:sex;type:tinyint(1);default:0;comment:性别(0:未知 1:男 2:女)" json:"sex"`
|
||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||
Title int `gorm:"column:title;type:tinyint(1);comment:医生职称(1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)" json:"title"`
|
||
DepartmentName string `gorm:"column:department_name;type:varchar(100);comment:科室名称" json:"department_name"`
|
||
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:所属医院id" json:"hospital_id"`
|
||
Address string `gorm:"column:address;type:varchar(255);comment:医生地址" json:"address"`
|
||
Model
|
||
Hospital *BasicHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"hospital"`
|
||
}
|
||
|
||
func (m *User) TableName() string {
|
||
return "user"
|
||
}
|
||
|
||
func (m *User) BeforeCreate(tx *gorm.DB) error {
|
||
if m.UserId == 0 {
|
||
m.UserId = 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
|
||
}
|