2024-07-19 13:37:16 +08:00

45 lines
2.1 KiB
Go
Raw 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"
"hepa-calc-api/global"
"time"
)
// User 用户表
type User struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:用户id" json:"user_id"`
UserName string `gorm:"column:user_name;type:varchar(200);comment:用户名称" json:"user_name"`
Mobile string `gorm:"column:mobile;type:varchar(20);comment:手机号;NOT NULL" json:"mobile"`
UserStatus int `gorm:"column:user_status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"user_status"`
RegisterSource int `gorm:"column:register_source;type:tinyint(1);default:1;comment:注册来源1app注册 2公众号注册" 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"`
Age *uint `gorm:"column:age;type:int(10) unsigned;comment:年龄" json:"age"`
Sex int `gorm:"column:sex;type:tinyint(1) unsigned;default:0;comment:性别0:未知 1:男 2:女)" json:"sex"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
IsMember int `gorm:"column:is_member;type:tinyint(1);default:0;comment:是否会员0:否 1:是)" json:"is_member"`
MemberExpireDate *time.Time `gorm:"column:member_expire_date;type:datetime;comment:会员到期时间非会员时为null" json:"member_expire_date"`
LoginAt LocalTime `gorm:"column:login_at;type:datetime;comment:登陆时间" json:"login_at"`
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
Model
}
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
}