授权绑定就采集数据
This commit is contained in:
parent
cf23c31975
commit
7fa9118f2f
@ -29,16 +29,16 @@ class GoogleAdsAds
|
||||
const queue = 'googleads:ads:queue';
|
||||
|
||||
|
||||
public function syncAds()
|
||||
public function syncAds($options = [])
|
||||
{
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
Redis::send($queue, $customer);
|
||||
Redis::send($queue, $customer,rand(1,10));
|
||||
}
|
||||
}
|
||||
return 'ads redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,18 +26,18 @@ class GoogleAdsAssetRelations
|
||||
const queue = 'googleads:assetrelations:queue';
|
||||
const video_queue = 'googleads:assetrelations:video_queue';
|
||||
|
||||
public function syncAssetRelations()
|
||||
public function syncAssetRelations($options = [])
|
||||
{
|
||||
$queue = self::queue;
|
||||
$video_queue = self::video_queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
Redis::send($queue, $customer);
|
||||
Redis::send($video_queue, $customer);
|
||||
Redis::send($queue, $customer,rand(5,15));
|
||||
Redis::send($video_queue, $customer,rand(5,15));
|
||||
}
|
||||
}
|
||||
return 'assets redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,16 +27,16 @@ class GoogleAdsAssets
|
||||
const event = 'googleads:assets:event';
|
||||
const queue = 'googleads:assets:queue';
|
||||
|
||||
public function syncAssets()
|
||||
public function syncAssets($options = [])
|
||||
{
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
Redis::send($queue, $customer);
|
||||
Redis::send($queue, $customer,rand(1,10));
|
||||
}
|
||||
}
|
||||
return 'assets redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,9 +5,6 @@ namespace app\event;
|
||||
use app\service\GoogleAdsCampaignService;
|
||||
use app\service\GoogleOAuthService;
|
||||
use Google\ApiCore\ApiException;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use support\Db;
|
||||
use support\Response;
|
||||
use DI\Annotation\Inject;
|
||||
use Webman\RedisQueue\Redis;
|
||||
@ -28,16 +25,16 @@ class GoogleAdsCampaigns
|
||||
const event = 'googleads:campaigns:event';
|
||||
const queue = 'googleads:campaigns:queue';
|
||||
|
||||
public function syncCampaigns()
|
||||
public function syncCampaigns($options = []): string
|
||||
{
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] >0){
|
||||
Redis::send($queue,$customer);
|
||||
Redis::send($queue,$customer,rand(1,10));
|
||||
}
|
||||
}
|
||||
return 'redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,8 +5,6 @@ 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;
|
||||
@ -27,17 +25,17 @@ class GoogleAdsDateDatas
|
||||
const event = 'googleads:datedatas:event';
|
||||
const queue = 'googleads:datedatas:queue';
|
||||
|
||||
public function syncDateDatas($options)
|
||||
public function syncDateDatas($options = [])
|
||||
{
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
$customer['date'] = $options['date'];
|
||||
Redis::send($queue, $customer);
|
||||
Redis::send($queue, $customer,rand(1,10));
|
||||
}
|
||||
}
|
||||
return 'redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,8 +10,8 @@ use Google\ApiCore\ApiException;
|
||||
use support\Response;
|
||||
use DI\Annotation\Inject;
|
||||
use Webman\RedisQueue\Redis;
|
||||
//use QL\QueryList;
|
||||
|
||||
//use QL\QueryList;
|
||||
|
||||
|
||||
class GoogleAdsGroups
|
||||
@ -28,16 +28,16 @@ class GoogleAdsGroups
|
||||
const queue = 'googleads:groups:queue';
|
||||
|
||||
|
||||
public function syncGroups()
|
||||
public function syncGroups($options = [])
|
||||
{
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
|
||||
$queue = self::queue;
|
||||
$customers = $this->googleOAuthService->getGoogleAdCustomers($options);
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer['login_customer_id'] >0){
|
||||
Redis::send($queue,$customer);
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
Redis::send($queue,$customer,rand(1,10));
|
||||
}
|
||||
}
|
||||
return 'redis queue ok';
|
||||
return self::event.' send queue ok';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,31 +47,31 @@ class GoogleAdsGroups
|
||||
public function getGroups($customer)
|
||||
{
|
||||
|
||||
$googleAdsGroupService = new GoogleAdsGroupService($customer['customer_id']);
|
||||
if ($customer['login_customer_id'] >0){
|
||||
$resourceName = $googleAdsGroupService->runListGroups($customer['customer_id'],$customer);
|
||||
}
|
||||
$googleAdsGroupService = new GoogleAdsGroupService($customer['customer_id']);
|
||||
if ($customer['login_customer_id'] > 0) {
|
||||
$resourceName = $googleAdsGroupService->runListGroups($customer['customer_id'], $customer);
|
||||
}
|
||||
// return $this->successResponse(['groups_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
|
||||
]);
|
||||
}
|
||||
// 可以加入一些公共方法
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,12 @@
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\event\GoogleAdsCustomers;
|
||||
use app\event\GoogleAdsCampaigns;
|
||||
use app\event\GoogleAdsGroups;
|
||||
use app\event\GoogleAdsAds;
|
||||
use app\event\GoogleAdsAssets;
|
||||
use app\event\GoogleAdsDateDatas;
|
||||
use app\event\GoogleAdsAssetRelations;
|
||||
use Webman\Event\Event;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
@ -17,10 +23,29 @@ class GoogleAdsCustomerQueue implements Consumer
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
dump($this->queue.' consumed',$data);
|
||||
dump($this->queue . ' consumed', $data);
|
||||
//新绑定的客户,立即同步广告系列
|
||||
|
||||
Event::emit(GoogleAdsCustomers::add_queue, $data);
|
||||
// 无需反序列化
|
||||
// var_export($data); // 输出 ['to' => 'tom@gmail.com', 'content' => 'hello']
|
||||
Event::emit(GoogleAdsCampaigns::event, $data);
|
||||
|
||||
//新绑定的客户,立即同步广告组
|
||||
Event::emit(GoogleAdsGroups::event, $data);
|
||||
//新绑定的客户,立即同步广告
|
||||
Event::emit(GoogleAdsAds::event, $data);
|
||||
//新绑定的客户,立即同步素材库
|
||||
Event::emit(GoogleAdsAssets::event, $data);
|
||||
//新绑定的客户,立即同步素材关系绑定
|
||||
Event::emit(GoogleAdsAssetRelations::event, $data);
|
||||
//新绑定的客户,立即同步最近3天的广告报表
|
||||
$data['date'] = date('Y-m-d', strtotime('-2 day'));
|
||||
Event::emit(GoogleAdsDateDatas::event, $data);
|
||||
$data['date'] = date('Y-m-d', strtotime('-1 day'));
|
||||
Event::emit(GoogleAdsDateDatas::event, $data);
|
||||
$data['date'] = date('Y-m-d', strtotime('0 day'));
|
||||
Event::emit(GoogleAdsDateDatas::event, $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user