webman_ad/app/event/GoogleAdsAssetRelations.php
huangguancheng 13107526fe 调试
2025-02-10 17:04:19 +08:00

89 lines
2.4 KiB
PHP

<?php
namespace app\event;
use app\service\GoogleAdsAssetRelationService;
use app\service\GoogleOAuthService;
use Google\ApiCore\ApiException;
use support\Response;
use DI\Annotation\Inject;
//use QL\QueryList;
use Webman\RedisQueue\Redis;
class GoogleAdsAssetRelations
{
/**
* @Inject
* @var GoogleOAuthService
*/
private $googleOAuthService;
const event = 'googleads:assetrelations:event';
const queue = 'googleads:assetrelations:queue';
const video_queue = 'googleads:assetrelations:video_queue';
public function syncAssetRelations($options = [])
{
$queue = self::queue;
$video_queue = self::video_queue;
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
// dump($customers);
foreach ($customers as $customer) {
if ($customer['login_customer_id'] > 0) {
Redis::send($queue, $customer,rand(5,15));
Redis::send($video_queue, $customer,rand(5,15));
}
}
return self::event.' send queue ok';
}
/**
* get asset relations
* @throws ApiException
*/
public function getAssetRelations($customer)
{
if ($customer['login_customer_id'] > 0) {
$googleAdsAssetRelationService = new GoogleAdsAssetRelationService($customer['customer_id']);
$resourceName = $googleAdsAssetRelationService->runListAssetRelations($customer['customer_id']);
}
// return $this->successResponse(['ads_list' => $resourceName]);
}
/**
* get asset relations
* @throws ApiException
*/
public function getVideoAssetRelations($customer)
{
$googleAdsAssetRelationService = new GoogleAdsAssetRelationService($customer['customer_id']);
$resourceName = $googleAdsAssetRelationService->runListVideoAssetRelations($customer['customer_id']);
// 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
]);
}
}