Merge pull request 'history-order-list' (#3) from history-order-list into main
Reviewed-on: https://git.altru.id/Furtuna/furtuna-backend/pulls/3
This commit is contained in:
@@ -3,8 +3,10 @@ package orders
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/logger"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/entity"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
@@ -83,7 +85,7 @@ func (r *OrderRepository) Update(ctx context.Context, order *entity.Order) (*ent
|
||||
return order, nil
|
||||
}
|
||||
|
||||
func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.HistoryOrderSearch) (entity.HistoryOrderList, int, error) {
|
||||
func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.OrderSearch) (entity.HistoryOrderList, int, error) {
|
||||
var orders []*entity.HistoryOrderDB
|
||||
var total int64
|
||||
|
||||
@@ -128,3 +130,47 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Hi
|
||||
|
||||
return orders, int(total), nil
|
||||
}
|
||||
|
||||
func (r *OrderRepository) CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSoldDB, error) {
|
||||
today := time.Now().Format("2006-01-02")
|
||||
ticketCount := new(entity.TicketSoldDB)
|
||||
|
||||
query := r.db.Table("orders").
|
||||
Select("sum(items.qty) as count").
|
||||
Joins("left join order_items items on orders.id = items.order_id").
|
||||
Where("orders.status = ?", "PAID").
|
||||
Where("orders.created_at = ?", today)
|
||||
|
||||
if !req.IsAdmin {
|
||||
query = query.Where("orders.partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
if err := query.Scan(&ticketCount).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get count ticket", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ticketCount, nil
|
||||
}
|
||||
|
||||
func (r *OrderRepository) SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.OrderDB, error) {
|
||||
amount := new(entity.OrderDB)
|
||||
today := time.Now().Format("2006-01-02")
|
||||
|
||||
query := r.db.Table("orders").
|
||||
Select("sum(amount) as amount").
|
||||
Where("payment_type = ?", req.PaymentType).
|
||||
Where("date(created_at) = ?", today).
|
||||
Where("status = ?", "PAID")
|
||||
|
||||
if !req.IsAdmin {
|
||||
query = query.Where("orders.partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
if err := query.Scan(&amount).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get cash amount", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return amount, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/repository/branches"
|
||||
"furtuna-be/internal/repository/brevo"
|
||||
"furtuna-be/internal/repository/license"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"furtuna-be/internal/repository/trx"
|
||||
"furtuna-be/internal/repository/users"
|
||||
repository "furtuna-be/internal/repository/wallet"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -133,7 +135,9 @@ type Order interface {
|
||||
FindByID(ctx context.Context, id int64) (*entity.Order, error)
|
||||
Update(ctx context.Context, order *entity.Order) (*entity.Order, error)
|
||||
SetOrderStatus(ctx context.Context, db *gorm.DB, orderID int64, status string) error
|
||||
GetAllHystoryOrders(ctx context.Context, req entity.HistoryOrderSearch) (entity.HistoryOrderList, int, error)
|
||||
GetAllHystoryOrders(ctx context.Context, req entity.OrderSearch) (entity.HistoryOrderList, int, error)
|
||||
SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.OrderDB, error)
|
||||
CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSoldDB, error)
|
||||
}
|
||||
|
||||
type OSSRepository interface {
|
||||
@@ -157,6 +161,7 @@ type SiteRepository interface {
|
||||
GetByID(ctx context.Context, id int64) (*entity.SiteDB, error)
|
||||
GetAll(ctx context.Context, req entity.SiteSearch) (entity.SiteList, int, error)
|
||||
Delete(ctx context.Context, id int64) error
|
||||
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error)
|
||||
}
|
||||
|
||||
type TransactionManager interface {
|
||||
|
||||
@@ -3,6 +3,7 @@ package sites
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/logger"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/entity"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -129,3 +130,21 @@ func (r *SiteRepository) Delete(ctx context.Context, id int64) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *SiteRepository) Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error) {
|
||||
count := new(entity.SiteCountDB)
|
||||
|
||||
query := r.db.Table("sites").
|
||||
Select("count(*) as count")
|
||||
|
||||
if !req.IsAdmin {
|
||||
query = query.Where("partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
if err := query.Scan(&count).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get count sites", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user