userOauth.go 803 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package user_m

import (
	"git.hilo.cn/hilo-common/domain"
	"gorm.io/gorm"
	"hilo-user/myerr"
)

type UserOauth struct {
	UserId         uint64 `json:"user_id"`
	ThirdPartyId   string `json:"third_party_id"`
	ThirdPartyType int8   `json:"third_party_type"`
}

func (*UserOauth) TableName() string {
	return "user_oauth"
}

// 根据id获取第三方登录信息
func GetUserOauthByUserId(model *domain.Model, userId uint64, thirdType uint8) ([]*UserOauth, error) {
	res := make([]*UserOauth, 0)
	db := model.DB().Where(&UserOauth{UserId: userId})
	if thirdType > 0 {
		db = db.Where(&UserOauth{ThirdPartyType: int8(thirdType)})
	}
	err := db.Find(&res).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, myerr.WrapErr(err)
		}
	}
	return res, nil
}