2023-10-08 15:59:42 +07:00
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Order struct {
|
2024-06-04 02:59:31 +07:00
|
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
|
|
|
RefID string `gorm:"type:varchar;column:ref_id"`
|
|
|
|
|
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
|
|
|
|
Status string `gorm:"type:varchar;column:status"`
|
|
|
|
|
Amount float64 `gorm:"type:numeric;not null;column:amount"`
|
|
|
|
|
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
|
|
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
|
|
|
|
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
|
|
|
|
PaymentType string `gorm:"type:varchar;column:payment_type"`
|
|
|
|
|
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
|
|
|
|
OrderItems []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type OrderResponse struct {
|
|
|
|
|
Order *Order
|
|
|
|
|
Token string
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type ExecuteOrderResponse struct {
|
|
|
|
|
Order *Order
|
|
|
|
|
PaymentToken string
|
|
|
|
|
RedirectURL string
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
func (Order) TableName() string {
|
2023-10-08 15:59:42 +07:00
|
|
|
return "orders"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OrderItem struct {
|
2024-06-04 02:59:31 +07:00
|
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:order_item_id"`
|
|
|
|
|
OrderID int64 `gorm:"type:int;column:order_id"`
|
|
|
|
|
ItemID int64 `gorm:"type:int;column:item_id"`
|
|
|
|
|
ItemType string `gorm:"type:varchar;column:item_type"`
|
|
|
|
|
Price float64 `gorm:"type:numeric;not null;column:price"`
|
|
|
|
|
Quantity int64 `gorm:"type:int;column:qty"`
|
|
|
|
|
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
|
|
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
|
|
|
|
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
|
|
|
|
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
2024-06-05 00:24:53 +07:00
|
|
|
Product *Product `gorm:"foreignKey:ItemID;references:ID"`
|
2024-06-04 02:59:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (OrderItem) TableName() string {
|
|
|
|
|
return "order_items"
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type OrderRequest struct {
|
|
|
|
|
CreatedBy int64
|
|
|
|
|
PartnerID int64 `json:"partner_id" validate:"required"`
|
|
|
|
|
PaymentMethod string `json:"payment_method" validate:"required"`
|
|
|
|
|
OrderItems []OrderItemRequest `json:"order_items" validate:"required,dive"`
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type OrderItemRequest struct {
|
|
|
|
|
ProductID int64 `json:"product_id" validate:"required"`
|
|
|
|
|
Quantity int64 `json:"quantity" validate:"required"`
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type OrderExecuteRequest struct {
|
|
|
|
|
CreatedBy int64
|
|
|
|
|
PartnerID int64
|
|
|
|
|
Token string
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
func (o *Order) SetExecutePaymentStatus() {
|
|
|
|
|
if o.PaymentType == "CASH" {
|
|
|
|
|
o.Status = "PAID"
|
|
|
|
|
return
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
2024-06-04 02:59:31 +07:00
|
|
|
o.Status = "PENDING"
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
2024-06-05 00:24:53 +07:00
|
|
|
|
|
|
|
|
type CallbackRequest struct {
|
|
|
|
|
TransactionStatus string `json:"transaction_status"`
|
|
|
|
|
TransactionID string `json:"transaction_id"`
|
|
|
|
|
}
|
2024-07-26 11:37:22 +07:00
|
|
|
|
|
|
|
|
type HistoryOrder struct {
|
|
|
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
|
|
|
Employee string `gorm:"type:varchar;column:employee"`
|
|
|
|
|
Site string `gorm:"type:varchar;column:site"`
|
|
|
|
|
Timestamp time.Time `gorm:"autoCreateTime;column:timestamp"`
|
|
|
|
|
BookingTime time.Time `gorm:"autoCreateTime;column:booking_time"`
|
|
|
|
|
Tickets []string `gorm:"-"`
|
|
|
|
|
RawTickets string `gorm:"type:text;column:tickets"`
|
|
|
|
|
PaymentType string `gorm:"type:varchar;column:payment_type"`
|
|
|
|
|
Status string `gorm:"type:varchar;column:status"`
|
|
|
|
|
Amount float64 `gorm:"type:numeric;column:amount"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HistoryOrderDB struct {
|
|
|
|
|
HistoryOrder
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HistoryOrderSearch struct {
|
2024-07-26 22:32:24 +07:00
|
|
|
PartnerID *int64
|
|
|
|
|
IsAdmin bool
|
|
|
|
|
Limit int
|
|
|
|
|
Offset int
|
2024-07-26 11:37:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HistoryOrderList []*HistoryOrderDB
|
|
|
|
|
|
|
|
|
|
func (b *HistoryOrder) ToHistoryOrderDB() *HistoryOrderDB {
|
|
|
|
|
return &HistoryOrderDB{
|
|
|
|
|
HistoryOrder: *b,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *HistoryOrderDB) ToHistoryOrder() *HistoryOrder {
|
|
|
|
|
return &HistoryOrder{
|
|
|
|
|
ID: e.ID,
|
|
|
|
|
Employee: e.Employee,
|
|
|
|
|
Site: e.Site,
|
|
|
|
|
Timestamp: e.Timestamp,
|
|
|
|
|
BookingTime: e.BookingTime,
|
|
|
|
|
Tickets: e.Tickets,
|
|
|
|
|
RawTickets: e.RawTickets,
|
|
|
|
|
PaymentType: e.PaymentType,
|
|
|
|
|
Status: e.Status,
|
|
|
|
|
Amount: e.Amount,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *HistoryOrderList) ToHistoryOrderList() []*HistoryOrder {
|
|
|
|
|
var HistoryOrders []*HistoryOrder
|
|
|
|
|
for _, historyOrder := range *b {
|
|
|
|
|
HistoryOrders = append(HistoryOrders, historyOrder.ToHistoryOrder())
|
|
|
|
|
}
|
|
|
|
|
return HistoryOrders
|
|
|
|
|
}
|