report调用广告分析数据聚合接口 更新1
This commit is contained in:
parent
64f26d4ced
commit
f3f564e0da
@ -2,15 +2,9 @@
|
|||||||
|
|
||||||
namespace app\controller;
|
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\AdsInsightService;
|
||||||
use app\service\AdsDashboardService;
|
use app\service\AdsDashboardService;
|
||||||
use app\service\LandingUrlInsightService;
|
use app\service\LandingUrlInsightService;
|
||||||
use app\service\GoogleOAuthService;
|
|
||||||
use app\service\BpsAdAccountService;
|
use app\service\BpsAdAccountService;
|
||||||
use DI\Annotation\Inject;
|
use DI\Annotation\Inject;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
@ -39,29 +33,6 @@ class BpsAdController
|
|||||||
*/
|
*/
|
||||||
private $landingUrlInsightService;
|
private $landingUrlInsightService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var GoogleAdsGroupService
|
|
||||||
*/
|
|
||||||
private $googleAdsGroupService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var GoogleAdsAdService
|
|
||||||
*/
|
|
||||||
private $googleAdsAdService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var GoogleAdsCampaignService
|
|
||||||
*/
|
|
||||||
private $googleAdsCampaignService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var GoogleOAuthService
|
|
||||||
*/
|
|
||||||
private $googleOAuthService;
|
|
||||||
/**
|
/**
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var BpsAdAccountService
|
* @var BpsAdAccountService
|
||||||
@ -74,6 +45,10 @@ class BpsAdController
|
|||||||
public function aggregateAd(Request $request)
|
public function aggregateAd(Request $request)
|
||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
|
|
||||||
|
//是否远程调用
|
||||||
|
$request->rpc = true;
|
||||||
|
|
||||||
// $startDate = $options['conditions']['startDate'] ?? null;
|
// $startDate = $options['conditions']['startDate'] ?? null;
|
||||||
// $endDate = $options['conditions']['endDate'] ?? null;
|
// $endDate = $options['conditions']['endDate'] ?? null;
|
||||||
$metrics = explode(',', $options['conditions']['metrics'] ?? '');
|
$metrics = explode(',', $options['conditions']['metrics'] ?? '');
|
||||||
@ -82,8 +57,6 @@ class BpsAdController
|
|||||||
// $merchantId = $options['jwtClaims']['merchant_id'];
|
// $merchantId = $options['jwtClaims']['merchant_id'];
|
||||||
$preloadedData = [];
|
$preloadedData = [];
|
||||||
|
|
||||||
//是否远程调用
|
|
||||||
$request->rpc = true;
|
|
||||||
|
|
||||||
// 预处理指标类型
|
// 预处理指标类型
|
||||||
$needsDashboard = false;
|
$needsDashboard = false;
|
||||||
@ -97,17 +70,24 @@ class BpsAdController
|
|||||||
$platformKey = strtolower($platform);
|
$platformKey = strtolower($platform);
|
||||||
|
|
||||||
if ($sourceType === 'dashboard') {
|
if ($sourceType === 'dashboard') {
|
||||||
$needsDashboard = true;
|
if (in_array($platformKey, ['meta_ads', 'google_ads', 'tiktok_ads'])) {
|
||||||
|
$needsDashboard = true;
|
||||||
|
}
|
||||||
} elseif ($sourceType === 'analytics') {
|
} elseif ($sourceType === 'analytics') {
|
||||||
if (in_array($platformKey, ['accounts', 'campaigns', 'adsets', 'ads', 'creatives'])) {
|
if (in_array($platformKey, ['accounts', 'campaigns', 'adsets', 'ads', 'creatives'])) {
|
||||||
$analyticsEntities[$platformKey] = true;
|
$analyticsEntities[$platformKey] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return $this->successResponse(['data' => [$needsDashboard,$analyticsEntities]], $request);
|
//调试用 return $this->successResponse(['data' => [$needsDashboard,$analyticsEntities]], $request);
|
||||||
// 批量预加载数据
|
// 批量预加载数据
|
||||||
if ($needsDashboard) {
|
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) {
|
foreach (array_keys($analyticsEntities) as $entity) {
|
||||||
@ -117,7 +97,6 @@ class BpsAdController
|
|||||||
$preloadedData[$entity] = $this->$methodName($request);
|
$preloadedData[$entity] = $this->$methodName($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return $this->successResponse(['data' => $preloadedData], $request);
|
|
||||||
|
|
||||||
// 处理每个指标
|
// 处理每个指标
|
||||||
foreach ($metrics as $metric) {
|
foreach ($metrics as $metric) {
|
||||||
@ -135,7 +114,7 @@ class BpsAdController
|
|||||||
}
|
}
|
||||||
} elseif ($sourceType === 'analytics' && isset($preloadedData[$platformKey])) {
|
} elseif ($sourceType === 'analytics' && isset($preloadedData[$platformKey])) {
|
||||||
if (isset($preloadedData[$platformKey][$field])) {
|
if (isset($preloadedData[$platformKey][$field])) {
|
||||||
$result[$platformKey][$field] = $preloadedData[$platformKey][$field];
|
$result[$platformKey][$field] = $preloadedData[$platformKey][$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -733,6 +712,7 @@ class BpsAdController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
$options['rpc'] = $request->rpc ?? false;
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom
|
$cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom
|
||||||
@ -758,6 +738,9 @@ class BpsAdController
|
|||||||
$startDate, // 开始日期
|
$startDate, // 开始日期
|
||||||
$endDate // 结束日期
|
$endDate // 结束日期
|
||||||
);
|
);
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['data'];
|
||||||
|
}
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
|
Loading…
Reference in New Issue
Block a user