gift.go 1.15 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
package res_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
)

type ResGift struct {
	mysql.Entity
	Name              mysql.Str
	IconUrl           mysql.Str
	SvagUrl           mysql.Str
	MusicUrl          mysql.Str
	Column            uint16
	DiamondNum        mysql.Num
	BeanNum           mysql.Num
	ReceiveDiamondNum mysql.Num
	Second            mysql.Num // obsolete
	N                 mysql.Num
	GroupBroadcast    bool
	Cp                bool
	Together          bool
	Status            mysql.UserYesNo
	GiftType          mysql.Type
hujiebin's avatar
hujiebin committed
25
	HasGiftText       bool
hujiebin's avatar
hujiebin committed
26 27
}

hujiebin's avatar
hujiebin committed
28 29
// 获取所有的礼物
func FindAllResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) {
hujiebin's avatar
hujiebin committed
30 31
	res := make(map[mysql.ID]ResGift, 0)
	rows := make([]ResGift, 0)
hujiebin's avatar
hujiebin committed
32
	if err := model.DB().Model(ResGift{}).Find(&rows).Error; err != nil {
hujiebin's avatar
hujiebin committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
		return nil, err
	}
	for i, v := range rows {
		res[v.ID] = rows[i]
	}
	return res, nil
}

// 获取礼物
func FindResGift(model *domain.Model, giftId mysql.ID) (*ResGift, error) {
	res := new(ResGift)
	if err := model.DB().Model(ResGift{}).Where("id = ?", giftId).First(res).Error; err != nil {
		return nil, err
	}
	return res, nil
}