This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
)
|
||||
|
||||
// MpDraft 微信公众号草稿表
|
||||
type MpDraft 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:图文消息内容"`
|
||||
ContentSourceUrl *string `json:"contentSourceUrl" 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"`
|
||||
ShowCoverPic int `json:"showCoverPic" gorm:"default:1;comment:是否显示封面 0不显示 1显示"`
|
||||
NeedOpenComment int `json:"needOpenComment" gorm:"default:0;comment:是否打开评论 0不打开 1打开"`
|
||||
OnlyFansCanComment int `json:"onlyFansCanComment" gorm:"default:0;comment:是否粉丝才可评论 0所有人 1粉丝"`
|
||||
|
||||
// 草稿状态
|
||||
Status string `json:"status" gorm:"type:varchar(32);default:'draft';comment:状态 draft草稿 published已发布"`
|
||||
UpdateTime *time.Time `json:"updateTime" gorm:"comment:更新时间"`
|
||||
|
||||
// 微信相关
|
||||
WechatMediaID *string `json:"wechatMediaId" gorm:"type:varchar(128);comment:微信草稿media_id"`
|
||||
WechatCreateTime *time.Time `json:"wechatCreateTime" gorm:"comment:微信创建时间"`
|
||||
WechatUpdateTime *time.Time `json:"wechatUpdateTime" gorm:"comment:微信更新时间"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (MpDraft) TableName() string {
|
||||
return "mp_draft"
|
||||
}
|
||||
|
||||
// DraftStatus 草稿状态常量
|
||||
const (
|
||||
DraftStatusDraft = "draft" // 草稿
|
||||
DraftStatusPublished = "published" // 已发布
|
||||
DraftStatusDeleted = "deleted" // 已删除
|
||||
)
|
||||
|
||||
// IsDraft 是否为草稿状态
|
||||
func (d *MpDraft) IsDraft() bool {
|
||||
return d.Status == DraftStatusDraft
|
||||
}
|
||||
|
||||
// IsPublished 是否已发布
|
||||
func (d *MpDraft) IsPublished() bool {
|
||||
return d.Status == DraftStatusPublished
|
||||
}
|
||||
|
||||
// IsDeleted 是否已删除
|
||||
func (d *MpDraft) IsDeleted() bool {
|
||||
return d.Status == DraftStatusDeleted
|
||||
}
|
||||
|
||||
// GetDisplayTitle 获取显示标题
|
||||
func (d *MpDraft) GetDisplayTitle() string {
|
||||
if d.Title == "" {
|
||||
return "无标题"
|
||||
}
|
||||
return d.Title
|
||||
}
|
||||
|
||||
// GetDisplayAuthor 获取显示作者
|
||||
func (d *MpDraft) GetDisplayAuthor() string {
|
||||
if d.Author == nil || *d.Author == "" {
|
||||
return "未知作者"
|
||||
}
|
||||
return *d.Author
|
||||
}
|
||||
|
||||
// HasThumb 是否有缩略图
|
||||
func (d *MpDraft) HasThumb() bool {
|
||||
return d.ThumbMediaID != nil && *d.ThumbMediaID != ""
|
||||
}
|
||||
|
||||
// IsShowCover 是否显示封面
|
||||
func (d *MpDraft) IsShowCover() bool {
|
||||
return d.ShowCoverPic == 1
|
||||
}
|
||||
|
||||
// IsOpenComment 是否打开评论
|
||||
func (d *MpDraft) IsOpenComment() bool {
|
||||
return d.NeedOpenComment == 1
|
||||
}
|
||||
|
||||
// IsOnlyFansComment 是否仅粉丝可评论
|
||||
func (d *MpDraft) IsOnlyFansComment() bool {
|
||||
return d.OnlyFansCanComment == 1
|
||||
}
|
||||
Reference in New Issue
Block a user