trade_union.go 957 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 36 37 38 39 40 41 42 43 44
package user_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-group/myerr"
)

type UserTradeUnion struct {
	mysql.Entity
	*domain.Model     `gorm:"-"`
	UserId            mysql.ID
	MatchNotification mysql.OpenClose
	AgentId           mysql.ID
	StarchatId        mysql.ID
	Avatar            string
}

func GetUserTradeUnion(userId mysql.ID) (*UserTradeUnion, error) {
	var userTradeUnion UserTradeUnion
	if err := mysql.Db.Where(UserTradeUnion{
		UserId: userId,
	}).First(&userTradeUnion).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, myerr.WrapErr(err)
		}
	}
	return &userTradeUnion, nil
}

type AgentMgr struct {
	mysql.Entity
	*domain.Model `gorm:"-"`
	UserId        mysql.ID
	AgentId       mysql.ID
}

func IsAgent(userId uint64) bool {
	data := AgentMgr{}
	return mysql.Db.Where(&AgentMgr{UserId: userId}).First(&data).Error == nil
}