62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
)
|
|
|
|
// MiniUser 微信小程序用户表
|
|
type MiniUser struct {
|
|
global.GVA_MODEL
|
|
OpenID string `json:"openid" gorm:"type:varchar(100);not null;uniqueIndex;comment:用户openid"`
|
|
UnionID *string `json:"unionid" gorm:"type:varchar(64);index;comment:微信开放平台统一标识"`
|
|
UserID *uint `json:"userId" gorm:"index;comment:关联系统用户ID"`
|
|
SessionKey *string `json:"sessionKey" gorm:"type:varchar(255);comment:会话密钥"`
|
|
Nickname *string `json:"nickname" gorm:"type:varchar(50);comment:用户昵称"`
|
|
AvatarURL *string `json:"avatarUrl" gorm:"type:varchar(1024);comment:用户头像"`
|
|
Gender *int `json:"gender" gorm:"comment:用户性别 0未知 1男 2女"`
|
|
Country *string `json:"country" gorm:"type:varchar(30);comment:用户国家"`
|
|
Province *string `json:"province" gorm:"type:varchar(30);comment:用户省份"`
|
|
City *string `json:"city" gorm:"type:varchar(30);comment:用户城市"`
|
|
Language *string `json:"language" gorm:"type:varchar(30);comment:用户语言"`
|
|
Phone *string `json:"phone" gorm:"type:varchar(20);index;comment:手机号"`
|
|
LastLoginTime *time.Time `json:"lastLoginTime" gorm:"comment:最后登录时间"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (MiniUser) TableName() string {
|
|
return "wechat_mini_users"
|
|
}
|
|
|
|
// IsLinkedToSystemUser 检查是否已关联系统用户
|
|
func (w *MiniUser) IsLinkedToSystemUser() bool {
|
|
return w.UserID != nil && *w.UserID > 0
|
|
}
|
|
|
|
// HasUnionID 检查是否有 UnionID
|
|
func (w *MiniUser) HasUnionID() bool {
|
|
return w.UnionID != nil && *w.UnionID != ""
|
|
}
|
|
|
|
// HasPhone 检查是否已绑定手机号
|
|
func (w *MiniUser) HasPhone() bool {
|
|
return w.Phone != nil && *w.Phone != ""
|
|
}
|
|
|
|
// GetDisplayName 获取显示名称
|
|
func (w *MiniUser) GetDisplayName() string {
|
|
if w.Nickname != nil && *w.Nickname != "" {
|
|
return *w.Nickname
|
|
}
|
|
return "微信用户"
|
|
}
|
|
|
|
// GetAvatarURL 获取头像URL
|
|
func (w *MiniUser) GetAvatarURL() string {
|
|
if w.AvatarURL != nil {
|
|
return *w.AvatarURL
|
|
}
|
|
return ""
|
|
}
|