feat: update parent category detail
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user