add order and payment
This commit is contained in:
@@ -10,3 +10,9 @@ type JWTAuthClaims struct {
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
type JWTOrderClaims struct {
|
||||
PartnerID int64 `json:"id"`
|
||||
OrderID int64 `json:"order_id"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package entity
|
||||
|
||||
type MidtransResponse struct {
|
||||
Token string
|
||||
RedirectURL string
|
||||
}
|
||||
|
||||
type MidtransRequest struct {
|
||||
PaymentReferenceID string
|
||||
TotalAmount int64
|
||||
OrderItems []OrderItem
|
||||
}
|
||||
+53
-142
@@ -1,166 +1,77 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/constants/order"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
ID int64
|
||||
BranchID int64
|
||||
BranchName string
|
||||
Status order.OrderStatus
|
||||
Amount float64
|
||||
CustomerName string `gorm:"column:customer_name" json:"customer_name"`
|
||||
CustomerPhone string `gorm:"column:customer_phone" json:"customer_phone"`
|
||||
Pax int `gorm:"column:pax" json:"pax"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
CreatedBy int64
|
||||
UpdatedBy int64
|
||||
Transaction Transaction
|
||||
OrderItem []OrderItem
|
||||
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;"`
|
||||
}
|
||||
|
||||
type OrderSearch struct {
|
||||
Search string
|
||||
StatusActive order.OrderSearchStatus
|
||||
Status order.OrderStatus
|
||||
BranchID int64
|
||||
Limit int
|
||||
Offset int
|
||||
type OrderResponse struct {
|
||||
Order *Order
|
||||
Token string
|
||||
}
|
||||
|
||||
type OrderTotalRevenueSearch struct {
|
||||
Year int
|
||||
Month int
|
||||
BranchID int64
|
||||
DateStart *time.Time
|
||||
DateEnd *time.Time
|
||||
type ExecuteOrderResponse struct {
|
||||
Order *Order
|
||||
PaymentToken string
|
||||
RedirectURL string
|
||||
}
|
||||
|
||||
type OrderYearlyRevenueList []OrderYearlyRevenue
|
||||
type OrderYearlyRevenue struct {
|
||||
ItemType string `gorm:"column:item_type"`
|
||||
Month int `gorm:"column:month_number"`
|
||||
Amount float64 `gorm:"column:total_amount"`
|
||||
}
|
||||
|
||||
type OrderBranchRevenueSearch struct {
|
||||
DateStart *time.Time
|
||||
DateEnd *time.Time
|
||||
}
|
||||
|
||||
type OrderBranchRevenueList []OrderBranchRevenue
|
||||
type OrderBranchRevenue struct {
|
||||
BranchID string `gorm:"column:branch_id"`
|
||||
BranchName string `gorm:"column:name"`
|
||||
BranchLocation string `gorm:"column:location"`
|
||||
TotalTransaction int `gorm:"column:total_trans"`
|
||||
TotalAmount float64 `gorm:"column:total_amount"`
|
||||
}
|
||||
|
||||
type OrderList []*OrderDB
|
||||
|
||||
type OrderDB struct {
|
||||
Order
|
||||
}
|
||||
|
||||
func (b *Order) ToOrderDB() *OrderDB {
|
||||
var amount float64
|
||||
for _, i := range b.OrderItem {
|
||||
amount = amount + (i.Price * float64(i.Qty))
|
||||
}
|
||||
b.Amount = amount
|
||||
b.Transaction.Amount = amount
|
||||
|
||||
return &OrderDB{
|
||||
Order: *b,
|
||||
}
|
||||
}
|
||||
|
||||
func (OrderDB) TableName() string {
|
||||
func (Order) TableName() string {
|
||||
return "orders"
|
||||
}
|
||||
|
||||
func (e *OrderDB) ToOrder() *Order {
|
||||
return &Order{
|
||||
ID: e.ID,
|
||||
Status: e.Status,
|
||||
BranchID: e.BranchID,
|
||||
BranchName: e.BranchName,
|
||||
Amount: e.Amount,
|
||||
CustomerName: e.CustomerName,
|
||||
CustomerPhone: e.CustomerPhone,
|
||||
Pax: e.Pax,
|
||||
Transaction: e.Transaction,
|
||||
OrderItem: e.OrderItem,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *OrderList) ToOrderList() []*Order {
|
||||
var Orders []*Order
|
||||
for _, order := range *b {
|
||||
Orders = append(Orders, order.ToOrder())
|
||||
}
|
||||
return Orders
|
||||
}
|
||||
|
||||
func (o *OrderDB) ToUpdatedOrder(updatedby int64, req Order) {
|
||||
o.UpdatedBy = updatedby
|
||||
|
||||
if req.Amount > 0 {
|
||||
o.Amount = req.Amount
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
o.Status = req.Status
|
||||
}
|
||||
}
|
||||
|
||||
type OrderItem struct {
|
||||
OrderItemID int64
|
||||
OrderID int64
|
||||
ItemID int64
|
||||
ItemType order.ItemType
|
||||
ItemName string
|
||||
Price float64
|
||||
Qty int64
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
CreatedBy int64
|
||||
UpdatedBy int64
|
||||
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"`
|
||||
}
|
||||
|
||||
type OrderItemDB struct {
|
||||
OrderItem
|
||||
}
|
||||
|
||||
func (b *OrderItem) ToOrderItemDB() *OrderItemDB {
|
||||
return &OrderItemDB{
|
||||
OrderItem: *b,
|
||||
}
|
||||
}
|
||||
|
||||
func (OrderItemDB) TableName() string {
|
||||
func (OrderItem) TableName() string {
|
||||
return "order_items"
|
||||
}
|
||||
|
||||
func (e *OrderItemDB) ToOrderItem() *OrderItem {
|
||||
return &OrderItem{
|
||||
OrderItemID: e.OrderItemID,
|
||||
OrderID: e.OrderID,
|
||||
ItemID: e.ItemID,
|
||||
ItemType: e.ItemType,
|
||||
Price: e.Price,
|
||||
Qty: e.Qty,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
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"`
|
||||
}
|
||||
|
||||
type OrderItemRequest struct {
|
||||
ProductID int64 `json:"product_id" validate:"required"`
|
||||
Quantity int64 `json:"quantity" validate:"required"`
|
||||
}
|
||||
|
||||
type OrderExecuteRequest struct {
|
||||
CreatedBy int64
|
||||
PartnerID int64
|
||||
Token string
|
||||
}
|
||||
|
||||
func (o *Order) SetExecutePaymentStatus() {
|
||||
if o.PaymentType == "CASH" {
|
||||
o.Status = "PAID"
|
||||
return
|
||||
}
|
||||
o.Status = "PENDING"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/datatypes"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primaryKey;column:id"`
|
||||
PartnerID string `gorm:"type:varchar;not null;column:partner_id"`
|
||||
OrderID string `gorm:"type:varchar;not null;column:order_id"`
|
||||
ReferenceID string `gorm:"type:varchar;not null;column:reference_id"`
|
||||
Channel string `gorm:"type:varchar;not null;column:channel"`
|
||||
PaymentType string `gorm:"type:varchar;not null;column:payment_type"`
|
||||
Amount float64 `gorm:"type:numeric;not null;column:amount"`
|
||||
State string `gorm:"type:varchar;not null;column:state"`
|
||||
RequestMetadata datatypes.JSON `gorm:"type:json;not null;column:request_metadata"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
FinishedAt time.Time `gorm:"column:finished_at"`
|
||||
}
|
||||
|
||||
func (Payment) TableName() string {
|
||||
return "payments"
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Transaction struct {
|
||||
ID int64
|
||||
BranchID int64
|
||||
PartnerID int64
|
||||
Status transaction.PaymentStatus
|
||||
Amount float64
|
||||
OrderID int64
|
||||
|
||||
Reference in New Issue
Block a user