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.

49 lines
1.4 KiB
Go

1 month ago
package purchase
import "time"
// ContentType 内容类型
type ContentType int8
const (
ContentTypeArticle ContentType = 1 // 文章
ContentTypeColumn ContentType = 2 // 专栏
)
//ContentSource 内容来源
type ContentSource int8
const (
ContentSourceBuy ContentSource = 1 //购买
ContentSourceGift ContentSource = 1 //购买
)
// Purchase 内容购买记录
type Purchase struct {
Id uint64 `xorm:"pk autoincr 'id'" json:"id"`
UserId uint64 `xorm:"notnull 'user_id'" json:"userId"`
ContentId uint64 `xorm:"notnull 'content_id'" json:"contentId"`
ContentType ContentType `xorm:"tinyint(1) notnull 'content_type'" `
Price float64 `xorm:"decimal(10,2) notnull 'price'" json:"price"`
ContentSource ContentSource `xorm:"tinyint(1) notnull 'content_source'" `
Status int8 `xorm:"tinyint(1) default 1 'status'" json:"status"`
CreatedAt time.Time `xorm:"datetime created 'created_at'" json:"createdAt"`
UpdatedAt time.Time `xorm:"datetime updated 'updated_at'" json:"updatedAt"`
}
// IsValid 检查购买记录是否有效
func (p *Purchase) IsValid() bool {
return p.Status == 1
}
// NewPurchase 创建购买记录
func NewPurchase(userId, contentId uint64, contentType ContentType, price float64) *Purchase {
return &Purchase{
UserId: userId,
ContentId: contentId,
ContentType: contentType,
Price: price,
Status: 1,
}
}