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.

35 lines
702 B
Go

11 months ago
package model
import (
7 months ago
"encoding/json"
11 months ago
"time"
)
type Order struct {
7 months ago
ID int
7 months ago
OrderNo string
UserID int
Amount float64
7 months ago
User User `gorm:"foreignKey:UserID;references:ID"`
7 months ago
OrderProducts []OrderProduct `gorm:"foreignKey:OrderNo;references:OrderNo"`
CreatedAt time.Time
UpdatedAt time.Time
11 months ago
}
func (Order) TableName() string {
8 months ago
return "orders"
11 months ago
}
7 months ago
func (o Order) MarshalJSON() ([]byte, error) {
type Alias Order
return json.Marshal(&struct {
CreatedAt string
UpdatedAt string
*Alias
}{
CreatedAt: o.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: o.UpdatedAt.Format("2006-01-02 15:04:05"),
Alias: (*Alias)(&o),
})
}