2023-10-08 15:59:42 +07:00
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Order struct {
|
2024-08-13 23:09:05 +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"`
|
|
|
|
|
Total float64 `gorm:"type:numeric;not null;column:total"`
|
|
|
|
|
Fee float64 `gorm:"type:numeric;not null;column:fee"`
|
|
|
|
|
SiteID *int64 `gorm:"type:numeric;not null;column:site_id"`
|
2024-08-21 22:27:05 +07:00
|
|
|
Site *Site `gorm:"foreignKey:SiteID;constraint:OnDelete:CASCADE;"`
|
2024-08-13 23:09:05 +07:00
|
|
|
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;"`
|
|
|
|
|
Payment Payment `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
|
|
|
|
User User `gorm:"foreignKey:CreatedBy;constraint:OnDelete:CASCADE;"`
|
|
|
|
|
Source string `gorm:"type:varchar;column:source"`
|
|
|
|
|
TicketStatus string `gorm:"type:varchar;column:ticket_status"`
|
|
|
|
|
VisitDate time.Time `gorm:"type:date;column:visit_date"`
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 16:47:33 +07:00
|
|
|
type OrderDB struct {
|
|
|
|
|
Order
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Order) ToOrderDB() *OrderDB {
|
|
|
|
|
return &OrderDB{
|
|
|
|
|
Order: *b,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *OrderDB) ToSumAmount() *Order {
|
|
|
|
|
return &Order{
|
|
|
|
|
Amount: e.Amount,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type OrderResponse struct {
|
|
|
|
|
Order *Order
|
|
|
|
|
Token string
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
2024-08-13 23:09:05 +07:00
|
|
|
type CheckinResponse struct {
|
|
|
|
|
Order *Order
|
|
|
|
|
Token string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CheckinExecute struct {
|
|
|
|
|
Order *Order
|
|
|
|
|
Token string
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 02:59:31 +07:00
|
|
|
type ExecuteOrderResponse struct {
|
|
|
|
|
Order *Order
|
2024-08-06 16:21:55 +07:00
|
|
|
QRCode string
|
2024-06-04 02:59:31 +07:00
|
|
|
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 {
|
2024-08-04 01:14:59 +07:00
|
|
|
Source string
|
2024-06-04 02:59:31 +07:00
|
|
|
CreatedBy int64
|
|
|
|
|
PartnerID int64 `json:"partner_id" validate:"required"`
|
|
|
|
|
PaymentMethod string `json:"payment_method" validate:"required"`
|
|
|
|
|
OrderItems []OrderItemRequest `json:"order_items" validate:"required,dive"`
|
2024-08-15 22:17:28 +07:00
|
|
|
VisitDate string `json:"visit_date"`
|
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"
|
2024-08-18 12:38:29 +07:00
|
|
|
o.TicketStatus = "USED"
|
2024-06-04 02:59:31 +07:00
|
|
|
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 {
|
2024-08-13 23:09:05 +07:00
|
|
|
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"`
|
|
|
|
|
VisitDate time.Time `gorm:"type:date;column:visit_date"`
|
|
|
|
|
TicketStatus string `gorm:"type:varchar;column:ticket_status"`
|
|
|
|
|
Source string `gorm:"type:numeric;column:source"`
|
2024-07-26 11:37:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HistoryOrderDB struct {
|
|
|
|
|
HistoryOrder
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-27 16:47:33 +07:00
|
|
|
type OrderSearch struct {
|
|
|
|
|
PartnerID *int64
|
2024-07-30 22:02:36 +07:00
|
|
|
SiteID *int64
|
2024-07-27 16:47:33 +07:00
|
|
|
IsAdmin bool
|
2024-08-04 01:14:59 +07:00
|
|
|
CreatedBy int64
|
2024-07-27 16:47:33 +07:00
|
|
|
PaymentType string
|
2024-07-30 22:02:36 +07:00
|
|
|
Status string
|
2024-07-27 16:47:33 +07:00
|
|
|
Limit int
|
|
|
|
|
Offset int
|
2024-07-30 22:02:36 +07:00
|
|
|
StartDate string
|
|
|
|
|
EndDate string
|
2024-08-02 14:41:41 +07:00
|
|
|
Period string
|
2024-08-04 01:14:59 +07:00
|
|
|
IsCustomer bool
|
2024-08-13 23:09:05 +07:00
|
|
|
Source string
|
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{
|
2024-08-13 23:09:05 +07:00
|
|
|
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,
|
|
|
|
|
VisitDate: e.VisitDate,
|
2024-08-10 23:21:01 +07:00
|
|
|
TicketStatus: e.TicketStatus,
|
2024-08-13 23:09:05 +07:00
|
|
|
Source: e.Source,
|
2024-07-26 11:37:22 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *HistoryOrderList) ToHistoryOrderList() []*HistoryOrder {
|
|
|
|
|
var HistoryOrders []*HistoryOrder
|
|
|
|
|
for _, historyOrder := range *b {
|
2024-08-18 12:38:29 +07:00
|
|
|
if historyOrder.Status != "NEW" && historyOrder.Tickets != nil {
|
|
|
|
|
HistoryOrders = append(HistoryOrders, historyOrder.ToHistoryOrder())
|
|
|
|
|
}
|
2024-07-26 11:37:22 +07:00
|
|
|
}
|
|
|
|
|
return HistoryOrders
|
|
|
|
|
}
|
2024-07-27 16:47:33 +07:00
|
|
|
|
|
|
|
|
type TicketSold struct {
|
|
|
|
|
Count int64 `gorm:"type:int;column:count"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TicketSoldDB struct {
|
|
|
|
|
TicketSold
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *TicketSold) ToTicketSoldDB() *TicketSoldDB {
|
|
|
|
|
return &TicketSoldDB{
|
|
|
|
|
TicketSold: *b,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *TicketSoldDB) ToTicketSold() *TicketSold {
|
|
|
|
|
return &TicketSold{
|
|
|
|
|
Count: e.Count,
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-02 02:27:57 +07:00
|
|
|
|
|
|
|
|
type ProductDailySales struct {
|
2024-08-02 14:41:41 +07:00
|
|
|
Day time.Time
|
|
|
|
|
SiteID int64
|
|
|
|
|
SiteName string
|
|
|
|
|
PaymentType string
|
|
|
|
|
Total float64
|
2024-08-02 02:27:57 +07:00
|
|
|
}
|
2024-08-02 15:16:28 +07:00
|
|
|
|
|
|
|
|
type PaymentTypeDistribution struct {
|
|
|
|
|
PaymentType string
|
|
|
|
|
Count int
|
|
|
|
|
}
|
2024-08-21 15:48:50 +07:00
|
|
|
|
|
|
|
|
type OrderPrintDetail struct {
|
|
|
|
|
ID int64 `gorm:"column:id"`
|
2024-08-21 15:51:40 +07:00
|
|
|
Logo string `gorm:"logo"`
|
2024-08-21 15:48:50 +07:00
|
|
|
PartnerName string `gorm:"column:partner_name"`
|
2024-08-24 14:25:58 +07:00
|
|
|
SiteName string `gorm:"column:site_name"`
|
2024-08-21 15:48:50 +07:00
|
|
|
OrderID string `gorm:"column:order_id"`
|
|
|
|
|
VisitDate time.Time `gorm:"column:visit_date"`
|
|
|
|
|
PaymentType string `gorm:"column:payment_type"`
|
|
|
|
|
OrderItems []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
|
|
|
|
Source string `gorm:"column:source"`
|
|
|
|
|
TicketStatus string `gorm:"column:ticket_status"`
|
|
|
|
|
Total float64 `gorm:"column:total"`
|
|
|
|
|
Fee float64 `gorm:"column:fee"`
|
|
|
|
|
}
|