2026-03-29 20:18:36 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReportTargetType 举报目标类型
|
|
|
|
|
type ReportTargetType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ReportTargetTypePost ReportTargetType = "post" // 帖子
|
|
|
|
|
ReportTargetTypeComment ReportTargetType = "comment" // 评论
|
|
|
|
|
ReportTargetTypeMessage ReportTargetType = "message" // 消息
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReportStatus 举报处理状态
|
|
|
|
|
type ReportStatus string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ReportStatusPending ReportStatus = "pending" // 待处理
|
|
|
|
|
ReportStatusProcessing ReportStatus = "processing" // 处理中
|
|
|
|
|
ReportStatusResolved ReportStatus = "resolved" // 已确认违规
|
|
|
|
|
ReportStatusRejected ReportStatus = "rejected" // 已驳回
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReportReason 举报原因类型
|
|
|
|
|
type ReportReason string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ReportReasonSpam ReportReason = "spam" // 垃圾广告
|
|
|
|
|
ReportReasonInappropriate ReportReason = "inappropriate" // 违规内容
|
|
|
|
|
ReportReasonHarassment ReportReason = "harassment" // 辱骂/攻击
|
|
|
|
|
ReportReasonMisinformation ReportReason = "misinformation" // 虚假信息
|
|
|
|
|
ReportReasonOther ReportReason = "other" // 其他
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Report 举报实体
|
|
|
|
|
type Report struct {
|
|
|
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
|
|
|
|
ReporterID string `json:"reporter_id" gorm:"type:varchar(36);index;index:idx_reports_reporter_status,priority:1;not null"`
|
|
|
|
|
TargetType ReportTargetType `json:"target_type" gorm:"type:varchar(20);index;index:idx_reports_target_type_id,priority:1;index:idx_reports_target_status,priority:1;not null"`
|
|
|
|
|
TargetID string `json:"target_id" gorm:"type:varchar(36);index:idx_reports_target_type_id,priority:2;index:idx_reports_target,priority:1;not null"`
|
|
|
|
|
Reason ReportReason `json:"reason" gorm:"type:varchar(30);not null"`
|
|
|
|
|
Description string `json:"description" gorm:"type:text"`
|
|
|
|
|
Status ReportStatus `json:"status" gorm:"type:varchar(20);default:pending;index:idx_reports_status_created,priority:1;index:idx_reports_reporter_status,priority:2;index:idx_reports_target_status,priority:2"`
|
|
|
|
|
HandledBy *string `json:"handled_by" gorm:"type:varchar(36);index"`
|
|
|
|
|
HandledAt *time.Time `json:"handled_at" gorm:"type:timestamp"`
|
|
|
|
|
Result *string `json:"result" gorm:"type:text"`
|
|
|
|
|
|
|
|
|
|
// 软删除
|
|
|
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
|
|
|
|
|
|
|
|
|
// 时间戳
|
|
|
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index:idx_reports_status_created,priority:2,sort:desc"`
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BeforeCreate 创建前生成UUID
|
|
|
|
|
func (r *Report) BeforeCreate(tx *gorm.DB) error {
|
2026-05-04 13:07:03 +08:00
|
|
|
SetUUIDIfEmpty(&r.ID)
|
2026-03-29 20:18:36 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName 指定表名
|
|
|
|
|
func (Report) TableName() string {
|
|
|
|
|
return "reports"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReportStats 举报统计(用于缓存或查询结果)
|
|
|
|
|
type ReportStats struct {
|
|
|
|
|
TargetType ReportTargetType
|
|
|
|
|
TargetID string
|
|
|
|
|
ReportCount int
|
|
|
|
|
IsHidden bool
|
|
|
|
|
}
|