74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace app\event;
|
|
|
|
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;
|
|
|
|
const event = 'googleads:assets:event';
|
|
const queue = 'googleads:assets:queue';
|
|
|
|
public function syncAssets($options = [])
|
|
{
|
|
$queue = self::queue;
|
|
$customers = $this->googleOAuthService->getGoogleAdCustomers($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['customer_id']);
|
|
if ($customer['login_customer_id'] >0){
|
|
$resourceName = $googleAdsAssetService->runListAssets($customer['customer_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
|
|
]);
|
|
}
|
|
}
|