package yb_activity_register

import "hongze/hongze_yb/global"

type UserRegister struct {
	ActivityRegisterID	int	`json:"activityRegisterId"`
	UserId				int	`json:"userId"`
	ActivityId			int	`json:"activityId"`
	RegisterState		int	`json:"registerState"`
}

// RegisterExist 根据用户ID和活动ID获取报名信息
func RegisterExist(userId, activityId int) (register *YbActivityRegister, err error) {
	err = global.DEFAULT_MYSQL.Table("yb_activity_register").Where("user_id = ? AND activity_id = ? AND register_state = ?", userId, activityId, 1).First(&register).Error
	return
}

// CountRegistedNumByActivityId 根据活动ID获取报名人数
func CountRegistedNumByActivityId(activityId int) (count int64, err error) {
	err = global.DEFAULT_MYSQL.Table("yb_activity_register").Where("activity_id = ? AND register_state = ?", activityId, 1).Count(&count).Error
	return
}

// GetRegistersByUserIdAndActivityIds 根据用户ID和活动IDs获取报名信息
func GetRegistersByUserIdAndActivityIds(userId int, activityIds []int) (registers []UserRegister, err error) {
	fields := []string{"activity_register_id", "user_id", "activity_id", "register_state"}
	err = global.DEFAULT_MYSQL.Model(YbActivityRegister{}).Select(fields).Where("user_id = ? AND register_state = ? AND activity_id IN (?)", userId, 1, activityIds).Scan(&registers).Error
	return
}