film/model/orders.go

68 lines
1.2 KiB
Go
Raw Normal View History

2023-04-06 13:46:19 +08:00
package model
import (
"gorm.io/gorm"
"time"
)
var (
tableNameOrder = "orders"
)
type Order struct {
Id int64
OrderId string
StartTime string
StartDate string
TotalPrice int64
PayPrice int64
2023-04-08 20:33:48 +08:00
MinPrice int64
MaxPrice int64
2023-04-06 13:46:19 +08:00
MaoyanPrice int64
SeatNum int
Seats string
ShowTime int64
PayTime int64
CityName string
ProvinceName string
Ting string
CinemaName string
MovieName string
Address string
2023-04-07 23:51:09 +08:00
Count int
IsSeat int
LoverSeat int
2023-04-06 13:57:39 +08:00
CreateDate string
2023-04-06 13:46:19 +08:00
CreateTime int64
UpdateTime int64
}
func AddOrder(o *Order) (int64, error) {
o.CreateTime = time.Now().Unix()
2023-04-06 13:57:39 +08:00
o.CreateDate = time.Now().Format("2006-01-02")
2023-04-06 13:46:19 +08:00
res := db.Table(tableNameOrder).Create(o)
return o.Id, res.Error
}
func GetOrder(id int64) (*Order, error) {
var u Order
tx := db.Table(tableNameOrder)
tx = tx.Where("id = ?", id)
res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound {
return nil, nil
}
if res.Error != nil {
return nil, res.Error
}
return &u, nil
}
func UpdateOrder(o *Order) error {
o.UpdateTime = time.Now().Unix()
tx := db.Table(tableNameOrder)
res := tx.Save(o)
return res.Error
}