|
|
|
|
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 `xorm:"pk autoincr 'id'" ` // 支付ID
|
|
|
|
|
OrderNo string `xorm:"unique"` // 订单编号
|
|
|
|
|
UserID uint64 `json:"userId"` // 用户ID
|
|
|
|
|
TargetID uint64 `json:"targetId"` // 商品ID(文章ID或专栏ID)
|
|
|
|
|
Type OrderType `json:"type"` // 订单类型(文章/专栏)
|
|
|
|
|
Amount int64 `json:"amount"` // 订单金额(分)
|
|
|
|
|
Duration int `json:"duration"` // 购买时长(月)
|
|
|
|
|
Coupon uint64 //优惠券
|
|
|
|
|
Status OrderStatus `json:"status"` // 订单状态
|
|
|
|
|
Description string `json:"description"` // 商品描述
|
|
|
|
|
CreatedAt time.Time `xorm:"creaed" ` // 创建时间
|
|
|
|
|
UpdatedAt time.Time `xorm:"updated" ` // 更新时间
|
|
|
|
|
DeletedAt *time.Time `xorm:"deleted"` // 删除时间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|