84 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace app\event;
 | |
| 
 | |
| use app\service\BpsAdAccountService;
 | |
| use app\service\GoogleAdsAssetService;
 | |
| use app\service\GoogleOAuthService;
 | |
| use Google\ApiCore\ApiException;
 | |
| use GuzzleHttp\Client;
 | |
| use GuzzleHttp\Exception\GuzzleException;
 | |
| use support\Db;
 | |
| use Webman\RedisQueue\Redis;
 | |
| use support\Response;
 | |
| use DI\Annotation\Inject;
 | |
| 
 | |
| //use QL\QueryList;
 | |
| 
 | |
| 
 | |
| class GoogleAdsAssets
 | |
| {
 | |
|     /**
 | |
|      * @Inject
 | |
|      * @var GoogleOAuthService
 | |
|      */
 | |
| 
 | |
|     private $googleOAuthService;
 | |
| 
 | |
|     /**
 | |
|      * @Inject
 | |
|      * @var BpsAdAccountService
 | |
|      */
 | |
| 
 | |
|     private $bpsAdAccountService;
 | |
| 
 | |
| 
 | |
|     const event = 'googleads:assets:event';
 | |
|     const queue = 'googleads:assets:queue';
 | |
| 
 | |
|     public function syncAssets($options = [])
 | |
|     {
 | |
|         $queue = self::queue;
 | |
| //        $customers = $this->googleOAuthService->getGoogleAdCustomers($options);
 | |
|         $customers = $this->bpsAdAccountService->getGoogleAdAccounts($options);
 | |
|         foreach ($customers as $customer) {
 | |
|             if ($customer['login_customer_id'] > 0) {
 | |
|                 Redis::send($queue, $customer, rand(1, 10));
 | |
|             }
 | |
|         }
 | |
|         return self::event . ' send queue ok';
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * get assets
 | |
|      * @throws ApiException
 | |
|      */
 | |
|     public function getAssets($customer)
 | |
|     {
 | |
|         $googleAdsAssetService = new GoogleAdsAssetService($customer['account_id']);
 | |
|         if ($customer['login_customer_id'] > 0) {
 | |
|             $resourceName = $googleAdsAssetService->runListAssets($customer['account_id'], $customer);
 | |
|         }
 | |
| //        return $this->successResponse(['ads_list' => $resourceName]);
 | |
|     }
 | |
| 
 | |
|     // 可以加入一些公共方法
 | |
|     protected function successResponse($data): Response
 | |
|     {
 | |
|         return Json([
 | |
|             'code' => 0,
 | |
|             'msg' => 'ok',
 | |
|             'data' => $data,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     protected function errorResponse($code, $message, $data = []): Response
 | |
|     {
 | |
|         return Json([
 | |
|             'code' => $code,
 | |
|             'msg' => $message ?: 'error',
 | |
|             'data' => $data
 | |
|         ]);
 | |
|     }
 | |
| }
 | 
