user_bag.go 818 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
package bag_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"hilo-user/_const/enum/res_e"
	"time"
)

type UserBag struct {
	mysql.Entity
	UserId  mysql.ID
	ResType mysql.Type
	ResId   mysql.ID
	Count   mysql.Num
	EndTime time.Time
}

// 获取用户有效的背包
// param userId 用户id
// param resType 背包类型 1:礼物
// condition
//	1.获取end_time未到期的
//	2.数量大于0的
func GetUserValidUserBag(model *domain.Model, userId mysql.ID, resType res_e.ResUserBag) ([]*UserBag, error) {
	var res []*UserBag
	if err := model.DB().Model(UserBag{}).
		Where("end_time > ?", time.Now()).
		Where("count > 0").
hujiebin's avatar
hujiebin committed
30
		Where("res_type = ?", resType).
hujiebin's avatar
hujiebin committed
31 32
		Where("user_id = ?", userId).
		Order("id").Find(&res).Error; err != nil {
hujiebin's avatar
hujiebin committed
33 34 35 36
		return nil, err
	}
	return res, nil
}