groupInfo.go 2.78 KB
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
package group_m

import (
	"git.hilo.cn/hilo-common/domain"
	"gorm.io/gorm"
	"hilo-user/_const/enum/group_e"
	"hilo-user/myerr/bizerr"
	"time"
)

type GroupInfo struct {
	Id             int64
	ImGroupId      string
	TxGroupId      string
	Type           uint16
	Code           string
	OriginCode     string
	Owner          uint64
	Name           string
	Introduction   string
	Notification   string
	FaceUrl        string
	Country        string
	ChannelId      string
	Password       string
	EntryLevel     uint32 // obsolete
	MicOn          bool
	LoadHistory    bool
	ThemeId        int16
	MicNumType     group_e.GroupMicNumType
	TouristMic     uint8     // 游客是否能上麦1是2否
	TouristSendMsg uint8     // 游客是否能发消息1是2否
	TouristSendPic uint8     // 游客是否能发图片1是2否
	MemberFee      uint64    // 加入会员需要黄钻数
	CreatedTime    time.Time `gorm:"->"`
	UpdatedTime    time.Time `gorm:"->"`
}

func GetGroupInfo(model *domain.Model, groupId string) (*GroupInfo, error) {
	if len(groupId) <= 0 {
		return nil, bizerr.GroupNotFound
	}
	r := GroupInfo{}
	err := model.Db.Where(&GroupInfo{ImGroupId: groupId}).First(&r).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, err
		}
	}
	return &r, nil
}

func FindGroupByOwner(model *domain.Model, ownerId uint64) ([]GroupInfo, error) {
	rows := make([]GroupInfo, 0)
	err := model.Db.Where(&GroupInfo{Owner: ownerId}).Find(&rows).Error
	if err != nil {
		return nil, err
	}
	return rows, nil
}

func ToTxGroupId(model *domain.Model, imGroupId string) (string, error) {
	if len(imGroupId) <= 0 {
		return "", nil
	}

	gi, err := GetGroupInfo(model, imGroupId)
	if err != nil {
		return "", err
	}
	if gi == nil {
		return "", bizerr.GroupNotFound
	}
	return gi.TxGroupId, nil
}

hujiebin's avatar
hujiebin committed
79 80 81 82 83 84 85 86 87 88 89 90
func ToTxGroupIdMap(model *domain.Model, imGroupIds []string) (map[string]string, error) {
	var res = make(map[string]string)
	var rows []GroupInfo
	if err := model.DB().Model(GroupInfo{}).Where("im_group_id in ?", imGroupIds).Find(&rows).Error; err != nil {
		return res, err
	}
	for _, v := range rows {
		res[v.ImGroupId] = v.TxGroupId
	}
	return res, nil
}

hujiebin's avatar
hujiebin committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
func ToImGroupId(model *domain.Model, txGroupId string) (string, error) {
	if len(txGroupId) <= 0 {
		return "", nil
	}

	gi, err := GetInfoByTxGroupId(model, txGroupId)
	if err != nil {
		return "", err
	}
	if gi == nil {
		return "", bizerr.GroupNotFound
	}
	return gi.ImGroupId, nil
}

func GetInfoByTxGroupId(model *domain.Model, txGroupId string) (*GroupInfo, error) {
	if len(txGroupId) <= 0 {
		return nil, bizerr.GroupNotFound
	}

	r := GroupInfo{}
	err := model.Db.Where(&GroupInfo{TxGroupId: txGroupId}).First(&r).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, err
		}
	}
	return &r, nil
}