diff --git a/internal/model/notification.go b/internal/model/notification.go index 827dc2e..40d215a 100644 --- a/internal/model/notification.go +++ b/internal/model/notification.go @@ -6,6 +6,8 @@ const ( NotifyAuditRejected = "audit_rejected" NotifyPostApproved = "post_approved" NotifyPostRejected = "post_rejected" + NotifyPostLocked = "post_locked" + NotifyPostUnlocked = "post_unlocked" NotifyLevelUp = "level_up" NotifyComment = "comment" NotifyCommentReply = "comment_reply" @@ -32,6 +34,8 @@ var NotifyTypeNames = map[string]string{ NotifyAuditRejected: "资料审核", NotifyPostApproved: "稿件审核", NotifyPostRejected: "稿件审核", + NotifyPostLocked: "稿件审核", + NotifyPostUnlocked: "稿件审核", NotifyLevelUp: "等级提升", NotifyComment: "评论", NotifyCommentReply: "回复", @@ -45,6 +49,8 @@ var NotifyCategory = map[string]string{ NotifyAuditRejected: "system", NotifyPostApproved: "system", NotifyPostRejected: "system", + NotifyPostLocked: "system", + NotifyPostUnlocked: "system", NotifyLevelUp: "system", NotifyComment: "mention", NotifyCommentReply: "mention", diff --git a/internal/service/notification_notify.go b/internal/service/notification_notify.go index ec3f0aa..820fcf5 100644 --- a/internal/service/notification_notify.go +++ b/internal/service/notification_notify.go @@ -47,7 +47,7 @@ func countUIDs(uids string) int { func categoryTypes(category string) []string { switch category { case "system": - return []string{model.NotifyAuditApproved, model.NotifyAuditRejected, model.NotifyPostApproved, model.NotifyPostRejected, model.NotifyLevelUp} + return []string{model.NotifyAuditApproved, model.NotifyAuditRejected, model.NotifyPostApproved, model.NotifyPostRejected, model.NotifyPostLocked, model.NotifyPostUnlocked, model.NotifyLevelUp} case "mention": return []string{model.NotifyComment, model.NotifyCommentReply} case "like": @@ -111,6 +111,24 @@ func (s *NotificationService) NotifyPostRejected(userID uint, postTitle, reason _ = s.Create(userID, model.NotifyPostRejected, title, content, &postID, nil) } +// NotifyPostLocked 稿件锁定通知 +func (s *NotificationService) NotifyPostLocked(userID uint, postTitle, reason string, postID uint) { + title := "稿件被锁定" + content := "你的稿件《" + postTitle + "》已被锁定" + if reason != "" { + content += ",理由:" + reason + } + _ = s.Create(userID, model.NotifyPostLocked, title, content, &postID, nil) +} + +// NotifyPostUnlocked 稿件解除锁定通知 +func (s *NotificationService) NotifyPostUnlocked(userID uint, postTitle string, postID uint) { + _ = s.Create(userID, model.NotifyPostUnlocked, + "稿件被解除锁定", + "你的稿件《"+postTitle+"》已被解除锁定", + &postID, nil) +} + // NotifyFollow 关注通知(followerID 关注了 followeeID) func (s *NotificationService) NotifyFollow(followerID, followeeID uint) { // 获取关注者用户名 diff --git a/internal/service/post_audit_service.go b/internal/service/post_audit_service.go index ac592b9..0084897 100644 --- a/internal/service/post_audit_service.go +++ b/internal/service/post_audit_service.go @@ -163,7 +163,14 @@ func (s *PostService) Lock(postID uint, reason string) error { } post.IsLocked = true post.LockReason = reason - return s.repo.Update(post) + if err := s.repo.Update(post); err != nil { + return err + } + // 通知作者稿件被锁定 + if s.notifier != nil { + s.notifier.NotifyPostLocked(post.UserID, post.Title, reason, post.ID) + } + return nil } // Unlock 解锁:清除 IsLocked 标志,恢复可编辑 @@ -177,7 +184,14 @@ func (s *PostService) Unlock(postID uint) error { } post.IsLocked = false post.LockReason = "" - return s.repo.Update(post) + if err := s.repo.Update(post); err != nil { + return err + } + // 通知作者稿件被解除锁定 + if s.notifier != nil { + s.notifier.NotifyPostUnlocked(post.UserID, post.Title, post.ID) + } + return nil } // Restore 恢复软删除 diff --git a/internal/service/repository.go b/internal/service/repository.go index d3a3ddf..4bc2ae4 100644 --- a/internal/service/repository.go +++ b/internal/service/repository.go @@ -75,6 +75,8 @@ type userExpReader interface { type postNotifier interface { NotifyPostApproved(userID uint, postTitle string, postID uint) NotifyPostRejected(userID uint, postTitle, reason string, postID uint) + NotifyPostLocked(userID uint, postTitle, reason string, postID uint) + NotifyPostUnlocked(userID uint, postTitle string, postID uint) } // userLevelStore LevelService 所需的用户仓储接口