wx-server/internal/dao/user_character.go

27 lines
922 B
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 dao
type UserCharacter struct {
ID int32 `gorm:"primaryKey;type:int;not null;auto_increment;comment:'角色ID'"`
UserId int32 `gorm:"default null;comment:'关联的用户ID'"`
CharacterId int32 `gorm:"default null;comment:'关联的角色ID'"`
Persona string `gorm:"type:json;default null;comment:'个性化配置'"`
}
// 根据userId查询关联的角色表
func UserCharacter_QueryList(userId int32) ([]*UserCharacter, error) {
var list []*UserCharacter
if err := s.db.Where("user_id = ?", userId).Find(&list).Error; err != nil {
return nil, err
}
return list, nil
}
// 根据userId查询关联角色的role_id
func UserCharacter_QueryList_OnlyCharacterId(userId int32) ([]int32, error) {
var list []int32
if err := s.db.Model(&UserCharacter{}).Where("user_id = ?", userId).Select("character_id").Scan(&list).Error; err != nil {
return nil, err
}
return list, nil
}