gift.go 1.17 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
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
}

// 获取所有有效的礼物
func FindValidResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) {
	res := make(map[mysql.ID]ResGift, 0)
	rows := make([]ResGift, 0)
	if err := model.DB().Model(ResGift{}).Where("status = ?", mysql.USER).Find(&rows).Error; err != nil {
		return nil, err
	}
	for i, v := range rows {
		res[v.ID] = rows[i]
	}
	return res, nil
}
hujiebin's avatar
hujiebin committed
39 40 41 42 43 44 45 46 47

// 获取礼物
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
}