48 lines
2.5 KiB
Go
Raw Permalink 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.

package model
import (
"gorm.io/gorm"
"hospital-open-api/global"
"time"
)
// User 用户主表
type User struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键" json:"user_id"`
UserName string `gorm:"column:user_name;type:varchar(50);comment:用户名称" json:"user_name"`
UserAccount string `gorm:"column:user_account;type:varchar(50);comment:账号" json:"user_account"`
Mobile string `gorm:"column:mobile;type:varchar(20);comment:手机号" json:"mobile"`
WxMobile string `gorm:"column:wx_mobile;type:varchar(20);comment:微信手机号" json:"wx_mobile"`
UserPassword string `gorm:"column:user_password;type:varchar(50);comment:密码" json:"user_password"`
Salt string `gorm:"column:salt;type:varchar(50);comment:密码混淆码" json:"salt"`
UserType int `gorm:"column:user_type;type:tinyint(1);comment:用户类型1:患者 2:医师 3:药师);NOT NULL" json:"user_type"`
UserStatus int `gorm:"column:user_status;type:tinyint(4);default:1;comment:状态0:禁用 1:正常 2:删除)" json:"user_status"`
RegisterMethod int `gorm:"column:register_method;type:tinyint(1);comment:注册方式1:微信小程序 " json:"register_method"`
Age uint `gorm:"column:age;type:int(10) unsigned;comment:年龄" json:"age"`
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"`
IsOnline int `gorm:"column:is_online;type:tinyint(1);default:0;comment:是否在线0:不在线 1:在线)" json:"is_online"`
LoginAt LocalTime `gorm:"column:login_at;type:datetime;comment:小程序登陆时间" json:"login_at"`
ImLoginAt LocalTime `gorm:"column:im_login_at;type:datetime;comment:im登陆时间" json:"im_login_at"`
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
CreatedBy string `gorm:"column:created_by;type:varchar(100);comment:创建者id后台用户表id null:自己注册)" json:"created_by"`
Model
}
func (m *User) TableName() string {
return "gdxz_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
}