webman_ad/app/event/GoogleAdsDateDatas.php

102 lines
2.6 KiB
PHP

<?php
namespace app\event;
use app\service\GoogleAdsCampaignService;
use app\service\GoogleOAuthService;
use Google\ApiCore\ApiException;
use support\Response;
use DI\Annotation\Inject;
use Webman\RedisQueue\Redis;
use Webman\RedisQueue\Client;
//use QL\QueryList;
class GoogleAdsDateDatas
{
/**
* @Inject
* @var GoogleOAuthService
*/
private $googleOAuthService;
const event = 'googleads:datedatas:event';
const queue = 'googleads:datedatas:queue';
const task = 'googleads:datedatas:task';
public function syncDateDatas($options = [])
{
$queue = self::queue;
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
foreach ($customers as $customer) {
if ($customer['login_customer_id'] > 0) {
$customer['date'] = $options['date'];
Redis::send($queue, $customer, rand(1, 10));
}
}
//同步消息到同步任务表
// $queueTask = self::task;
// $taskInfo = [
// 'ecommerce' => 1001,
// 'ecommerce_shop_id' => $options['date'],
// 'task_type' => 'InsightsMerge',
// 'remain' => 1
// ];
// Client::send($queueTask, $taskInfo, 30);
return self::event . ' send queue ok';
}
/**
* get date datas
* @throws ApiException
*/
public function getDateDatas($customer)
{
if ($customer['login_customer_id'] > 0 && ((isset($customer['manager']) && $customer['manager'] === false))) {
// dump($customer);
$googleAdsCampaignService = new googleAdsCampaignService($customer['customer_id']);
// dump($customer['customer_id'],$customer, $options['date']);
$googleAdsCampaignService->runListDateDatas($customer['customer_id'], $customer, $customer['date']);
}
// $this->googleAdsCampaignService->runListDateDatas($options['customer_id'], $options['date']);
// return $this->successResponse(['data' => $resourceName]);
}
/**
* 通知到同步task todo
* @throws ApiException
*/
public function noticeDateDatas($taskInfo)
{
}
// 可以加入一些公共方法
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
]);
}
}