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"). Where("res_type = ?", resType). Where("user_id = ?", userId). Order("id").Find(&res).Error; err != nil { return nil, err } return res, nil }