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