report调用广告分析数据聚合接口
This commit is contained in:
parent
6a15181d90
commit
64f26d4ced
@ -68,6 +68,84 @@ class BpsAdController
|
|||||||
*/
|
*/
|
||||||
private $bpsAdAccountService;
|
private $bpsAdAccountService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广告数据聚合接口
|
||||||
|
*/
|
||||||
|
public function aggregateAd(Request $request)
|
||||||
|
{
|
||||||
|
$options = $request->all();
|
||||||
|
// $startDate = $options['conditions']['startDate'] ?? null;
|
||||||
|
// $endDate = $options['conditions']['endDate'] ?? null;
|
||||||
|
$metrics = explode(',', $options['conditions']['metrics'] ?? '');
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
// $merchantId = $options['jwtClaims']['merchant_id'];
|
||||||
|
$preloadedData = [];
|
||||||
|
|
||||||
|
//是否远程调用
|
||||||
|
$request->rpc = true;
|
||||||
|
|
||||||
|
// 预处理指标类型
|
||||||
|
$needsDashboard = false;
|
||||||
|
$analyticsEntities = [];
|
||||||
|
foreach ($metrics as $metric) {
|
||||||
|
$parts = explode('#', $metric);
|
||||||
|
if (count($parts) !== 3) continue;
|
||||||
|
|
||||||
|
[$sourceType, $platform, $field] = $parts;
|
||||||
|
$sourceType = strtolower($sourceType);
|
||||||
|
$platformKey = strtolower($platform);
|
||||||
|
|
||||||
|
if ($sourceType === 'dashboard') {
|
||||||
|
$needsDashboard = true;
|
||||||
|
} elseif ($sourceType === 'analytics') {
|
||||||
|
if (in_array($platformKey, ['accounts', 'campaigns', 'adsets', 'ads', 'creatives'])) {
|
||||||
|
$analyticsEntities[$platformKey] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// return $this->successResponse(['data' => [$needsDashboard,$analyticsEntities]], $request);
|
||||||
|
// 批量预加载数据
|
||||||
|
if ($needsDashboard) {
|
||||||
|
$preloadedData['dashboard'] = $this->listCards($request)->original['data'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array_keys($analyticsEntities) as $entity) {
|
||||||
|
$methodName = 'list' . ucfirst($entity);
|
||||||
|
|
||||||
|
if (method_exists($this, $methodName)) {
|
||||||
|
$preloadedData[$entity] = $this->$methodName($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// return $this->successResponse(['data' => $preloadedData], $request);
|
||||||
|
|
||||||
|
// 处理每个指标
|
||||||
|
foreach ($metrics as $metric) {
|
||||||
|
$parts = explode('#', $metric);
|
||||||
|
if (count($parts) !== 3) continue;
|
||||||
|
|
||||||
|
[$sourceType, $platform, $field] = $parts;
|
||||||
|
$sourceType = strtolower($sourceType);
|
||||||
|
$platformKey = strtolower($platform);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($sourceType === 'dashboard') {
|
||||||
|
if (isset($preloadedData['dashboard'][$platformKey][$field])) {
|
||||||
|
$result[$platformKey][$field] = $preloadedData['dashboard'][$platformKey][$field];
|
||||||
|
}
|
||||||
|
} elseif ($sourceType === 'analytics' && isset($preloadedData[$platformKey])) {
|
||||||
|
if (isset($preloadedData[$platformKey][$field])) {
|
||||||
|
$result[$platformKey][$field] = $preloadedData[$platformKey][$field];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$result[$platformKey]['errors'][$field] = $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successResponse(['data' => $result], $request);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 返回标签页角标数字接口
|
* 返回标签页角标数字接口
|
||||||
*
|
*
|
||||||
@ -97,10 +175,17 @@ class BpsAdController
|
|||||||
return $this->successResponse($ad_data_count, $request);
|
return $this->successResponse($ad_data_count, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listThirdUsers(Request $request)
|
public function listAccounts(Request $request)
|
||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
$options['rpc'] = $request->rpc ?? false;
|
||||||
|
if ($options['rpc']) {
|
||||||
|
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||||
|
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||||
|
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$page = $options['pageNo'] ?? 1; // 页码
|
$page = $options['pageNo'] ?? 1; // 页码
|
||||||
@ -137,6 +222,10 @@ class BpsAdController
|
|||||||
$requireSpend
|
$requireSpend
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['statistics'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
@ -146,6 +235,12 @@ class BpsAdController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
$options['rpc'] = $request->rpc ?? false;
|
||||||
|
if ($options['rpc']) {
|
||||||
|
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||||
|
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||||
|
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$page = $options['pageNo'] ?? 1; // 页码
|
$page = $options['pageNo'] ?? 1; // 页码
|
||||||
@ -155,7 +250,7 @@ class BpsAdController
|
|||||||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||||||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||||||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||||||
$requireSpend = (bool)($options['conditions']['requireSpend']?? false);
|
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||||||
// $dateRange = 'Last Week'; // 默认日期范围
|
// $dateRange = 'Last Week'; // 默认日期范围
|
||||||
|
|
||||||
// 根据 platformType 获取广告账户
|
// 根据 platformType 获取广告账户
|
||||||
@ -181,6 +276,10 @@ class BpsAdController
|
|||||||
$requireSpend
|
$requireSpend
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['statistics'];
|
||||||
|
}
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
}
|
}
|
||||||
@ -189,6 +288,12 @@ class BpsAdController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
$options['rpc'] = $request->rpc ?? false;
|
||||||
|
if ($options['rpc']) {
|
||||||
|
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||||
|
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||||
|
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$page = $options['pageNo'] ?? 1; // 页码
|
$page = $options['pageNo'] ?? 1; // 页码
|
||||||
@ -221,6 +326,11 @@ class BpsAdController
|
|||||||
$status,
|
$status,
|
||||||
$requireSpend
|
$requireSpend
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['statistics'];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
// return $this->errorResponse(300,'授权失败');
|
// return $this->errorResponse(300,'授权失败');
|
||||||
}
|
}
|
||||||
@ -446,6 +556,12 @@ class BpsAdController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
$options['rpc'] = $request->rpc ?? false;
|
||||||
|
if ($options['rpc']) {
|
||||||
|
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||||
|
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||||
|
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$page = $options['pageNo'] ?? 1; // 页码
|
$page = $options['pageNo'] ?? 1; // 页码
|
||||||
@ -481,6 +597,10 @@ class BpsAdController
|
|||||||
$requireSpend
|
$requireSpend
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['statistics'];
|
||||||
|
}
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
}
|
}
|
||||||
@ -489,6 +609,11 @@ class BpsAdController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
$options['jwtClaims'] = $request->jwtClaims;
|
$options['jwtClaims'] = $request->jwtClaims;
|
||||||
|
if ($options['rpc']) {
|
||||||
|
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||||
|
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||||
|
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取请求参数
|
// 获取请求参数
|
||||||
$page = $options['pageNo'] ?? 1; // 页码
|
$page = $options['pageNo'] ?? 1; // 页码
|
||||||
@ -522,6 +647,9 @@ class BpsAdController
|
|||||||
$endDate, // 结束日期
|
$endDate, // 结束日期
|
||||||
$requireSpend
|
$requireSpend
|
||||||
);
|
);
|
||||||
|
if ($options['rpc']) {
|
||||||
|
return $result['statistics'];
|
||||||
|
}
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return $this->successResponse($result, $request);
|
return $this->successResponse($result, $request);
|
||||||
|
@ -70,7 +70,7 @@ Route::group('/marketing', function () {
|
|||||||
app\middleware\OauthThirdCheck::class,
|
app\middleware\OauthThirdCheck::class,
|
||||||
]);
|
]);
|
||||||
Route::group('/account', function () {
|
Route::group('/account', function () {
|
||||||
Route::post('/list', [BpsAdController::class, 'listThirdUsers']);
|
Route::post('/list', [BpsAdController::class, 'listAccounts']);
|
||||||
Route::post('/export', [BpsAdController::class, 'exportAccountsToExcel']);
|
Route::post('/export', [BpsAdController::class, 'exportAccountsToExcel']);
|
||||||
})->middleware([
|
})->middleware([
|
||||||
app\middleware\JwtLocal::class,
|
app\middleware\JwtLocal::class,
|
||||||
@ -104,9 +104,11 @@ Route::group('/marketing', function () {
|
|||||||
app\middleware\JwtLocal::class,
|
app\middleware\JwtLocal::class,
|
||||||
app\middleware\OauthThirdCheck::class,
|
app\middleware\OauthThirdCheck::class,
|
||||||
]);
|
]);
|
||||||
// Route::group('/notice', function () {
|
Route::group('/notice', function () {
|
||||||
// Route::post('/init_ads_account', [NoticeController::class, 'initNewGoogleAdsAccountData']);
|
Route::post('/aggregate', [BpsAdController::class, 'aggregateAd']);
|
||||||
// });
|
})->middleware([
|
||||||
|
app\middleware\JwtLocal::class,
|
||||||
|
]);
|
||||||
Route::group('/customer', function () {
|
Route::group('/customer', function () {
|
||||||
Route::get('/handle_binding', [CustomerController::class, 'handleBindingNew']); //绑定接口
|
Route::get('/handle_binding', [CustomerController::class, 'handleBindingNew']); //绑定接口
|
||||||
Route::post('/bind', [CustomerController::class, 'bind']); //绑定接口
|
Route::post('/bind', [CustomerController::class, 'bind']); //绑定接口
|
||||||
|
Loading…
Reference in New Issue
Block a user