You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package column
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
|
|
// Column 专栏实体
|
|
|
|
|
type Column struct {
|
|
|
|
|
ID uint64 `xorm:"pk autoincr 'id'"`
|
|
|
|
|
Title string `xorm:"varchar(100) notnull 'title'"` // 专栏标题
|
|
|
|
|
Brief string `xorm:"varchar(500) 'brief'"` // 专栏简介
|
|
|
|
|
Cover string `xorm:"varchar(255) 'cover'"` // 封面图片
|
|
|
|
|
AuthorID uint64 `xorm:"notnull 'author_id'"` // 作者ID
|
|
|
|
|
Status int8 `xorm:"tinyint(1) notnull default 1 'status'"` // 状态:1-正常 2-下架
|
|
|
|
|
ArticleNum int `xorm:"int default 0 'article_num'"` // 文章数量
|
|
|
|
|
FollowNum int `xorm:"int default 0 'follow_num'"` // 关注人数
|
|
|
|
|
PurchaseNum int `xorm:"int default 0 'purchase_num'"` // 购买人数
|
|
|
|
|
CreatedAt time.Time `xorm:"created 'created_at'"`
|
|
|
|
|
UpdatedAt time.Time `xorm:"updated 'updated_at'"`
|
|
|
|
|
DeletedAt *time.Time `xorm:"deleted 'deleted_at'"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewColumn 创建专栏
|
|
|
|
|
func NewColumn(title string, brief string, cover string, authorID uint64) *Column {
|
|
|
|
|
return &Column{
|
|
|
|
|
Title: title,
|
|
|
|
|
Brief: brief,
|
|
|
|
|
Cover: cover,
|
|
|
|
|
AuthorID: authorID,
|
|
|
|
|
Status: 1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsValid 检查专栏是否有效
|
|
|
|
|
func (c *Column) IsValid() bool {
|
|
|
|
|
return c.Status == 1 && c.DeletedAt == nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddArticle 增加文章数量
|
|
|
|
|
func (c *Column) AddArticle() {
|
|
|
|
|
c.ArticleNum++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoveArticle 减少文章数量
|
|
|
|
|
func (c *Column) RemoveArticle() {
|
|
|
|
|
if c.ArticleNum > 0 {
|
|
|
|
|
c.ArticleNum--
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddFollow 增加关注人数
|
|
|
|
|
func (c *Column) AddFollow() {
|
|
|
|
|
c.FollowNum++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoveFollow 减少关注人数
|
|
|
|
|
func (c *Column) RemoveFollow() {
|
|
|
|
|
if c.FollowNum > 0 {
|
|
|
|
|
c.FollowNum--
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddPurchase 增加购买人数
|
|
|
|
|
func (c *Column) AddPurchase() {
|
|
|
|
|
c.PurchaseNum++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemovePurchase 减少购买人数
|
|
|
|
|
func (c *Column) RemovePurchase() {
|
|
|
|
|
if c.PurchaseNum > 0 {
|
|
|
|
|
c.PurchaseNum--
|
|
|
|
|
}
|
|
|
|
|
}
|