This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
)
|
||||
|
||||
// WechatMiniUser 微信小程序用户表
|
||||
type WechatMiniUser 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 (WechatMiniUser) TableName() string {
|
||||
return "wechat_mini_users"
|
||||
}
|
||||
|
||||
// IsLinkedToSystemUser 检查是否已关联系统用户
|
||||
func (w *WechatMiniUser) IsLinkedToSystemUser() bool {
|
||||
return w.UserID != nil && *w.UserID > 0
|
||||
}
|
||||
|
||||
// HasUnionID 检查是否有 UnionID
|
||||
func (w *WechatMiniUser) HasUnionID() bool {
|
||||
return w.UnionID != nil && *w.UnionID != ""
|
||||
}
|
||||
|
||||
// HasPhone 检查是否已绑定手机号
|
||||
func (w *WechatMiniUser) HasPhone() bool {
|
||||
return w.Phone != nil && *w.Phone != ""
|
||||
}
|
||||
|
||||
// GetDisplayName 获取显示名称
|
||||
func (w *WechatMiniUser) GetDisplayName() string {
|
||||
if w.Nickname != nil && *w.Nickname != "" {
|
||||
return *w.Nickname
|
||||
}
|
||||
return "微信用户"
|
||||
}
|
||||
|
||||
// GetAvatarURL 获取头像URL
|
||||
func (w *WechatMiniUser) GetAvatarURL() string {
|
||||
if w.AvatarURL != nil {
|
||||
return *w.AvatarURL
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user