fix Creative
This commit is contained in:
parent
0a36726ca4
commit
568df50454
@ -96,6 +96,7 @@ class AdsInsightService
|
||||
$total_impressions = array_sum(array_column($allCampaigns, 'impressions'));
|
||||
$total_clicks = array_sum(array_column($allCampaigns, 'clicks'));
|
||||
$total_purchases_value = array_sum(array_column($allCampaigns, 'purchases_value'));
|
||||
$total_revenue = array_sum(array_column($allCampaigns, 'revenue'));
|
||||
$total_purchases = array_sum(array_column($allCampaigns, 'purchases'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
// 汇总统计数据
|
||||
@ -113,10 +114,10 @@ class AdsInsightService
|
||||
'cost_per_purchase' => '$' . number_format($cost_per_purchase, 2) ?: '$0.00',
|
||||
'revenue' => '$' . number_format(array_sum(array_column($allCampaigns, 'revenue')), 2) ?: '$0.00', // 格式化收入
|
||||
'total_cost' => '$' . number_format($total_cost, 2) ?: '$0.00', // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有计算逻辑,保持为 '-'
|
||||
'net_profit' => '-', // 没有计算 net_profit,保持为 '-'
|
||||
'net_profit_margin' => '-', // 没有计算 net_profit_margin,保持为 '-'
|
||||
'net_profit_on_ad_spend' => '-', // 没有计算 net_profit_on_ad_spend,保持为 '-'
|
||||
'conversion_rate' => $total_clicks == 0 ? '-' : round(($total_purchases / $total_clicks) * 100, 2) . '%', // 转换率
|
||||
'net_profit' => ($total_revenue - $total_cost) >= 0 ? '+$' . number_format($total_revenue - $total_cost, 2) : '-$' . number_format($total_revenue - $total_cost, 2), // 净利润
|
||||
'net_profit_margin' => $total_revenue == 0 ? '-' : round(($total_revenue - $total_cost) / $total_revenue, 2) * 100 . '%', // 净利润率
|
||||
'net_profit_on_ad_spend' => $total_spend == 0 ? '-' : round(($total_revenue - $total_cost) / $total_spend, 2), // 广告支出净利润
|
||||
// 计算总的 CTR
|
||||
'ctr' => ($total_impressions > 0) ? number_format(($total_clicks / $total_impressions) * 100, 2) . '%' : '-', // 格式化为百分比
|
||||
];
|
||||
@ -882,6 +883,9 @@ class AdsInsightService
|
||||
|
||||
// 6. 执行查询并获取聚合结果
|
||||
$aggregatedData = $creativeDataQuery->select();
|
||||
// 打印调试 SQL 查询
|
||||
//$sql = $creativeDataQuery->getLastSql();
|
||||
// dump($sql);
|
||||
|
||||
// 7. 初始化广告创意的汇总数据和统计数据
|
||||
$creativeSummaryData = [];
|
||||
@ -928,14 +932,12 @@ class AdsInsightService
|
||||
// 更新该 creative_id 的统计数据
|
||||
$creativeSummaryData[$creativeData->creative_id]['spend'] += $creativeData->total_spend;
|
||||
$creativeSummaryData[$creativeData->creative_id]['total_conversions_value'] += $creativeData->total_conversions_value;
|
||||
$creativeSummaryData[$creativeData->creative_id]['total_conversions'] += $creativeData->total_conversions;
|
||||
$creativeSummaryData[$creativeData->creative_id]['total_impressions'] += $creativeData->total_impressions;
|
||||
|
||||
// 汇总总体统计数据
|
||||
$statisticsData['spend'] += $creativeData->total_spend;
|
||||
$statisticsData['conversions_value'] += $creativeData->total_conversions_value;
|
||||
$statisticsData['total_conversions'] += $creativeData->total_conversions;
|
||||
$statisticsData['total_impressions'] += $creativeData->total_impressions;
|
||||
$statisticsData['impressions'] += $creativeData->total_impressions;
|
||||
|
||||
// 计算 ROAS
|
||||
$roas = $creativeSummaryData[$creativeData->creative_id]['spend'] > 0
|
||||
@ -971,6 +973,7 @@ class AdsInsightService
|
||||
{
|
||||
return [
|
||||
'conversions_value' => 0,
|
||||
'impressions' => 0,
|
||||
'spend' => 0,
|
||||
'purchase_value' => '-', // 可根据需求进一步计算
|
||||
'roas' => 0, // 可以根据需要计算总体 ROAS
|
||||
|
Loading…
Reference in New Issue
Block a user