更新采集数据功能

This commit is contained in:
hgc 2024-12-24 19:51:13 +08:00
parent 1f1d7b9bd1
commit 91f1af5c06
4 changed files with 54 additions and 30 deletions

View File

@ -7,6 +7,11 @@ use support\Request;
use support\Response; use support\Response;
use DI\Annotation\Inject; use DI\Annotation\Inject;
use app\model\ThirdUserAdvertiser; use app\model\ThirdUserAdvertiser;
use app\event\GoogleAdsCampaigns;
use app\event\GoogleAdsGroups;
use app\event\GoogleAdsAds;
use app\event\GoogleAdsDateDatas;
use Webman\Event\Event;
class OAuthController class OAuthController
{ {
@ -105,8 +110,24 @@ class OAuthController
public function testRefreshToken(Request $request) public function testRefreshToken(Request $request)
{ {
$customers = $this->googleOAuthService->getGoogleAdCustomers([]);
return $this->successResponse(['data' => $customers]); //发布事件
// $dayBeforeYesterdayStart = date('Y-m-d', strtotime('-2 day'));
// dump($dayBeforeYesterdayStart . '更新' . GoogleAdsDateDatas::type . '开始');
// Event::emit(GoogleAdsDateDatas::type, ['date' => $dayBeforeYesterdayStart]);
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始');
// Event::emit(GoogleAdsCampaigns::type, []);
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsGroups::type . '开始');
// Event::emit(GoogleAdsGroups::type, []);
dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAds::type . '开始');
Event::emit(GoogleAdsAds::type, []);
return $this->successResponse(['data' => []]);
// $customers = $this->googleOAuthService->getGoogleAdCustomers([]);
// return $this->successResponse(['data' => $customers]);
// $list = ThinkDb::table('bps.bps_third_user')->where('third_type', 'google')->select(); // $list = ThinkDb::table('bps.bps_third_user')->where('third_type', 'google')->select();

View File

@ -61,7 +61,7 @@ class GoogleAdsGroups
foreach ($customers as $customerId) { foreach ($customers as $customerId) {
$googleAdsGroupService = new GoogleAdsGroupService($customerId); $googleAdsGroupService = new GoogleAdsGroupService($customerId);
$resourceName = $googleAdsGroupService->runListGroups($options['customer_id']); $resourceName = $googleAdsGroupService->runListGroups($customerId);
// return $this->successResponse(['groups_list' => $resourceName]); // return $this->successResponse(['groups_list' => $resourceName]);
} }

View File

@ -21,56 +21,56 @@ class UpdateGoogleAdsTask
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('10 */1 * * * *', function () { new Crontab('10 */15 * * * *', function () {
// $dayBeforeYesterdayStart = date('Y-m-d', strtotime('-2 day')); $dayBeforeYesterdayStart = date('Y-m-d', strtotime('-2 day'));
// dump($dayBeforeYesterdayStart . '更新' . GoogleAdsDateDatas::type . '开始'); dump($dayBeforeYesterdayStart . '更新' . GoogleAdsDateDatas::type . '开始');
// Event::emit(GoogleAdsDateDatas::type, ['date' => $dayBeforeYesterdayStart]); Event::emit(GoogleAdsDateDatas::type, ['date' => $dayBeforeYesterdayStart]);
} }
); );
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('20 */1 * * * *', function () { new Crontab('20 */15 * * * *', function () {
// $yesterdayStart = date('Y-m-d', strtotime('-1 day')); $yesterdayStart = date('Y-m-d', strtotime('-1 day'));
// dump($yesterdayStart . '更新' . GoogleAdsDateDatas::type . '开始'); dump($yesterdayStart . '更新' . GoogleAdsDateDatas::type . '开始');
// Event::emit(GoogleAdsDateDatas::type, ['date' => $yesterdayStart]); Event::emit(GoogleAdsDateDatas::type, ['date' => $yesterdayStart]);
} }
); );
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('30 */1 * * * *', function () { new Crontab('30 */15 * * * *', function () {
//获取今天的 0 点的YYYY-MM-DD格式 //获取今天的 0 点的YYYY-MM-DD格式
// $todayStart = date('Y-m-d', strtotime('0 day')); $todayStart = date('Y-m-d', strtotime('0 day'));
// dump($todayStart . '更新' . GoogleAdsDateDatas::type . '开始'); dump($todayStart . '更新' . GoogleAdsDateDatas::type . '开始');
// Event::emit(GoogleAdsDateDatas::type, ['date' => $todayStart]); Event::emit(GoogleAdsDateDatas::type, ['date' => $todayStart]);
} }
); );
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('40 */1 * * * *', function () { new Crontab('40 */15 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始'); dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始');
// Event::emit(GoogleAdsCampaigns::type, ['customer_id'=>4060397299]); Event::emit(GoogleAdsCampaigns::type, []);
} }
); );
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('50 */1 * * * *', function () { new Crontab('50 */15 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsGroups::type . '开始'); dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsGroups::type . '开始');
// Event::emit(GoogleAdsGroups::type, ['customer_id'=>4060397299]); Event::emit(GoogleAdsGroups::type, []);
} }
); );
// 每15分钟执行一次 // 每15分钟执行一次
new Crontab('55 */1 * * * *', function () { new Crontab('55 */15 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAds::type . '开始'); dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsAds::type . '开始');
// Event::emit(GoogleAdsAds::type, ['customer_id'=>4060397299]); Event::emit(GoogleAdsAds::type, []);
} }
); );
// 每2分钟执行一次 // 每15分钟执行一次
new Crontab('0 */1 * * * *', function () { new Crontab('58 */15 * * * *', function () {
// dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始'); dump(date('Y-m-d H:i:s') . '更新' . GoogleAdsCampaigns::type . '开始');
// Event::emit(GoogleAdsCampaigns::type, ['customer_id'=>4060397299]); Event::emit(GoogleAdsCampaigns::type, ['customer_id'=>4060397299]);
}); });

