From f3f564e0da3152217033b291ccf5a0a0d195cb01 Mon Sep 17 00:00:00 2001 From: hgc Date: Fri, 28 Feb 2025 14:45:18 +0800 Subject: [PATCH] =?UTF-8?q?report=E8=B0=83=E7=94=A8=E5=B9=BF=E5=91=8A?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=95=B0=E6=8D=AE=E8=81=9A=E5=90=88=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=E6=9B=B4=E6=96=B01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/BpsAdController.php | 55 +++++++++++------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/app/controller/BpsAdController.php b/app/controller/BpsAdController.php index 5a029f8..7190542 100644 --- a/app/controller/BpsAdController.php +++ b/app/controller/BpsAdController.php @@ -2,15 +2,9 @@ namespace app\controller; -use app\service\GoogleAdsAdService; -use app\service\GoogleAdsCampaignService; -use app\service\GoogleAdsGroupService; - -//use app\service\GoogleAdsReportService; use app\service\AdsInsightService; use app\service\AdsDashboardService; use app\service\LandingUrlInsightService; -use app\service\GoogleOAuthService; use app\service\BpsAdAccountService; use DI\Annotation\Inject; use support\Request; @@ -39,29 +33,6 @@ class BpsAdController */ private $landingUrlInsightService; - /** - * @Inject - * @var GoogleAdsGroupService - */ - private $googleAdsGroupService; - - /** - * @Inject - * @var GoogleAdsAdService - */ - private $googleAdsAdService; - - /** - * @Inject - * @var GoogleAdsCampaignService - */ - private $googleAdsCampaignService; - - /** - * @Inject - * @var GoogleOAuthService - */ - private $googleOAuthService; /** * @Inject * @var BpsAdAccountService @@ -74,6 +45,10 @@ class BpsAdController public function aggregateAd(Request $request) { $options = $request->all(); + + //是否远程调用 + $request->rpc = true; + // $startDate = $options['conditions']['startDate'] ?? null; // $endDate = $options['conditions']['endDate'] ?? null; $metrics = explode(',', $options['conditions']['metrics'] ?? ''); @@ -82,8 +57,6 @@ class BpsAdController // $merchantId = $options['jwtClaims']['merchant_id']; $preloadedData = []; - //是否远程调用 - $request->rpc = true; // 预处理指标类型 $needsDashboard = false; @@ -97,17 +70,24 @@ class BpsAdController $platformKey = strtolower($platform); if ($sourceType === 'dashboard') { - $needsDashboard = true; + if (in_array($platformKey, ['meta_ads', 'google_ads', 'tiktok_ads'])) { + $needsDashboard = true; + } } elseif ($sourceType === 'analytics') { if (in_array($platformKey, ['accounts', 'campaigns', 'adsets', 'ads', 'creatives'])) { $analyticsEntities[$platformKey] = true; } } } -// return $this->successResponse(['data' => [$needsDashboard,$analyticsEntities]], $request); +//调试用 return $this->successResponse(['data' => [$needsDashboard,$analyticsEntities]], $request); // 批量预加载数据 if ($needsDashboard) { - $preloadedData['dashboard'] = $this->listCards($request)->original['data'] ?? []; + $dashboardData = $this->listCards($request); + // 转换平台 key 添加 _ads 后缀 + $preloadedData['dashboard'] = []; + foreach ($dashboardData as $platform => $data) { + $preloadedData['dashboard'][$platform . '_ads'] = $data; //键名适配 + } } foreach (array_keys($analyticsEntities) as $entity) { @@ -117,7 +97,6 @@ class BpsAdController $preloadedData[$entity] = $this->$methodName($request); } } -// return $this->successResponse(['data' => $preloadedData], $request); // 处理每个指标 foreach ($metrics as $metric) { @@ -135,7 +114,7 @@ class BpsAdController } } elseif ($sourceType === 'analytics' && isset($preloadedData[$platformKey])) { if (isset($preloadedData[$platformKey][$field])) { - $result[$platformKey][$field] = $preloadedData[$platformKey][$field]; + $result[$platformKey][$field] = $preloadedData[$platformKey][$field]; } } } catch (\Exception $e) { @@ -733,6 +712,7 @@ class BpsAdController { $options = $request->all(); $options['jwtClaims'] = $request->jwtClaims; + $options['rpc'] = $request->rpc ?? false; // 获取请求参数 $cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom @@ -758,6 +738,9 @@ class BpsAdController $startDate, // 开始日期 $endDate // 结束日期 ); + if ($options['rpc']) { + return $result['data']; + } // 返回结果 return $this->successResponse($result, $request);