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.

59 lines
1.2 KiB
Go

package model
import (
"encoding/json"
"time"
)
const PaymentStatusSuccess = 1
const PaymentStatusFailed = 2
const PaymentStatusWait = 0
type Payment struct {
ID int
PaymentNo string
PayOrderID string
UserID int
Amount float64
Token string
User User `gorm:"foreignKey:UserID;references:ID"`
PayType string
OpenID string
ErrorMessage string
PayerCardNo string
PayerAccountName string
Status int
CreatedAt time.Time
UpdatedAt time.Time
}
func (Payment) TableName() string {
return "payments"
}
func (p Payment) MarshalJSON() ([]byte, error) {
type Alias Payment
return json.Marshal(&struct {
CreatedAt string
UpdatedAt string
*Alias
}{
CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"),
Alias: (*Alias)(&p),
})
}
func (p Payment) GetStatusText() string {
statusText := ""
switch p.Status {
case PaymentStatusSuccess:
statusText = "支付成功"
case PaymentStatusFailed:
statusText = "支付失败"
case PaymentStatusWait:
statusText = "待支付"
}
return statusText
}