View File

@ -122,11 +122,12 @@ class GoogleAdsAdService extends BaseService
$tableName = getenv('DB_PG_SCHEMA') ? getenv('DB_PG_SCHEMA') . '.' . $tableName : 'public' . $tableName; $tableName = getenv('DB_PG_SCHEMA') ? getenv('DB_PG_SCHEMA') . '.' . $tableName : 'public' . $tableName;
foreach ($groupadsResourceName as $data) { foreach ($groupadsResourceName as $data) {
$sql = "INSERT INTO {$tableName} $sql = "INSERT INTO {$tableName}
(ad_id, ad_group_id, customer_id, ad_name, status, resource_name) (ad_id, ad_group_id, campaign_id,customer_id, ad_name, status, resource_name)
VALUES (:ad_id, :ad_group_id, :customer_id, :ad_name, :status, :resource_name) VALUES (:ad_id, :ad_group_id,:campaign_id, :customer_id, :ad_name, :status, :resource_name)
ON CONFLICT (ad_id) ON CONFLICT (ad_id)
DO UPDATE SET DO UPDATE SET
ad_group_id = EXCLUDED.ad_group_id, ad_group_id = EXCLUDED.ad_group_id,
campaign_id = EXCLUDED.campaign_id,
customer_id = EXCLUDED.customer_id, customer_id = EXCLUDED.customer_id,
ad_name = EXCLUDED.ad_name, ad_name = EXCLUDED.ad_name,
status = EXCLUDED.status, status = EXCLUDED.status,
@ -155,6 +156,7 @@ class GoogleAdsAdService extends BaseService
$query = "SELECT $query = "SELECT
ad_group_ad.ad.id, ad_group_ad.ad.id,
ad_group.id, ad_group.id,
campaign.id,
customer.id, customer.id,
ad_group_ad.ad.name, ad_group_ad.ad.name,
ad_group_ad.status, ad_group_ad.status,
@ -179,6 +181,7 @@ class GoogleAdsAdService extends BaseService
$resourceName['ad_id'] = $googleAdsRow->getAdGroupAd()->getAd()->getId(); $resourceName['ad_id'] = $googleAdsRow->getAdGroupAd()->getAd()->getId();
$resourceName['ad_name'] = $googleAdsRow->getAdGroupAd()->getAd()->getName(); $resourceName['ad_name'] = $googleAdsRow->getAdGroupAd()->getAd()->getName();
$resourceName['ad_group_id'] = $googleAdsRow->getAdGroup()->getId(); $resourceName['ad_group_id'] = $googleAdsRow->getAdGroup()->getId();
$resourceName['campaign_id'] = $googleAdsRow->getCampaign()->getId();
$resourceName['customer_id'] = $googleAdsRow->getCustomer()->getId(); $resourceName['customer_id'] = $googleAdsRow->getCustomer()->getId();
// $resourceName['final_urls'] = $finalUrlsArray; // $resourceName['final_urls'] = $finalUrlsArray;
$resourceName['status'] = $googleAdsRow->getAdGroupAd()->getStatus(); $resourceName['status'] = $googleAdsRow->getAdGroupAd()->getStatus();