feat: add ads/sponsor/captcha modules and polish home & chat UI
This commit is contained in:
44
backend/model/ad.go
Normal file
44
backend/model/ad.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 广告类型与状态
|
||||
const (
|
||||
AdKindImage = "image"
|
||||
AdKindText = "text"
|
||||
|
||||
AdStatusPending = "pending"
|
||||
AdStatusActive = "active"
|
||||
AdStatusRejected = "rejected"
|
||||
AdStatusExpired = "expired"
|
||||
)
|
||||
|
||||
// Ad 赞助广告(游客可申购,管理员审核后展示于首页侧栏)
|
||||
type Ad struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Kind string `gorm:"size:16;not null;index" json:"kind"` // image | text
|
||||
Status string `gorm:"size:16;not null;index" json:"status"` // pending/active/rejected/expired
|
||||
ContactEmail string `gorm:"size:128;not null" json:"contact_email"`
|
||||
LinkURL string `gorm:"size:512;not null" json:"link_url"`
|
||||
ImageURL string `gorm:"size:512" json:"image_url"` // 图片广告
|
||||
Title string `gorm:"size:64" json:"title"` // 文字广告
|
||||
TextColor string `gorm:"size:16" json:"text_color"`
|
||||
BgColor string `gorm:"size:16" json:"bg_color"`
|
||||
DurationDays int `gorm:"not null" json:"duration_days"`
|
||||
PaymentID string `gorm:"size:64;not null" json:"payment_id"`
|
||||
BuyerNote string `gorm:"size:200" json:"buyer_note"`
|
||||
StartsAt *time.Time `json:"starts_at"`
|
||||
EndsAt *time.Time `json:"ends_at"`
|
||||
RejectReason string `gorm:"size:200" json:"reject_reason"`
|
||||
SortOrder int `gorm:"not null;default:0" json:"sort_order"`
|
||||
SubmitIP string `gorm:"size:45" json:"-"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
ReviewedBy *uint `json:"reviewed_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func InitDB(dsn string) error {
|
||||
&Announcement{}, &SitePage{}, &SiteSetting{}, &SiteDailyStats{}, &SiteDailyVisitor{}, &Attachment{}, &UserBoard{}, &LoginLog{},
|
||||
&ChatRoom{}, &ChatRoomMember{}, &ChatMessage{},
|
||||
&PointLedger{}, &PostContentUnlock{}, &PostAttachment{}, &PostAttachmentUnlock{},
|
||||
&PostPollVote{}, &PostLotteryEntry{},
|
||||
&PostPollVote{}, &PostLotteryEntry{}, &Ad{},
|
||||
); err != nil {
|
||||
return fmt.Errorf("自动迁移失败: %w", err)
|
||||
}
|
||||
@@ -78,6 +78,11 @@ func InitDB(dsn string) error {
|
||||
return fmt.Errorf("login_logs 默认值修正失败: %w", err)
|
||||
}
|
||||
|
||||
// 早期 site_settings.value 可能是 varchar(255);广告/赞助商 JSON 会超长
|
||||
if err := prepareSiteSettingValueText(db); err != nil {
|
||||
return fmt.Errorf("site_settings.value 扩容失败: %w", err)
|
||||
}
|
||||
|
||||
// 新表结构就位后删除遗留的明文列
|
||||
if err := dropLegacyRefreshTokenColumn(db); err != nil {
|
||||
return fmt.Errorf("refresh token 旧列清理失败: %w", err)
|
||||
@@ -152,6 +157,28 @@ func prepareAnnouncementPinnedColumn(db *gorm.DB) error {
|
||||
return db.Exec(`ALTER TABLE announcements ADD COLUMN pinned boolean NOT NULL DEFAULT false`).Error
|
||||
}
|
||||
|
||||
// prepareSiteSettingValueText 将 site_settings.value 从 varchar(255) 扩为 text(幂等)
|
||||
func prepareSiteSettingValueText(db *gorm.DB) error {
|
||||
var tableCount int64
|
||||
if err := db.Raw(`SELECT count(1) FROM information_schema.tables WHERE table_name = 'site_settings'`).
|
||||
Scan(&tableCount).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if tableCount == 0 {
|
||||
return nil
|
||||
}
|
||||
var dataType string
|
||||
if err := db.Raw(`SELECT data_type FROM information_schema.columns
|
||||
WHERE table_name = 'site_settings' AND column_name = 'value'`).
|
||||
Scan(&dataType).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if dataType == "" || dataType == "text" {
|
||||
return nil
|
||||
}
|
||||
return db.Exec(`ALTER TABLE site_settings ALTER COLUMN value TYPE text`).Error
|
||||
}
|
||||
|
||||
// prepareRefreshTokenSessionColumns 存量 refresh_tokens 加 logged_in_at / last_used_at:
|
||||
// 先可空加列,用 created_at 回填后再收紧 NOT NULL。
|
||||
func prepareRefreshTokenSessionColumns(db *gorm.DB) error {
|
||||
|
||||
Reference in New Issue
Block a user