diff --git a/app/service/AdsInsightService.php b/app/service/AdsInsightService.php index c8dedfc..8d26de5 100644 --- a/app/service/AdsInsightService.php +++ b/app/service/AdsInsightService.php @@ -525,7 +525,7 @@ class AdsInsightService // 计算 ROAS $roas = $total_spend == 0 ? '-' : round($total_purchases_value / $total_spend, 2); - + $cost_per_purchase = $total_purchases == 0? '-' : round($total_spend / $total_purchases, 2); // 计算 CTR $ctr = $total_impressions > 0 ? number_format(($total_clicks / $total_impressions) * 100, 2) . '%' : '-'; @@ -541,6 +541,7 @@ class AdsInsightService 'cost_per_atc' => $total_cost_per_atc, 'purchases' => $total_purchases, 'purchases_value' => '$' . number_format($total_purchases_value, 2) ?: '$0.00', // 格式化销售额$total_purchases_value, + 'cost_per_purchase' => '$' . number_format($cost_per_purchase, 2) ?: '$0.00', // 格式化销售额$total_purchases_value, 'revenue' => '$' . number_format($total_revenue, 2) ?: '$0.00', // 格式化收入 'total_cost' => '$' . number_format($total_cost, 2) ?: '$0.00', // 格式化总成本 'conversion_rate' => '-', // 没有计算逻辑,保持为 '-' @@ -575,6 +576,7 @@ class AdsInsightService 'cost_per_atc' => 0, 'purchases' => 0, 'purchases_value' => 0, + 'cost_per_purchase' => 0, 'revenue' => 0, 'total_cost' => 0, 'net_profit' => '-', // 没有提供 net_profit,保持为 '-' @@ -616,6 +618,7 @@ class AdsInsightService $aggregatedUsers[$userId]['roas'] = $total_spend == 0 ? '-' : round($total_purchases_value / $total_spend, 2); $aggregatedUsers[$userId]['amount_spend'] = '$' . number_format($total_spend, 2) ?: '$0.00'; $aggregatedUsers[$userId]['purchases_value'] = '$' . number_format($total_purchases_value, 2) ?: '$0.00'; + $aggregatedUsers[$userId]['cost_per_purchase'] = $data['purchases'] == 0 ? '$0.00' : '$' . number_format($total_purchases_value / $data['purchases'], 2); $aggregatedUsers[$userId]['revenue'] = '$' . number_format($total_revenue, 2) ?: '$0.00'; $aggregatedUsers[$userId]['total_cost'] = '$' . number_format($total_cost, 2) ?: '$0.00'; $aggregatedUsers[$userId]['conversion_rate'] = $total_impressions == 0 ? '-' : round(($total_clicks / $total_impressions) * 100, 2) . '%';