feat: add ads/sponsor/captcha modules and polish home & chat UI
This commit is contained in:
@@ -10,13 +10,19 @@ import (
|
||||
|
||||
// OverviewService 首页聚合服务:一次请求返回统计、热门榜、活跃用户、板块计数
|
||||
type OverviewService struct {
|
||||
db *gorm.DB
|
||||
db *gorm.DB
|
||||
ads *AdService
|
||||
}
|
||||
|
||||
func NewOverviewService(db *gorm.DB) *OverviewService {
|
||||
return &OverviewService{db: db}
|
||||
}
|
||||
|
||||
func (s *OverviewService) WithAds(ads *AdService) *OverviewService {
|
||||
s.ads = ads
|
||||
return s
|
||||
}
|
||||
|
||||
// OverviewStats 社区整体统计(社区脉搏卡)
|
||||
type OverviewStats struct {
|
||||
Posts int64 `json:"posts"`
|
||||
@@ -75,6 +81,32 @@ type OverviewData struct {
|
||||
SidebarPages []SidebarPageItem `json:"sidebar_pages"`
|
||||
NewUsers []NewUserItem `json:"new_users"`
|
||||
Checkin *CheckinStatus `json:"checkin,omitempty"`
|
||||
Ads []PublicAdItem `json:"ads"`
|
||||
AdsPanelTitle string `json:"ads_panel_title"`
|
||||
AdsEnabled bool `json:"ads_enabled"`
|
||||
Sponsors []PublicSponsorItem `json:"sponsors"`
|
||||
SponsorsPanelTitle string `json:"sponsors_panel_title"`
|
||||
SponsorsEnabled bool `json:"sponsors_enabled"`
|
||||
}
|
||||
|
||||
// PublicAdItem 侧栏广告条目
|
||||
type PublicAdItem struct {
|
||||
ID uint `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
LinkURL string `json:"link_url"`
|
||||
ImageURL string `json:"image_url,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
TextColor string `json:"text_color,omitempty"`
|
||||
BgColor string `json:"bg_color,omitempty"`
|
||||
}
|
||||
|
||||
// PublicSponsorItem 侧栏赞助商
|
||||
type PublicSponsorItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LogoURL string `json:"logo_url"`
|
||||
LinkURL string `json:"link_url,omitempty"`
|
||||
HoverText string `json:"hover_text,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -286,6 +318,36 @@ LIMIT 5`
|
||||
})
|
||||
}
|
||||
|
||||
data.Ads = []PublicAdItem{}
|
||||
data.AdsPanelTitle = AdDefaultTitle
|
||||
data.Sponsors = []PublicSponsorItem{}
|
||||
data.SponsorsPanelTitle = SponsorDefaultTitle
|
||||
if s.ads != nil {
|
||||
list, cfg, err := s.ads.ActivePublic()
|
||||
if err == nil {
|
||||
data.AdsEnabled = cfg.Enabled
|
||||
data.AdsPanelTitle = cfg.PanelTitle
|
||||
for _, a := range list {
|
||||
data.Ads = append(data.Ads, PublicAdItem{
|
||||
ID: a.ID, Kind: a.Kind, LinkURL: a.LinkURL,
|
||||
ImageURL: a.ImageURL, Title: a.Title,
|
||||
TextColor: a.TextColor, BgColor: a.BgColor,
|
||||
})
|
||||
}
|
||||
}
|
||||
scfg, slist, err := s.ads.PublicSponsors()
|
||||
if err == nil {
|
||||
data.SponsorsEnabled = scfg.Enabled
|
||||
data.SponsorsPanelTitle = scfg.PanelTitle
|
||||
for _, it := range slist {
|
||||
data.Sponsors = append(data.Sponsors, PublicSponsorItem{
|
||||
ID: it.ID, Name: it.Name, LogoURL: it.LogoURL,
|
||||
LinkURL: it.LinkURL, HoverText: it.HoverText,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user