From 2577f5df5832136300b48b85c0040699c850543e Mon Sep 17 00:00:00 2001 From: huangguancheng Date: Fri, 10 Jan 2025 20:27:02 +0800 Subject: [PATCH] fix Creative 2 --- app/service/AdsInsightService.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/service/AdsInsightService.php b/app/service/AdsInsightService.php index aa62187..1868ccb 100644 --- a/app/service/AdsInsightService.php +++ b/app/service/AdsInsightService.php @@ -96,7 +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_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); // 汇总统计数据 @@ -831,8 +831,10 @@ class AdsInsightService { // 1. 创建查询对象,初始化 BpsAdCreativeInsight 查询 $creativeDataQuery = BpsAdCreativeInsight::alias('i') - ->join('bps.bps_ads_creative c', 'i.creative_id = c.creative_id', 'LEFT') // 联接 bps_ads_creative 表 - ->where('i.platform', $platformType); // 根据 platform 筛选 + ->join('bps.bps_ads_creative c', 'i.creative_id = c.creative_id', 'LEFT'); // 联接 bps_ads_creative 表 + if ($platformType != 0) { + $creativeDataQuery->where('i.platform', $platformType); // 只有 platformType 不为 0 时才添加筛选 + } // 2. 日期范围筛选 if ($startDate && $endDate) { @@ -937,7 +939,7 @@ class AdsInsightService // 汇总总体统计数据 $statisticsData['spend'] += $creativeData->total_spend; $statisticsData['conversions_value'] += $creativeData->total_conversions_value; - $statisticsData['impressions'] += $creativeData->total_impressions; + $statisticsData['impressions'] += $creativeData->total_impressions; // 计算 ROAS $roas = $creativeSummaryData[$creativeData->creative_id]['spend'] > 0