cost_per_purchase
This commit is contained in:
parent
5d8d1085ba
commit
d574c02f41
@ -30,7 +30,7 @@ class AdsInsightService
|
||||
/**
|
||||
* 获取广告系列列表
|
||||
*/
|
||||
public static function getCampaignList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null,$status =0)
|
||||
public static function getCampaignList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null, $status = 0)
|
||||
{
|
||||
// 检查 customerIds 是否为空,直接返回空结构
|
||||
if (empty($customerIds)) {
|
||||
@ -96,6 +96,8 @@ 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_purchases = array_sum(array_column($allCampaigns, 'purchases'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
// 汇总统计数据
|
||||
$statistics = [
|
||||
'assisted_purchases' => array_sum(array_column($allCampaigns, 'assisted_purchases')),
|
||||
@ -108,6 +110,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => array_sum(array_column($allCampaigns, 'cost_per_atc')),
|
||||
'purchases' => array_sum(array_column($allCampaigns, 'purchases')),
|
||||
'purchases_value' => array_sum(array_column($allCampaigns, 'purchases_value')),
|
||||
'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' => '-', // 没有计算逻辑,保持为 '-'
|
||||
@ -140,6 +143,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => $item['cost_per_atc'],
|
||||
'purchases' => $item['purchases'],
|
||||
'purchases_value' => '$' . number_format($item['purchases_value'], 2), // 格式化购买金额
|
||||
'cost_per_purchase' => $item['purchases'] > 0 ? '$' . number_format(($item['spend'] / $item['purchases']), 2) : '$0.00',
|
||||
'revenue' => '$' . number_format($item['revenue'], 2), // 格式化收入
|
||||
'total_cost' => '$' . number_format($item['total_cost'], 2), // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有提供有效的计算,保持为 '-'
|
||||
@ -236,6 +240,8 @@ class AdsInsightService
|
||||
$total_impressions = array_sum(array_column($allAdsets, 'impressions'));
|
||||
$total_clicks = array_sum(array_column($allAdsets, 'clicks'));
|
||||
$total_purchases_value = array_sum(array_column($allAdsets, 'purchases_value'));
|
||||
$total_purchases = array_sum(array_column($allAdsets, 'purchases'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
|
||||
// 汇总统计数据
|
||||
$statistics = [
|
||||
@ -249,6 +255,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => array_sum(array_column($allAdsets, 'cost_per_atc')),
|
||||
'purchases' => array_sum(array_column($allAdsets, 'purchases')),
|
||||
'purchases_value' => array_sum(array_column($allAdsets, 'purchases_value')),
|
||||
'cost_per_purchase' => '$' . number_format($cost_per_purchase, 2) ?: '$0.00',
|
||||
'revenue' => '$' . number_format(array_sum(array_column($allAdsets, 'revenue')), 2) ?: '$0.00', // 格式化收入
|
||||
'total_cost' => '$' . number_format($total_cost, 2) ?: '$0.00', // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有计算逻辑,保持为 '-'
|
||||
@ -281,6 +288,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => $item['cost_per_atc'],
|
||||
'purchases' => $item['purchases'],
|
||||
'purchases_value' => '$' . number_format($item['purchases_value'], 2), // 格式化购买金额
|
||||
'cost_per_purchase' => $item['purchases'] > 0 ? '$' . number_format(($item['spend'] / $item['purchases']), 2) : '$0.00',
|
||||
'revenue' => '$' . number_format($item['revenue'], 2), // 格式化收入
|
||||
'total_cost' => '$' . number_format($item['total_cost'], 2), // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有提供有效的计算,保持为 '-'
|
||||
@ -374,6 +382,8 @@ class AdsInsightService
|
||||
$total_impressions = array_sum(array_column($allAds, 'impressions'));
|
||||
$total_clicks = array_sum(array_column($allAds, 'clicks'));
|
||||
$total_purchases_value = array_sum(array_column($allAds, 'purchases_value'));
|
||||
$total_purchases = array_sum(array_column($allAds, 'purchases'));
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
|
||||
$statistics = [
|
||||
'assisted_purchases' => array_sum(array_column($allAds, 'assisted_purchases')),
|
||||
@ -386,6 +396,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => array_sum(array_column($allAds, 'cost_per_atc')),
|
||||
'purchases' => array_sum(array_column($allAds, 'purchases')),
|
||||
'purchases_value' => array_sum(array_column($allAds, 'purchases_value')),
|
||||
'cost_per_purchase' => '$' . number_format($cost_per_purchase, 2) ?: '$0.00',
|
||||
'revenue' => '$' . number_format(array_sum(array_column($allAds, 'revenue')), 2) ?: '$0.00', // 格式化收入
|
||||
'total_cost' => '$' . number_format($total_cost, 2) ?: '$0.00', // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有计算逻辑,保持为 '-'
|
||||
@ -417,6 +428,7 @@ class AdsInsightService
|
||||
'cost_per_atc' => $item['cost_per_atc'],
|
||||
'purchases' => $item['purchases'],
|
||||
'purchases_value' => '$' . number_format($item['purchases_value'], 2), // 格式化购买金额
|
||||
'cost_per_purchase' => $item['purchases'] > 0 ? '$' . number_format(($item['spend'] / $item['purchases']), 2) : '$0.00',
|
||||
'revenue' => '$' . number_format($item['revenue'], 2), // 格式化收入
|
||||
'total_cost' => '$' . number_format($item['total_cost'], 2), // 格式化总成本
|
||||
'conversion_rate' => '-', // 没有提供有效的计算,保持为 '-'
|
||||
@ -524,8 +536,8 @@ class AdsInsightService
|
||||
$total_cost = array_sum(array_column($allUsers, 'total_cost'));
|
||||
|
||||
// 计算 ROAS
|
||||
$roas = $total_spend == 0 ? '-' : round($total_purchases_value / $total_spend, 2);
|
||||
$cost_per_purchase = $total_purchases == 0? 0 : round($total_spend / $total_purchases, 2);
|
||||
$roas = $total_spend == 0 ? '-' : round($total_purchases_value / $total_spend, 2);
|
||||
$cost_per_purchase = $total_purchases == 0 ? 0 : round($total_spend / $total_purchases, 2);
|
||||
// 计算 CTR
|
||||
$ctr = $total_impressions > 0 ? number_format(($total_clicks / $total_impressions) * 100, 2) . '%' : '-';
|
||||
|
||||
@ -615,14 +627,14 @@ class AdsInsightService
|
||||
// $total_last_clicked_purchases = $data['last_clicked_purchases'];
|
||||
|
||||
// 计算 ROAS, CTR 和其他需要的字段
|
||||
$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]['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) . '%';
|
||||
$aggregatedUsers[$userId]['ctr'] = $total_impressions == 0 ? '-' : round(($total_clicks / $total_impressions) * 100, 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) . '%';
|
||||
$aggregatedUsers[$userId]['ctr'] = $total_impressions == 0 ? '-' : round(($total_clicks / $total_impressions) * 100, 2) . '%';
|
||||
}
|
||||
// 使用 array_values 移除键名
|
||||
$dataWithoutKeys = array_values($aggregatedUsers);
|
||||
|
Loading…
Reference in New Issue
Block a user