2026-01-28 08:08:14 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// NotificationType represents the type of notification
|
|
|
|
|
type NotificationType string
|
|
|
|
|
|
|
|
|
|
const (
|
2026-01-28 08:38:18 +08:00
|
|
|
NotificationTypeSystem NotificationType = "system"
|
|
|
|
|
NotificationTypeAlert NotificationType = "alert"
|
|
|
|
|
NotificationTypeInfo NotificationType = "info"
|
|
|
|
|
NotificationTypeBudgetAlert NotificationType = "budget_alert" // 预算超支提醒
|
|
|
|
|
NotificationTypeRecurring NotificationType = "recurring" // 周期交易提醒
|
|
|
|
|
NotificationTypePaymentReminder NotificationType = "payment_reminder" // 还款提醒
|
|
|
|
|
NotificationTypeSavingsGoal NotificationType = "savings_goal" // 储蓄目标提醒
|
2026-01-28 08:08:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Notification represents a system notification for a user
|
|
|
|
|
type Notification struct {
|
|
|
|
|
BaseModel
|
2026-01-28 08:38:18 +08:00
|
|
|
UserID uint `gorm:"not null;index" json:"user_id"`
|
|
|
|
|
Title string `gorm:"size:200;not null" json:"title"`
|
|
|
|
|
Content string `gorm:"type:text;not null" json:"content"`
|
|
|
|
|
Type NotificationType `gorm:"size:30;not null;default:'system';index" json:"type"`
|
|
|
|
|
IsRead bool `gorm:"default:false;index" json:"is_read"`
|
|
|
|
|
Link string `gorm:"size:255" json:"link,omitempty"` // Optional link to redirect
|
|
|
|
|
ReadAt *time.Time `json:"read_at,omitempty"`
|
|
|
|
|
RelatedID *uint `gorm:"index" json:"related_id,omitempty"` // 关联实体 ID (如预算、周期交易等)
|
2026-01-28 08:08:14 +08:00
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
User User `gorm:"foreignKey:UserID" json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName specifies the table name for Notification
|
|
|
|
|
func (Notification) TableName() string {
|
|
|
|
|
return "notifications"
|
|
|
|
|
}
|