feat(posts): 类型帖截止时间、抽奖奖品表与悬赏发帖体验
统一投票/悬赏/抽奖截止与状态展示,抽奖支持多奖品行;发帖页悬赏积分对齐表格输入,并在余额不足时于底部就地提示。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -91,6 +91,8 @@ func (h *Handlers) CreateComment(c *gin.Context) {
|
||||
if authorID, e := h.Post.GetAuthorID(uint(id)); e == nil {
|
||||
h.Notification.Create(authorID, claims.ID, model.NotificationTypeComment, uint(id), comment.ID, req.Content)
|
||||
}
|
||||
// 抽奖帖:主评入池并记录客户端 IP(同 IP 去重)
|
||||
h.Post.EnsureLotteryEntry(uint(id), claims.ID, comment.ID, c.ClientIP())
|
||||
} else {
|
||||
// 子回复:通知父评论作者(Notification.Create 内部排除自我通知)
|
||||
h.Notification.Create(parent.UserID, claims.ID, model.NotificationTypeReply, uint(id), comment.ID, req.Content)
|
||||
|
||||
@@ -78,6 +78,12 @@ func (h *Handlers) AdminApproveComment(c *gin.Context) {
|
||||
h.writeModerationError(c, err)
|
||||
return
|
||||
}
|
||||
// 抽奖帖主评通过审核后入池(无评论者 IP,回退其最近登录 IP)
|
||||
var cm model.Comment
|
||||
if e := model.DB.Select("id", "post_id", "user_id", "parent_id").First(&cm, uint(id)).Error; e == nil && cm.ParentID == nil {
|
||||
ip := h.Post.LatestSuccessLoginIP(cm.UserID)
|
||||
h.Post.EnsureLotteryEntry(cm.PostID, cm.UserID, cm.ID, ip)
|
||||
}
|
||||
h.broadcastFeedChanged("comment", postID, boardID, actor.ID)
|
||||
h.broadcastModerationChanged()
|
||||
c.JSON(http.StatusOK, gin.H{"message": "操作成功"})
|
||||
|
||||
@@ -449,6 +449,9 @@ func respondPostModError(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
case errors.Is(err, service.ErrPostForbidden):
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
|
||||
case errors.Is(err, service.ErrPollOptionsLocked),
|
||||
errors.Is(err, service.ErrLotteryPrizesLocked):
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ func (h *Handlers) respondInteractError(c *gin.Context, err error) {
|
||||
errors.Is(err, service.ErrPollClosed),
|
||||
errors.Is(err, service.ErrPollOptionsLocked),
|
||||
errors.Is(err, service.ErrLotteryDrawn),
|
||||
errors.Is(err, service.ErrLotteryClosed),
|
||||
errors.Is(err, service.ErrBountySettled),
|
||||
errors.Is(err, service.ErrBountyExpired):
|
||||
errors.Is(err, service.ErrBountySettled):
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -148,38 +146,6 @@ func (h *Handlers) AcceptBounty(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"post": post})
|
||||
}
|
||||
|
||||
// RefundBounty 退回悬赏
|
||||
func (h *Handlers) RefundBounty(c *gin.Context) {
|
||||
claims := middleware.CurrentUser(c)
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "无效的帖子 ID"})
|
||||
return
|
||||
}
|
||||
post, err := h.Post.RefundBounty(h.loadActor(claims.ID), claims.ID, uint(id))
|
||||
if err != nil {
|
||||
h.respondInteractError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"post": post})
|
||||
}
|
||||
|
||||
// CloseLottery 截止抽奖
|
||||
func (h *Handlers) CloseLottery(c *gin.Context) {
|
||||
claims := middleware.CurrentUser(c)
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "无效的帖子 ID"})
|
||||
return
|
||||
}
|
||||
post, err := h.Post.CloseLotteryEntries(h.loadActor(claims.ID), claims.ID, uint(id))
|
||||
if err != nil {
|
||||
h.respondInteractError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"post": post})
|
||||
}
|
||||
|
||||
// DrawLottery 开奖
|
||||
func (h *Handlers) DrawLottery(c *gin.Context) {
|
||||
claims := middleware.CurrentUser(c)
|
||||
|
||||
Reference in New Issue
Block a user