优化查询 广告主体下层级账号获取接口--过滤无权限0level账号
This commit is contained in:
parent
cb8a07b40f
commit
c4cfd60c7a
@ -5,6 +5,7 @@ namespace app\controller;
|
||||
use app\service\GoogleOAuthService;
|
||||
use app\service\GoogleAdsAccountService;
|
||||
use Google\ApiCore\ApiException;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use DI\Annotation\Inject;
|
||||
@ -55,8 +56,10 @@ class CustomerController
|
||||
{
|
||||
$options = $request->all();
|
||||
|
||||
$options['refresh_token'] = $request->refresh_token;
|
||||
$options['login_customer_id'] = $request->login_customer_id;
|
||||
$options['refresh_token'] = $request->refresh_token;
|
||||
// $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 操作
|
||||
return $this->getAccountHierarchy($options);
|
||||
}
|
||||
@ -90,9 +93,27 @@ class CustomerController
|
||||
*/
|
||||
public function getAccountHierarchy($options): Response
|
||||
{
|
||||
// dump($options);
|
||||
$resourceName = $this->googleAdsAccountService->runGetAccountHierarchy($options);
|
||||
return $this->successResponse(['links_resource_name' => $resourceName]);
|
||||
if (!isset($options['manager_customer_id'])) {
|
||||
$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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -741,6 +741,9 @@ class GoogleAdsAccountService extends BaseService
|
||||
'manager' => $customerClient->getManager(),
|
||||
'test_account' => $customerClient->getTestAccount(),
|
||||
'currency' => $customerClient->getCurrencyCode(),
|
||||
'status' => $customerClient->getStatus(),
|
||||
'level' => $customerClient->getLevel(),
|
||||
'time_zone' => $customerClient->getTimeZone(),
|
||||
];
|
||||
|
||||
// Recursively call this function for all child accounts of $customerClient.
|
||||
|
Loading…
Reference in New Issue
Block a user