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.

37 lines
681 B
Go

package model
import (
"encoding/json"
"time"
)
type OrderProduct struct {
ID uint
OrderNo string
UserID int
ProductID int
Num int
Price float64
Amount float64
Order *Order `gorm:"foreignKey:OrderNo;references:OrderNo"`
CreatedAt time.Time
UpdatedAt time.Time
}
func (OrderProduct) TableName() string {
return "order_products"
}
func (p OrderProduct) MarshalJSON() ([]byte, error) {
type Alias OrderProduct
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),
})
}