pet-ai/server/plugin/wechat-integration/model/mini_user.go

128 lines
3.0 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 (
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/google/uuid"
)
// 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:微信开放平台统一标识"`
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 "mini_users"
}
// 实现AppUserLogin接口
func (u *MiniUser) GetUUID() uuid.UUID {
// 将uint ID转换为UUID这里使用一个简单的方法
// 在实际项目中你可能需要为用户添加一个专门的UUID字段
return uuid.New()
}
func (u *MiniUser) GetUserId() uint {
return u.ID
}
func (u *MiniUser) GetOpenID() string {
return u.OpenID
}
func (u *MiniUser) GetUnionID() string {
if u.UnionID != nil {
return *u.UnionID
}
return ""
}
func (u *MiniUser) GetNickname() string {
if u.Nickname != nil {
return *u.Nickname
}
return ""
}
func (u *MiniUser) GetAvatar() string {
if u.AvatarURL != nil {
return *u.AvatarURL
}
return ""
}
func (u *MiniUser) GetPhone() string {
if u.Phone != nil {
return *u.Phone
}
return ""
}
func (u *MiniUser) GetGender() int {
if u.Gender != nil {
return *u.Gender
}
return 0
}
func (u *MiniUser) GetCity() string {
if u.City != nil {
return *u.City
}
return ""
}
func (u *MiniUser) GetProvince() string {
if u.Province != nil {
return *u.Province
}
return ""
}
func (u *MiniUser) GetCountry() string {
if u.Country != nil {
return *u.Country
}
return ""
}
// 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 ""
}