优化 creative 导出表格
This commit is contained in:
parent
982ecc2401
commit
5b38944261
@ -224,17 +224,17 @@ class AdsInsightService
|
||||
// 获取所有符合条件的数据(不分页)
|
||||
$allCampaigns = $query->select()->toArray();
|
||||
|
||||
$total_spend = array_sum(array_column($allCampaigns, 'spend'));
|
||||
$total_cost = array_sum(array_column($allCampaigns, 'total_cost'));
|
||||
$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'));
|
||||
$total_spend = array_sum(array_column($allCampaigns, 'spend'));
|
||||
$total_cost = array_sum(array_column($allCampaigns, 'total_cost'));
|
||||
$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'));
|
||||
// $total_platform_purchase = array_sum(array_column($allCampaigns, 'platform_purchase'));
|
||||
// $total_pixel_purchase = array_sum(array_column($allCampaigns, 'pixel_purchase'));
|
||||
$adds_to_cart = array_sum(array_column($allCampaigns, 'adds_to_cart'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
$adds_to_cart = array_sum(array_column($allCampaigns, 'adds_to_cart'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
// 汇总统计数据
|
||||
$statistics = [
|
||||
'platform_purchase' => array_sum(array_column($allCampaigns, 'platform_purchase')),
|
||||
@ -520,8 +520,8 @@ class AdsInsightService
|
||||
$sheet->setCellValue('B' . $row, self::$statusMapping[$adset['status']]); // Status
|
||||
$sheet->setCellValue('C' . $row, self::$platformMapping[$adset['platform_type']]); // Platform Type
|
||||
$sheet->setCellValueExplicit('D' . $row, (string)$adset['account_id'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
|
||||
$sheet->setCellValue('E' . $row, $adset['platform_purchase']);
|
||||
$sheet->setCellValue('F' . $row, $adset['pixel_purchase']);
|
||||
$sheet->setCellValue('E' . $row, $adset['platform_purchase']);
|
||||
$sheet->setCellValue('F' . $row, $adset['pixel_purchase']);
|
||||
$sheet->setCellValue('G' . $row, $adset['roas']); // ROAS
|
||||
$sheet->setCellValue('H' . $row, $adset['spend']); // Amount Spent
|
||||
$sheet->setCellValue('I' . $row, $adset['impressions']); // Impressions
|
||||
@ -738,30 +738,31 @@ class AdsInsightService
|
||||
// 设置表头
|
||||
$headers = [
|
||||
'A1' => 'Creative',
|
||||
'B1' => 'Thumbnail/Creative URL',
|
||||
'C1' => 'Creative Type',
|
||||
'D1' => 'Ad Count',
|
||||
'E1' => 'Spend',
|
||||
'F1' => 'Purchase value',
|
||||
'G1' => 'ROAS',
|
||||
'H1' => 'CPA',
|
||||
'I1' => 'CPC (link click)',
|
||||
'J1' => 'CPM',
|
||||
'K1' => 'CPC (all)',
|
||||
'L1' => 'AOV',
|
||||
'M1' => 'Click to ATC ratio',
|
||||
'N1' => 'ATC to purchase ratio',
|
||||
'O1' => 'Purchases',
|
||||
'P1' => '1st frame retention',
|
||||
'Q1' => 'Thumbstop',
|
||||
'R1' => 'CTR (outbound)',
|
||||
'S1' => 'Click to purchase',
|
||||
'T1' => 'CTR (all)',
|
||||
'U1' => '25% video plays (rate)',
|
||||
'V1' => '50% video plays (rate)',
|
||||
'W1' => '75% video plays (rate)',
|
||||
'X1' => '100% video plays (rate)',
|
||||
'Y1' => 'Hold rate'
|
||||
'B1' => 'Ad Platform',
|
||||
'C1' => 'Thumbnail/Creative URL',
|
||||
'D1' => 'Creative Type',
|
||||
'E1' => 'Ad Count',
|
||||
'F1' => 'Spend',
|
||||
'G1' => 'Purchase value',
|
||||
'H1' => 'ROAS',
|
||||
'I1' => 'CPA',
|
||||
'J1' => 'CPC (link click)',
|
||||
'K1' => 'CPM',
|
||||
'L1' => 'CPC (all)',
|
||||
'M1' => 'AOV',
|
||||
'N1' => 'Click to ATC ratio',
|
||||
'O1' => 'ATC to purchase ratio',
|
||||
'P1' => 'Purchases',
|
||||
'Q1' => '1st frame retention',
|
||||
'R1' => 'Thumbstop',
|
||||
'S1' => 'CTR (outbound)',
|
||||
'T1' => 'Click to purchase',
|
||||
'U1' => 'CTR (all)',
|
||||
'V1' => '25% video plays (rate)',
|
||||
'W1' => '50% video plays (rate)',
|
||||
'X1' => '75% video plays (rate)',
|
||||
'Y1' => '100% video plays (rate)',
|
||||
'Z1' => 'Hold rate'
|
||||
];
|
||||
|
||||
// 填充表头
|
||||
@ -773,58 +774,59 @@ class AdsInsightService
|
||||
$row = 2;
|
||||
foreach ($creativeList['data'] as $creative) {
|
||||
$sheet->setCellValue('A' . $row, $creative['creative']); // Creative
|
||||
$sheet->setCellValue('B' . $row, $creative['thumbnail_url'] ?: $creative['creative_url']); // Thumbnail/Creative URL
|
||||
$sheet->setCellValue('C' . $row, self::$creativeTypeMapping[$creative['creative_type']]); // Creative Type
|
||||
$sheet->setCellValue('D' . $row, $creative['ad_count']); // Ad Count
|
||||
$sheet->setCellValue('E' . $row, $creative['spend']); // Spend
|
||||
$sheet->setCellValue('F' . $row, $creative['purchases_value']); // Purchase value
|
||||
$sheet->setCellValue('G' . $row, $creative['roas']); // ROAS
|
||||
$sheet->setCellValue('H' . $row, $creative['cpa']); // CPA
|
||||
$sheet->setCellValue('I' . $row, $creative['cpc_link_click']); // CPC (link click)
|
||||
$sheet->setCellValue('J' . $row, $creative['cpm']); // CPM
|
||||
$sheet->setCellValue('K' . $row, $creative['cpc_all']); // CPC (all)
|
||||
$sheet->setCellValue('L' . $row, $creative['aov']); // AOV
|
||||
$sheet->setCellValue('M' . $row, $creative['click_to_atc_ratio']); // Click to ATC ratio
|
||||
$sheet->setCellValue('N' . $row, $creative['atc_to_purchase_ratio']); // ATC to purchase ratio
|
||||
$sheet->setCellValue('O' . $row, $creative['purchases']); // Purchases
|
||||
$sheet->setCellValue('P' . $row, $creative['first_frame_retention']); // 1st frame retention
|
||||
$sheet->setCellValue('Q' . $row, $creative['thumbstop']); // Thumbstop
|
||||
$sheet->setCellValue('R' . $row, $creative['ctr_outbound']); // CTR (outbound)
|
||||
$sheet->setCellValue('S' . $row, $creative['click_to_purchase']); // Click to purchase
|
||||
$sheet->setCellValue('T' . $row, $creative['ctr_all']); // CTR (all)
|
||||
$sheet->setCellValue('U' . $row, $creative['video_plays_25_rate']); // 25% video plays (rate)
|
||||
$sheet->setCellValue('V' . $row, $creative['video_plays_50_rate']); // 50% video plays (rate)
|
||||
$sheet->setCellValue('W' . $row, $creative['video_plays_75_rate']); // 75% video plays (rate)
|
||||
$sheet->setCellValue('X' . $row, $creative['video_plays_100_rate']); // 100% video plays (rate)
|
||||
$sheet->setCellValue('Y' . $row, $creative['hold_rate']); // Hold rate
|
||||
$sheet->setCellValue('B' . $row, self::$platformMapping[$creative['platform']]); // Ad Platform
|
||||
$sheet->setCellValue('C' . $row, $creative['thumbnail_url'] ?: $creative['creative_url']); // Thumbnail/Creative URL
|
||||
$sheet->setCellValue('D' . $row, self::$creativeTypeMapping[$creative['creative_type']]); // Creative Type
|
||||
$sheet->setCellValue('E' . $row, $creative['ad_count']); // Ad Count
|
||||
$sheet->setCellValue('F' . $row, $creative['spend']); // Spend
|
||||
$sheet->setCellValue('G' . $row, $creative['purchases_value']); // Purchase value
|
||||
$sheet->setCellValue('H' . $row, $creative['roas']); // ROAS
|
||||
$sheet->setCellValue('I' . $row, $creative['cpa']); // CPA
|
||||
$sheet->setCellValue('J' . $row, $creative['cpc_link_click']); // CPC (link click)
|
||||
$sheet->setCellValue('K' . $row, $creative['cpm']); // CPM
|
||||
$sheet->setCellValue('L' . $row, $creative['cpc_all']); // CPC (all)
|
||||
$sheet->setCellValue('M' . $row, $creative['aov']); // AOV
|
||||
$sheet->setCellValue('N' . $row, $creative['click_to_atc_ratio']); // Click to ATC ratio
|
||||
$sheet->setCellValue('O' . $row, $creative['atc_to_purchase_ratio']); // ATC to purchase ratio
|
||||
$sheet->setCellValue('P' . $row, $creative['purchases']); // Purchases
|
||||
$sheet->setCellValue('Q' . $row, $creative['first_frame_retention']); // 1st frame retention
|
||||
$sheet->setCellValue('R' . $row, $creative['thumbstop']); // Thumbstop
|
||||
$sheet->setCellValue('S' . $row, $creative['ctr_outbound']); // CTR (outbound)
|
||||
$sheet->setCellValue('T' . $row, $creative['click_to_purchase']); // Click to purchase
|
||||
$sheet->setCellValue('U' . $row, $creative['ctr_all']); // CTR (all)
|
||||
$sheet->setCellValue('V' . $row, $creative['video_plays_25_rate']); // 25% video plays (rate)
|
||||
$sheet->setCellValue('W' . $row, $creative['video_plays_50_rate']); // 50% video plays (rate)
|
||||
$sheet->setCellValue('X' . $row, $creative['video_plays_75_rate']); // 75% video plays (rate)
|
||||
$sheet->setCellValue('Y' . $row, $creative['video_plays_100_rate']); // 100% video plays (rate)
|
||||
$sheet->setCellValue('Z' . $row, $creative['hold_rate']); // Hold rate
|
||||
$row++;
|
||||
}
|
||||
|
||||
// 填充统计信息到表格的最后一行
|
||||
$statistics = $creativeList['statistics'];
|
||||
$statisticsRow = $row; // 统计信息从当前行开始
|
||||
$sheet->setCellValue('D' . $statisticsRow, 'Totals'); // 统计信息标题
|
||||
$sheet->setCellValue('E' . $statisticsRow, $statistics['spend']); // Spend
|
||||
$sheet->setCellValue('F' . $statisticsRow, $statistics['purchases_value']); // Purchase value
|
||||
$sheet->setCellValue('G' . $statisticsRow, $statistics['roas']); // ROAS
|
||||
$sheet->setCellValue('H' . $statisticsRow, $statistics['cpa']); // CPA
|
||||
$sheet->setCellValue('I' . $statisticsRow, $statistics['cpc_link_click']); // CPC (link click)
|
||||
$sheet->setCellValue('J' . $statisticsRow, $statistics['cpm']); // CPM
|
||||
$sheet->setCellValue('K' . $statisticsRow, $statistics['cpc_all']); // CPC (all)
|
||||
$sheet->setCellValue('L' . $statisticsRow, $statistics['aov']); // AOV
|
||||
$sheet->setCellValue('M' . $statisticsRow, $statistics['click_to_atc_ratio']); // Click to ATC ratio
|
||||
$sheet->setCellValue('N' . $statisticsRow, $statistics['atc_to_purchase_ratio']); // ATC to purchase ratio
|
||||
$sheet->setCellValue('O' . $statisticsRow, $statistics['purchases']); // Purchases
|
||||
$sheet->setCellValue('P' . $statisticsRow, $statistics['first_frame_retention']); // 1st frame retention
|
||||
$sheet->setCellValue('Q' . $statisticsRow, $statistics['thumbstop']); // Thumbstop
|
||||
$sheet->setCellValue('R' . $statisticsRow, $statistics['ctr_outbound']); // CTR (outbound)
|
||||
$sheet->setCellValue('S' . $statisticsRow, $statistics['click_to_purchase']); // Click to purchase
|
||||
$sheet->setCellValue('T' . $statisticsRow, $statistics['ctr_all']); // CTR (all)
|
||||
$sheet->setCellValue('U' . $statisticsRow, $statistics['video_plays_25_rate']); // 25% video plays (rate)
|
||||
$sheet->setCellValue('V' . $statisticsRow, $statistics['video_plays_50_rate']); // 50% video plays (rate)
|
||||
$sheet->setCellValue('W' . $statisticsRow, $statistics['video_plays_75_rate']); // 75% video plays (rate)
|
||||
$sheet->setCellValue('X' . $statisticsRow, $statistics['video_plays_100_rate']); // 100% video plays (rate)
|
||||
$sheet->setCellValue('Y' . $statisticsRow, $statistics['hold_rate']); // Hold rate
|
||||
$sheet->setCellValue('E' . $statisticsRow, 'Totals'); // 统计信息标题
|
||||
$sheet->setCellValue('F' . $statisticsRow, $statistics['spend']); // Spend
|
||||
$sheet->setCellValue('G' . $statisticsRow, $statistics['purchases_value']); // Purchase value
|
||||
$sheet->setCellValue('H' . $statisticsRow, $statistics['roas']); // ROAS
|
||||
$sheet->setCellValue('I' . $statisticsRow, $statistics['cpa']); // CPA
|
||||
$sheet->setCellValue('J' . $statisticsRow, $statistics['cpc_link_click']); // CPC (link click)
|
||||
$sheet->setCellValue('K' . $statisticsRow, $statistics['cpm']); // CPM
|
||||
$sheet->setCellValue('L' . $statisticsRow, $statistics['cpc_all']); // CPC (all)
|
||||
$sheet->setCellValue('M' . $statisticsRow, $statistics['aov']); // AOV
|
||||
$sheet->setCellValue('N' . $statisticsRow, $statistics['click_to_atc_ratio']); // Click to ATC ratio
|
||||
$sheet->setCellValue('O' . $statisticsRow, $statistics['atc_to_purchase_ratio']); // ATC to purchase ratio
|
||||
$sheet->setCellValue('P' . $statisticsRow, $statistics['purchases']); // Purchases
|
||||
$sheet->setCellValue('Q' . $statisticsRow, $statistics['first_frame_retention']); // 1st frame retention
|
||||
$sheet->setCellValue('R' . $statisticsRow, $statistics['thumbstop']); // Thumbstop
|
||||
$sheet->setCellValue('S' . $statisticsRow, $statistics['ctr_outbound']); // CTR (outbound)
|
||||
$sheet->setCellValue('T' . $statisticsRow, $statistics['click_to_purchase']); // Click to purchase
|
||||
$sheet->setCellValue('U' . $statisticsRow, $statistics['ctr_all']); // CTR (all)
|
||||
$sheet->setCellValue('V' . $statisticsRow, $statistics['video_plays_25_rate']); // 25% video plays (rate)
|
||||
$sheet->setCellValue('W' . $statisticsRow, $statistics['video_plays_50_rate']); // 50% video plays (rate)
|
||||
$sheet->setCellValue('X' . $statisticsRow, $statistics['video_plays_75_rate']); // 75% video plays (rate)
|
||||
$sheet->setCellValue('Y' . $statisticsRow, $statistics['video_plays_100_rate']); // 100% video plays (rate)
|
||||
$sheet->setCellValue('Z' . $statisticsRow, $statistics['hold_rate']); // Hold rate
|
||||
|
||||
// 释放内存
|
||||
unset($statistics);
|
||||
@ -933,8 +935,8 @@ class AdsInsightService
|
||||
$total_purchases = array_sum(array_column($allAdsets, 'purchases'));
|
||||
// $total_platform_purchase = array_sum(array_column($allAdsets, 'platform_purchase'));
|
||||
// $total_pixel_purchase = array_sum(array_column($allAdsets, 'pixel_purchase'));
|
||||
$adds_to_cart = array_sum(array_column($allAdsets, 'adds_to_cart'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
$adds_to_cart = array_sum(array_column($allAdsets, 'adds_to_cart'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
|
||||
// 汇总统计数据
|
||||
$statistics = [
|
||||
@ -1633,17 +1635,17 @@ class AdsInsightService
|
||||
}
|
||||
|
||||
// 汇总统计
|
||||
$aggregatedUsers[$thirdUserId]['spend'] += $item['spend'];
|
||||
$aggregatedUsers[$thirdUserId]['impressions'] += $item['impressions'];
|
||||
$aggregatedUsers[$thirdUserId]['clicks'] += $item['clicks'];
|
||||
$aggregatedUsers[$thirdUserId]['adds_to_cart'] += $item['adds_to_cart'];
|
||||
$aggregatedUsers[$thirdUserId]['cost_per_atc'] += $item['cost_per_atc'];
|
||||
$aggregatedUsers[$thirdUserId]['purchases'] += $item['purchases'];
|
||||
$aggregatedUsers[$thirdUserId]['purchases_value'] += $item['purchases_value'];
|
||||
$aggregatedUsers[$thirdUserId]['revenue'] += $item['revenue'];
|
||||
$aggregatedUsers[$thirdUserId]['total_cost'] += $item['total_cost'];
|
||||
$aggregatedUsers[$thirdUserId]['platform_purchase'] += $item['platform_purchase'];
|
||||
$aggregatedUsers[$thirdUserId]['pixel_purchase'] += $item['pixel_purchase'];
|
||||
$aggregatedUsers[$thirdUserId]['spend'] += $item['spend'];
|
||||
$aggregatedUsers[$thirdUserId]['impressions'] += $item['impressions'];
|
||||
$aggregatedUsers[$thirdUserId]['clicks'] += $item['clicks'];
|
||||
$aggregatedUsers[$thirdUserId]['adds_to_cart'] += $item['adds_to_cart'];
|
||||
$aggregatedUsers[$thirdUserId]['cost_per_atc'] += $item['cost_per_atc'];
|
||||
$aggregatedUsers[$thirdUserId]['purchases'] += $item['purchases'];
|
||||
$aggregatedUsers[$thirdUserId]['purchases_value'] += $item['purchases_value'];
|
||||
$aggregatedUsers[$thirdUserId]['revenue'] += $item['revenue'];
|
||||
$aggregatedUsers[$thirdUserId]['total_cost'] += $item['total_cost'];
|
||||
$aggregatedUsers[$thirdUserId]['platform_purchase'] += $item['platform_purchase'];
|
||||
$aggregatedUsers[$thirdUserId]['pixel_purchase'] += $item['pixel_purchase'];
|
||||
}
|
||||
|
||||
// 计算统计口径字段:ROAS, CTR等
|
||||
|
Loading…
Reference in New Issue
Block a user