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

7 months ago
package model
import (
"encoding/json"
"time"
)
7 months ago
const PaymentStatusSuccess = 1
const PaymentStatusFailed = 2
const PaymentStatusWait = 0
7 months ago
type Payment struct {
7 months ago
ID int
PaymentNo string
6 months ago
PayOrderID string
7 months ago
UserID int
Amount float64
6 months ago
Token string
7 months ago
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
7 months ago
}
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),
})
}
7 months ago
func (p Payment) GetStatusText() string {
statusText := ""
switch p.Status {
case PaymentStatusSuccess:
statusText = "支付成功"
case PaymentStatusFailed:
statusText = "支付失败"
case PaymentStatusWait:
statusText = "待支付"
}
return statusText
}