更新website
This commit is contained in:
@@ -129,6 +129,8 @@ func Init(_ string) {
|
||||
new(PlatformWebsiteNav),
|
||||
new(PlatformWebsiteLink),
|
||||
new(PlatformWebsitePage),
|
||||
// 站点公告(docs/sql/create_platform_website_notice.sql)
|
||||
new(PlatformWebsiteNotice),
|
||||
|
||||
new(SystemReminderList),
|
||||
|
||||
|
||||
@@ -160,6 +160,33 @@ func (m *PlatformWebsitePage) TableName() string {
|
||||
return "yz_platform_website_page"
|
||||
}
|
||||
|
||||
// PlatformWebsiteNotice 平台官网-站点公告 yz_platform_website_notice
|
||||
// 建表 SQL:docs/sql/create_platform_website_notice.sql
|
||||
type PlatformWebsiteNotice struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Title string `orm:"column(title);size(255);default('')" json:"title"`
|
||||
Summary string `orm:"column(summary);size(500);default('')" json:"summary"`
|
||||
Content string `orm:"column(content);type(mediumtext);null" json:"content"`
|
||||
Type int8 `orm:"column(type);default(1)" json:"type"` // 1 通知公告 2 活动公告 3 系统维护
|
||||
LinkURL string `orm:"column(link_url);size(500);default('')" json:"link_url"`
|
||||
IsPopup int8 `orm:"column(is_popup);default(0)" json:"is_popup"` // 是否作为弹窗公告
|
||||
Top int8 `orm:"column(top);default(0)" json:"top"` // 是否置顶
|
||||
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"` // 0 草稿 1 已发布 2 已下线
|
||||
StartTime *time.Time `orm:"column(start_time);type(datetime);null" json:"start_time"`
|
||||
EndTime *time.Time `orm:"column(end_time);type(datetime);null" json:"end_time"`
|
||||
Views int `orm:"column(views);default(0)" json:"views"`
|
||||
PublisherID *uint64 `orm:"column(publisher_id);null" json:"publisher_id"`
|
||||
PublishTime *time.Time `orm:"column(publish_time);type(datetime);null" json:"publish_time"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *PlatformWebsiteNotice) TableName() string {
|
||||
return "yz_platform_website_notice"
|
||||
}
|
||||
|
||||
// ===================== 公共查询helper =====================
|
||||
|
||||
// PlatformWebsiteCategoryNameMap 分类ID -> 分类名称
|
||||
@@ -199,6 +226,50 @@ func PlatformWebsiteCategoryMap(ids []uint64) map[uint64]PlatformWebsiteCategory
|
||||
return out
|
||||
}
|
||||
|
||||
// PlatformWebsiteCategoryDescendantMap 分类ID -> 全部后代分类ID(不含自身)
|
||||
//
|
||||
// 官网前台按父分类筛选 / 统计数量时,需要把整棵子树都算进来:
|
||||
// 文章挂在子分类上时,点父分类也应该能看到。
|
||||
// 分类数据量很小,每次整体构建一次即可;存在环时靠 seen 截断。
|
||||
func PlatformWebsiteCategoryDescendantMap() map[uint64][]uint64 {
|
||||
out := make(map[uint64][]uint64)
|
||||
|
||||
var rows []PlatformWebsiteCategory
|
||||
if _, err := Orm.QueryTable(new(PlatformWebsiteCategory)).
|
||||
Filter("delete_time__isnull", true).
|
||||
All(&rows, "ID", "Cid"); err != nil {
|
||||
return out
|
||||
}
|
||||
|
||||
children := make(map[uint64][]uint64, len(rows))
|
||||
ids := make([]uint64, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
if r.Cid > 0 && r.Cid != r.ID {
|
||||
children[r.Cid] = append(children[r.Cid], r.ID)
|
||||
}
|
||||
}
|
||||
|
||||
var walk func(id uint64, seen map[uint64]bool) []uint64
|
||||
walk = func(id uint64, seen map[uint64]bool) []uint64 {
|
||||
res := make([]uint64, 0, len(children[id]))
|
||||
for _, child := range children[id] {
|
||||
if seen[child] {
|
||||
continue
|
||||
}
|
||||
seen[child] = true
|
||||
res = append(res, child)
|
||||
res = append(res, walk(child, seen)...)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
out[id] = walk(id, map[uint64]bool{id: true})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PlatformWebsiteArticleTitleMap 文章ID -> 标题(评论列表展示所属文章用)
|
||||
func PlatformWebsiteArticleTitleMap(ids []uint64) map[uint64]string {
|
||||
out := make(map[uint64]string)
|
||||
|
||||
Reference in New Issue
Block a user