feat: update parent category detail

This commit is contained in:
efrilm
2026-10-03 00:15:43 +07:00
parent fbe7e97dc7
commit b59b7b4ddd
4 changed files with 20 additions and 0 deletions
+11
View File
@@ -469,7 +469,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co
// Bucket the product rows by the category they belong to
productsByCategory := make(map[uuid.UUID][]models.ParentCategoryAnalyticsProductData)
productRowsByCategory := make(map[uuid.UUID][]*entities.ProductAnalytics)
for _, product := range detail.Products {
productRowsByCategory[product.CategoryID] = append(productRowsByCategory[product.CategoryID], product)
productsByCategory[product.CategoryID] = append(productsByCategory[product.CategoryID], models.ParentCategoryAnalyticsProductData{
ProductID: product.ProductID,
ProductName: product.ProductName,
@@ -489,6 +491,12 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co
})
}
// Sub-categories take the owner fee of the parent category they sit under
var ownerFeePercent float64
if detail.Summary != nil {
ownerFeePercent = detail.Summary.OwnerFeePercent
}
categories := make([]models.ParentCategoryAnalyticsDetailData, 0, len(detail.Categories))
for _, category := range detail.Categories {
products := productsByCategory[category.CategoryID]
@@ -499,6 +507,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co
categories = append(categories, models.ParentCategoryAnalyticsDetailData{
CategoryID: category.CategoryID,
CategoryName: category.CategoryName,
OwnerFeePercent: ownerFeePercent,
SDL: category.TotalRevenue * ownerFeePercent / 100,
TopProduct: topProductByRevenue(productRowsByCategory[category.CategoryID]),
TotalRevenue: category.TotalRevenue,
TotalQuantity: category.TotalQuantity,
ProductCount: category.ProductCount,