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.

74 lines
2.2 KiB
Go

package payment
import "time"
// PaymentType 支付类型
type PaymentType int
const (
PaymentTypeWechat PaymentType = iota + 1 // 微信支付
PaymentTypeAlipay // 支付宝支付
)
// PaymentStatus 支付状态
type PaymentStatus int
const (
PaymentStatusPending PaymentStatus = iota + 1 // 待支付
PaymentStatusSuccess // 支付成功
PaymentStatusFailed // 支付失败
PaymentStatusRefunded // 已退款
)
// Payment 支付订单实体
type Payment struct {
ID uint64 `xorm:"pk autoincr 'id'" ` // 支付ID
OrderNo string `xorm:"unique"` // 订单编号
TransactionID string // 第三方交易号
UserID uint64 // 用户ID
TargetID uint64 // 商品ID
Type PaymentType // 支付类型
Amount int64 // 支付金额
Status PaymentStatus // 支付状态
Description string `xorm:"varchar(500)"` // 支付描述
NotifyData string `xorm:"varchar(1000) notnull "` // 支付回调数据
CreatedAt time.Time `xorm:"creaed" ` // 创建时间
UpdatedAt time.Time `xorm:"updated" ` // 更新时间
DeletedAt *time.Time `xorm:"deleted"` // 删除时间
}
// TableName 指定表名
// IsValid 检查支付订单是否有效
func (p *Payment) IsValid() bool {
return p.ID > 0 && p.OrderNo != "" && p.UserID > 0 && p.TargetID > 0
}
// IsSuccess 检查支付是否成功
func (p *Payment) IsSuccess() bool {
return p.Status == PaymentStatusSuccess
}
// IsFailed 检查支付是否失败
func (p *Payment) IsFailed() bool {
return p.Status == PaymentStatusFailed
}
// IsRefunded 检查是否已退款
func (p *Payment) IsRefunded() bool {
return p.Status == PaymentStatusRefunded
}
// NewPayment 创建支付订单
func NewPayment(orderNo string, userID, targetID uint64, paymentType PaymentType, amount int64, description string) *Payment {
return &Payment{
OrderNo: orderNo,
UserID: userID,
TargetID: targetID,
Type: paymentType,
Amount: amount,
Status: PaymentStatusPending,
Description: description,
}
}