From 973df3866eba799bd45f260bc221832b5760ed25 Mon Sep 17 00:00:00 2001 From: huangguancheng Date: Sat, 15 Feb 2025 18:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E4=B8=AA=E5=B9=BF=E5=91=8A=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=9B=B4=E6=8D=A2=E8=B4=A6=E5=8F=B7=E8=A1=A8222?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/AdsInsightService.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/service/AdsInsightService.php b/app/service/AdsInsightService.php index bee0b66..1a1a333 100644 --- a/app/service/AdsInsightService.php +++ b/app/service/AdsInsightService.php @@ -206,8 +206,8 @@ class AdsInsightService COALESCE(SUM(d.revenue / 1000000), 0) as revenue, COALESCE(SUM(d.total_cost / 1000000), 0) as total_cost, -1 as conversion_rate, -1 as roas, -1 as ctr,-1 as net_profit,-1 as net_profit_margin,-1 as net_profit_on_ad_spend') - ->group('c.campaign_id, c.status, c.account_id, c.name,c.platform_type') - ->where('c.account_id', 'in', $customerIds); // 添加 customerIds 条件 + ->group('c.campaign_id, c.status, c.account_id, c.name,c.platform_type'); +// ->where('c.account_id', 'in', $customerIds); // 添加 customerIds 条件 // 根据 $requireSpend 参数决定是否添加 SUM(d.spend) > 0 的条件 if ($requireSpend) { $query->having('SUM(d.spend) > 0'); @@ -910,8 +910,8 @@ class AdsInsightService COALESCE(SUM(d.revenue / 1000000), 0) as revenue, COALESCE(SUM(d.total_cost / 1000000), 0) as total_cost, -1 as conversion_rate, -1 as roas, -1 as ctr,-1 as net_profit,-1 as net_profit_margin,-1 as net_profit_on_ad_spend') - ->group('s.ad_set_id, s.status, s.account_id, s.name,s.platform_type,c.name') - ->where('s.account_id', 'in', $customerIds); // 添加 customerIds 条件 + ->group('s.ad_set_id, s.status, s.account_id, s.name,s.platform_type,c.name'); +// ->where('s.account_id', 'in', $customerIds); // 添加 customerIds 条件 // 根据 $requireSpend 参数决定是否添加 SUM(d.spend) > 0 的条件 if ($requireSpend) { $query->having('SUM(d.spend) > 0'); @@ -1214,8 +1214,8 @@ class AdsInsightService COALESCE(SUM(d.revenue) / 1000000, 0) as revenue, COALESCE(SUM(d.total_cost) / 1000000, 0) as total_cost, -1 as conversion_rate, -1 as roas, -1 as ctr, -1 as net_profit, -1 as net_profit_margin, -1 as net_profit_on_ad_spend') - ->group('bamr.account_id, bamr.account_name,bamr.platform') - ->where('bamr.account_id', 'in', $customerIds); // 添加 customerIds 条件 + ->group('bamr.account_id, bamr.account_name,bamr.platform'); +// ->where('bamr.account_id', 'in', $customerIds); // 添加 customerIds 条件 // 如果传入了 status 参数,按状态筛选 // if ($status !== 0) { // $query->where('a.status', '=', $status); @@ -1240,7 +1240,9 @@ class AdsInsightService // 获取所有符合条件的数据(不分页) $allAccounts = $query->select()->toArray(); - + // 打印调试 SQL 查询 + $sql = $query->getLastSql(); + dump($sql); // 汇总统计数据 $total_spend = array_sum(array_column($allAccounts, 'spend')); $total_cost = array_sum(array_column($allAccounts, 'total_cost')); @@ -1389,8 +1391,8 @@ class AdsInsightService COALESCE(SUM(d.revenue) / 1000000, 0) as revenue, COALESCE(SUM(d.total_cost) / 1000000, 0) as total_cost, -1 as conversion_rate, -1 as roas, -1 as ctr, -1 as net_profit, -1 as net_profit_margin, -1 as net_profit_on_ad_spend') - ->group('a.ad_id, a.status, a.account_id, a.name,a.platform_type, s.name') - ->where('a.account_id', 'in', $customerIds); // 添加 customerIds 条件 + ->group('a.ad_id, a.status, a.account_id, a.name,a.platform_type, s.name'); +// ->where('a.account_id', 'in', $customerIds); // 添加 customerIds 条件 // 如果传入了 status 参数,按状态筛选 if ($status !== 0) { $query->where('a.status', '=', $status);