346 lines
13 KiB
Go
346 lines
13 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type PlatformWebsiteCategory struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Cid uint64 `orm:"column(cid);default(0)" json:"cid"`
|
|
Name string `orm:"column(name);size(100);default('')" json:"name"`
|
|
Image string `orm:"column(image);size(500);default('')" json:"image"`
|
|
Desc string `orm:"column(desc);size(500);default('')" json:"desc"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
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 *PlatformWebsiteCategory) TableName() string {
|
|
return "yz_platform_website_category"
|
|
}
|
|
|
|
type PlatformWebsiteArticle struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
CateID uint64 `orm:"column(cate_id);default(0)" json:"cate_id"`
|
|
Title string `orm:"column(title);size(255);default('')" json:"title"`
|
|
Author string `orm:"column(author);size(100);default('')" json:"author"`
|
|
Desc string `orm:"column(desc);size(500);default('')" json:"desc"`
|
|
Image string `orm:"column(image);size(500);default('')" json:"image"`
|
|
Content string `orm:"column(content);type(mediumtext);null" json:"content"`
|
|
IsTrans int8 `orm:"column(is_trans);default(0)" json:"is_trans"`
|
|
TransURL *string `orm:"column(transurl);size(500);null" json:"transurl"`
|
|
Status int8 `orm:"column(status);default(0)" json:"status"`
|
|
Top int8 `orm:"column(top);default(0)" json:"top"`
|
|
Recommend int8 `orm:"column(recommend);default(0)" json:"recommend"`
|
|
Views int `orm:"column(views);default(0)" json:"views"`
|
|
Likes int `orm:"column(likes);default(0)" json:"likes"`
|
|
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 *PlatformWebsiteArticle) TableName() string {
|
|
return "yz_platform_website_article"
|
|
}
|
|
|
|
type PlatformWebsiteTag struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Name string `orm:"column(name);size(50);default('')" json:"name"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
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 *PlatformWebsiteTag) TableName() string {
|
|
return "yz_platform_website_tag"
|
|
}
|
|
|
|
type PlatformWebsiteArticleTag struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
ArticleID uint64 `orm:"column(article_id);default(0)" json:"article_id"`
|
|
TagID uint64 `orm:"column(tag_id);default(0)" json:"tag_id"`
|
|
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
|
}
|
|
|
|
func (m *PlatformWebsiteArticleTag) TableName() string {
|
|
return "yz_platform_website_article_tag"
|
|
}
|
|
|
|
type PlatformWebsiteComment struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
ArticleID uint64 `orm:"column(article_id);default(0)" json:"article_id"`
|
|
Nickname string `orm:"column(nickname);size(100);default('')" json:"nickname"`
|
|
Email string `orm:"column(email);size(150);default('')" json:"email"`
|
|
Content string `orm:"column(content);type(text);null" json:"content"`
|
|
Reply string `orm:"column(reply);type(text);null" json:"reply"`
|
|
Status int8 `orm:"column(status);default(0)" json:"status"`
|
|
IP string `orm:"column(ip);size(64);default('')" json:"ip"`
|
|
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 *PlatformWebsiteComment) TableName() string {
|
|
return "yz_platform_website_comment"
|
|
}
|
|
|
|
type PlatformWebsiteNav struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Pid uint64 `orm:"column(pid);default(0)" json:"pid"`
|
|
Title string `orm:"column(title);size(100);default('')" json:"title"`
|
|
Type int8 `orm:"column(type);default(1)" json:"type"`
|
|
Path string `orm:"column(path);size(255);default('')" json:"path"`
|
|
ComponentPath string `orm:"column(component_path);size(255);default('')" json:"component_path"`
|
|
Icon string `orm:"column(icon);size(100);default('')" json:"icon"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
IsVisible int8 `orm:"column(is_visible);default(1)" json:"is_visible"`
|
|
Permission string `orm:"column(permission);size(100);default('')" json:"permission"`
|
|
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 *PlatformWebsiteNav) TableName() string {
|
|
return "yz_platform_website_nav"
|
|
}
|
|
|
|
type PlatformWebsiteLink struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
LinkName string `orm:"column(link_name);size(100);default('')" json:"link_name"`
|
|
LinkURL string `orm:"column(link_url);size(500);default('')" json:"link_url"`
|
|
LinkLogo string `orm:"column(link_logo);size(500);default('')" json:"link_logo"`
|
|
Description string `orm:"column(description);size(255);default('')" json:"description"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
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 *PlatformWebsiteLink) TableName() string {
|
|
return "yz_platform_website_link"
|
|
}
|
|
|
|
type PlatformWebsitePage struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Title string `orm:"column(title);size(255);default('')" json:"title"`
|
|
Path string `orm:"column(path);size(200);default('')" json:"path"`
|
|
Content string `orm:"column(content);type(longtext);null" json:"content"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
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 *PlatformWebsitePage) TableName() string {
|
|
return "yz_platform_website_page"
|
|
}
|
|
|
|
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"`
|
|
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"`
|
|
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"
|
|
}
|
|
|
|
func PlatformWebsiteCategoryNameMap(ids []uint64) map[uint64]string {
|
|
out := make(map[uint64]string)
|
|
if len(ids) == 0 {
|
|
return out
|
|
}
|
|
var rows []PlatformWebsiteCategory
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteCategory)).
|
|
Filter("id__in", ids).
|
|
All(&rows, "ID", "Name"); err != nil {
|
|
return out
|
|
}
|
|
for _, r := range rows {
|
|
out[r.ID] = r.Name
|
|
}
|
|
return out
|
|
}
|
|
|
|
func PlatformWebsiteCategoryMap(ids []uint64) map[uint64]PlatformWebsiteCategory {
|
|
out := make(map[uint64]PlatformWebsiteCategory)
|
|
if len(ids) == 0 {
|
|
return out
|
|
}
|
|
var rows []PlatformWebsiteCategory
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteCategory)).
|
|
Filter("id__in", ids).
|
|
All(&rows, "ID", "Name", "Desc", "Image"); err != nil {
|
|
return out
|
|
}
|
|
for _, r := range rows {
|
|
out[r.ID] = r
|
|
}
|
|
return out
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func PlatformWebsiteArticleTitleMap(ids []uint64) map[uint64]string {
|
|
out := make(map[uint64]string)
|
|
if len(ids) == 0 {
|
|
return out
|
|
}
|
|
var rows []PlatformWebsiteArticle
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteArticle)).
|
|
Filter("id__in", ids).
|
|
All(&rows, "ID", "Title"); err != nil {
|
|
return out
|
|
}
|
|
for _, r := range rows {
|
|
out[r.ID] = r.Title
|
|
}
|
|
return out
|
|
}
|
|
|
|
func PlatformWebsiteArticleTagNameMap(articleIDs []uint64) map[uint64][]string {
|
|
out := make(map[uint64][]string)
|
|
if len(articleIDs) == 0 {
|
|
return out
|
|
}
|
|
var links []PlatformWebsiteArticleTag
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteArticleTag)).
|
|
Filter("article_id__in", articleIDs).
|
|
All(&links, "ID", "ArticleID", "TagID"); err != nil {
|
|
return out
|
|
}
|
|
if len(links) == 0 {
|
|
return out
|
|
}
|
|
|
|
tagIDs := make([]uint64, 0, len(links))
|
|
for _, l := range links {
|
|
tagIDs = append(tagIDs, l.TagID)
|
|
}
|
|
var tags []PlatformWebsiteTag
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteTag)).
|
|
Filter("id__in", tagIDs).
|
|
Filter("delete_time__isnull", true).
|
|
All(&tags, "ID", "Name"); err != nil {
|
|
return out
|
|
}
|
|
nameMap := make(map[uint64]string, len(tags))
|
|
for _, t := range tags {
|
|
nameMap[t.ID] = t.Name
|
|
}
|
|
|
|
for _, l := range links {
|
|
if name, ok := nameMap[l.TagID]; ok && name != "" {
|
|
out[l.ArticleID] = append(out[l.ArticleID], name)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func PlatformWebsiteArticleTagIDs(articleID uint64) []uint64 {
|
|
out := make([]uint64, 0)
|
|
if articleID == 0 {
|
|
return out
|
|
}
|
|
var rows []PlatformWebsiteArticleTag
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteArticleTag)).
|
|
Filter("article_id", articleID).
|
|
All(&rows, "ID", "TagID"); err != nil {
|
|
return out
|
|
}
|
|
for _, r := range rows {
|
|
out = append(out, r.TagID)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func SetPlatformWebsiteArticleTags(articleID uint64, tagIDs []uint64) error {
|
|
if articleID == 0 {
|
|
return nil
|
|
}
|
|
if _, err := Orm.QueryTable(new(PlatformWebsiteArticleTag)).
|
|
Filter("article_id", articleID).
|
|
Delete(); err != nil {
|
|
return err
|
|
}
|
|
seen := make(map[uint64]bool, len(tagIDs))
|
|
for _, tid := range tagIDs {
|
|
if tid == 0 || seen[tid] {
|
|
continue
|
|
}
|
|
seen[tid] = true
|
|
if _, err := Orm.Insert(&PlatformWebsiteArticleTag{ArticleID: articleID, TagID: tid}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ClearPlatformWebsiteArticleTags(articleID uint64) error {
|
|
_, err := Orm.QueryTable(new(PlatformWebsiteArticleTag)).
|
|
Filter("article_id", articleID).
|
|
Delete()
|
|
return err
|
|
}
|