fix: 批量修复功能问题 - 购物车结算/订单库存积分/搜索/抽奖/个人资料等
This commit is contained in:
@@ -52,6 +52,31 @@ func (h *LotteryHandler) Register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !lottery.IsActive {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Lottery is not active"})
|
||||
return
|
||||
}
|
||||
|
||||
if lottery.TotalQuota != nil && *lottery.TotalQuota > 0 {
|
||||
var participantCount int64
|
||||
utils.DB.Model(&models.LotteryParticipant{}).Where("lottery_id = ?", id).Count(&participantCount)
|
||||
if int(participantCount) >= *lottery.TotalQuota {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Lottery quota is full"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if lottery.DailyQuota != nil && *lottery.DailyQuota > 0 {
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
var dailyCount int64
|
||||
utils.DB.Model(&models.LotteryParticipant{}).Where("lottery_id = ? AND registered_at >= ? AND registered_at < ?", id, today, tomorrow).Count(&dailyCount)
|
||||
if int(dailyCount) >= *lottery.DailyQuota {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Daily quota is full"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var existing models.LotteryParticipant
|
||||
if err := utils.DB.Where("lottery_id = ? AND user_id = ?", id, userID).First(&existing).Error; err == nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Already registered"})
|
||||
|
||||
Reference in New Issue
Block a user