91 lines
3.2 KiB
Go
91 lines
3.2 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
)
|
|
|
|
// MpNews 微信公众号图文发表记录表
|
|
type MpNews struct {
|
|
global.GVA_MODEL
|
|
MediaID string `json:"mediaId" gorm:"type:varchar(128);not null;index;comment:图文消息的media_id"`
|
|
Title string `json:"title" gorm:"type:varchar(255);not null;comment:图文消息标题"`
|
|
Author *string `json:"author" gorm:"type:varchar(100);comment:作者"`
|
|
Digest *string `json:"digest" gorm:"type:varchar(500);comment:图文消息摘要"`
|
|
Content *string `json:"content" gorm:"type:longtext;comment:图文消息内容"`
|
|
ContentURL *string `json:"contentUrl" gorm:"type:varchar(1024);comment:图文页的URL"`
|
|
SourceURL *string `json:"sourceUrl" gorm:"type:varchar(1024);comment:原文地址"`
|
|
ThumbMediaID *string `json:"thumbMediaId" gorm:"type:varchar(128);comment:缩略图的media_id"`
|
|
ThumbURL *string `json:"thumbUrl" gorm:"type:varchar(1024);comment:缩略图URL"`
|
|
ShowCover bool `json:"showCover" gorm:"default:true;comment:是否显示封面"`
|
|
NeedOpenComment bool `json:"needOpenComment" gorm:"default:false;comment:是否打开评论"`
|
|
OnlyFansCanComment bool `json:"onlyFansCanComment" gorm:"default:false;comment:是否粉丝才可评论"`
|
|
|
|
// 发布信息
|
|
PublishTime *time.Time `json:"publishTime" gorm:"comment:发布时间"`
|
|
PublishStatus string `json:"publishStatus" gorm:"type:varchar(32);default:'draft';comment:发布状态 draft草稿 published已发布"`
|
|
|
|
// 统计数据
|
|
ReadNum int `json:"readNum" gorm:"default:0;comment:阅读数"`
|
|
LikeNum int `json:"likeNum" gorm:"default:0;comment:点赞数"`
|
|
CommentNum int `json:"commentNum" gorm:"default:0;comment:评论数"`
|
|
ShareNum int `json:"shareNum" gorm:"default:0;comment:分享数"`
|
|
|
|
// 微信相关
|
|
WechatURL *string `json:"wechatUrl" gorm:"type:varchar(1024);comment:微信图文链接"`
|
|
WechatMsgID *string `json:"wechatMsgId" gorm:"type:varchar(128);comment:微信消息ID"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (MpNews) TableName() string {
|
|
return "mp_news"
|
|
}
|
|
|
|
// PublishStatus 发布状态常量
|
|
const (
|
|
NewsStatusDraft = "draft" // 草稿
|
|
NewsStatusPublished = "published" // 已发布
|
|
NewsStatusDeleted = "deleted" // 已删除
|
|
)
|
|
|
|
// IsDraft 是否为草稿状态
|
|
func (n *MpNews) IsDraft() bool {
|
|
return n.PublishStatus == NewsStatusDraft
|
|
}
|
|
|
|
// IsPublished 是否已发布
|
|
func (n *MpNews) IsPublished() bool {
|
|
return n.PublishStatus == NewsStatusPublished
|
|
}
|
|
|
|
// IsDeleted 是否已删除
|
|
func (n *MpNews) IsDeleted() bool {
|
|
return n.PublishStatus == NewsStatusDeleted
|
|
}
|
|
|
|
// GetReadCount 获取阅读数
|
|
func (n *MpNews) GetReadCount() int {
|
|
return n.ReadNum
|
|
}
|
|
|
|
// GetLikeCount 获取点赞数
|
|
func (n *MpNews) GetLikeCount() int {
|
|
return n.LikeNum
|
|
}
|
|
|
|
// GetCommentCount 获取评论数
|
|
func (n *MpNews) GetCommentCount() int {
|
|
return n.CommentNum
|
|
}
|
|
|
|
// GetShareCount 获取分享数
|
|
func (n *MpNews) GetShareCount() int {
|
|
return n.ShareNum
|
|
}
|
|
|
|
// GetTotalInteraction 获取总互动数
|
|
func (n *MpNews) GetTotalInteraction() int {
|
|
return n.ReadNum + n.LikeNum + n.CommentNum + n.ShareNum
|
|
}
|