优化查询 广告主体下层级账号获取接口--过滤无权限0level账号
This commit is contained in:
parent
cb8a07b40f
commit
c4cfd60c7a
@ -5,6 +5,7 @@ namespace app\controller;
|
|||||||
use app\service\GoogleOAuthService;
|
use app\service\GoogleOAuthService;
|
||||||
use app\service\GoogleAdsAccountService;
|
use app\service\GoogleAdsAccountService;
|
||||||
use Google\ApiCore\ApiException;
|
use Google\ApiCore\ApiException;
|
||||||
|
use support\Log;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use DI\Annotation\Inject;
|
use DI\Annotation\Inject;
|
||||||
@ -56,7 +57,9 @@ class CustomerController
|
|||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
|
|
||||||
$options['refresh_token'] = $request->refresh_token;
|
$options['refresh_token'] = $request->refresh_token;
|
||||||
$options['login_customer_id'] = $request->login_customer_id;
|
// $options['login_customer_id'] = $request->login_customer_id;
|
||||||
|
$options['login_customer_id'] = $request->input('login_customer_id');
|
||||||
|
$options['manager_customer_id'] = $request->input('manager_customer_id') !== null ? $request->input('manager_customer_id') : null;
|
||||||
// 继续处理 Google Ads API 操作
|
// 继续处理 Google Ads API 操作
|
||||||
return $this->getAccountHierarchy($options);
|
return $this->getAccountHierarchy($options);
|
||||||
}
|
}
|
||||||
@ -90,8 +93,26 @@ class CustomerController
|
|||||||
*/
|
*/
|
||||||
public function getAccountHierarchy($options): Response
|
public function getAccountHierarchy($options): Response
|
||||||
{
|
{
|
||||||
// dump($options);
|
if (!isset($options['manager_customer_id'])) {
|
||||||
$resourceName = $this->googleAdsAccountService->runGetAccountHierarchy($options);
|
$resourceName = [];
|
||||||
|
$listAccessibleCustomers = $this->googleAdsAccountService->runListAccessibleCustomers($options);
|
||||||
|
foreach ($listAccessibleCustomers as $rootAccountId) {
|
||||||
|
$options['manager_customer_id'] = $rootAccountId; //开发者
|
||||||
|
$options['login_customer_id'] = $rootAccountId;
|
||||||
|
try {
|
||||||
|
// 获取当前 rootAccountId 的所有账户
|
||||||
|
$allAccountsByRoot = $this->googleAdsAccountService->runGetAccountHierarchy($options);
|
||||||
|
$resourceName[$rootAccountId] = $allAccountsByRoot;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 记录错误日志并跳过当前循环
|
||||||
|
Log::error("Error processing rootAccountId {$rootAccountId}: " . $e->getMessage());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$resourceName = $this->googleAdsAccountService->runListAccessibleCustomers($options);
|
||||||
|
|
||||||
|
}
|
||||||
return $this->successResponse(['links_resource_name' => $resourceName]);
|
return $this->successResponse(['links_resource_name' => $resourceName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,6 +741,9 @@ class GoogleAdsAccountService extends BaseService
|
|||||||
'manager' => $customerClient->getManager(),
|
'manager' => $customerClient->getManager(),
|
||||||
'test_account' => $customerClient->getTestAccount(),
|
'test_account' => $customerClient->getTestAccount(),
|
||||||
'currency' => $customerClient->getCurrencyCode(),
|
'currency' => $customerClient->getCurrencyCode(),
|
||||||
|
'status' => $customerClient->getStatus(),
|
||||||
|
'level' => $customerClient->getLevel(),
|
||||||
|
'time_zone' => $customerClient->getTimeZone(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Recursively call this function for all child accounts of $customerClient.
|
// Recursively call this function for all child accounts of $customerClient.
|
||||||
|
Loading…
Reference in New Issue
Block a user