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.

60 lines
2.0 KiB
Go

package order
import "time"
// OrderType 订单类型
type OrderType int
const (
OrderTypeArticle OrderType = iota + 1 // 文章订单
OrderTypeColumn // 专栏订单
)
// OrderStatus 订单状态
type OrderStatus int
const (
OrderStatusPending OrderStatus = iota + 1 // 待支付
OrderStatusPaid // 已支付
OrderStatusCanceled // 已取消
OrderStatusRefunded // 已退款
)
// Order 订单实体
type Order struct {
ID uint64 `gorm:"primarykey" json:"id"` // 订单ID
OrderNo string `gorm:"uniqueIndex" json:"orderNo"` // 订单编号
UserID uint64 `json:"userId"` // 用户ID
TargetID uint64 `json:"targetId"` // 商品ID文章ID或专栏ID
Type OrderType `json:"type"` // 订单类型(文章/专栏)
Amount int64 `json:"amount"` // 订单金额(分)
Duration int `json:"duration"` // 购买时长(月)
Status OrderStatus `json:"status"` // 订单状态
Description string `json:"description"` // 商品描述
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
DeletedAt *time.Time `gorm:"index" json:"deletedAt"` // 删除时间
}
// TableName 指定表名
// IsValid 检查订单是否有效
func (o *Order) IsValid() bool {
return o.ID > 0 && o.OrderNo != "" && o.UserID > 0 && o.TargetID > 0
}
// IsPaid 检查订单是否已支付
func (o *Order) IsPaid() bool {
return o.Status == OrderStatusPaid
}
// IsCanceled 检查订单是否已取消
func (o *Order) IsCanceled() bool {
return o.Status == OrderStatusCanceled
}
// IsRefunded 检查订单是否已退款
func (o *Order) IsRefunded() bool {
return o.Status == OrderStatusRefunded
}