<?php namespace app\process; use app\event\GoogleAdsCampaigns; use app\event\GoogleAdsCreatives; use app\event\GoogleAdsCustomers; use app\event\GoogleAdsGroups; use app\event\GoogleAdsAds; use app\event\GoogleAdsAssets; use app\event\GoogleAdsAssetRelations; use app\event\GoogleAdsDateDatas; use app\event\ShopifyOrders; use Webman\Event\Event; use Workerman\Crontab\Crontab; /** * 更新热搜列表任务 */ class UpdateGoogleAdsTask { //错开时间执行,否则固定时间段接口会响应很慢 public function onWorkerStart() { define('CURRENT_TIME', date('Y-m-d H:i:s')); // 每15分钟执行一次 new Crontab('2 2 0 * * *', function () { $data = []; $data['endDate'] = date('Y-m-d'); // 获取今天的日期 $data['startDate'] = date('Y-m-d', strtotime('-7 days')); // 获取7天前的日期 dump($data['startDate'] . '到' . $data['endDate'] . '' . '更新' . GoogleAdsDateDatas::event . '开始'); Event::emit(GoogleAdsDateDatas::event, $data); } ); // 每15分钟执行一次 new Crontab('2 5 0 * * *', function () { $data = []; $data['endDate'] = date('Y-m-d'); // 获取今天的日期 $data['startDate'] = date('Y-m-d', strtotime('-7 days')); // 获取7天前的日期 dump($data['startDate'] . '到' . $data['endDate'] . '' . '更新' . GoogleAdsAssetRelations::event . '开始'); Event::emit(GoogleAdsAssetRelations::event, $data); } ); //获取某段时期的数据 // new Crontab('2 */1 * * * *', function () { // $data = []; // $data['endDate'] = '2024-12-22'; // 指定结束日期 // $data['startDate'] = '2024-12-18'; // 指定开始日期 // dump($data['startDate'] . '到' . $data['endDate'] . '' . '更新' . GoogleAdsDateDatas::event . '开始'); // Event::emit(GoogleAdsDateDatas::event, $data); // // } // ); //获取某段时期的数据 // new Crontab('40 */1 * * * *', function () { // $data = []; // $data['endDate'] = '2024-12-22'; // 指定结束日期 // $data['startDate'] = '2024-12-18'; // 指定开始日期 // dump($data['startDate'] . '到' . $data['endDate'] . '' . '更新' . GoogleAdsAssetRelations::event . '开始'); // Event::emit(GoogleAdsAssetRelations::event, $data); // }); // 每15分钟执行一次 new Crontab('30 2 */12 * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsGroups::event . '开始'); Event::emit(GoogleAdsGroups::event, []); dump(CURRENT_TIME . '更新' . GoogleAdsCampaigns::event . '开始'); Event::emit(GoogleAdsCampaigns::event, []); } ); // 每15分钟执行一次 new Crontab('5 2 */12 * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsAds::event . '开始'); Event::emit(GoogleAdsAds::event, []); } ); // 每15分钟执行一次 new Crontab('1 2 */12 * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsCreatives::event . '开始'); Event::emit(GoogleAdsCreatives::event, []); } ); new Crontab('25 11 */12 * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsAssets::event . '开始'); Event::emit(GoogleAdsAssets::event, []); } ); new Crontab('16 */1 * * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsCustomers::event . '开始'); Event::emit(GoogleAdsCustomers::event, []); } ); new Crontab('3 */1 * * * *', function () { dump(CURRENT_TIME . '更新' . GoogleAdsCustomers::newbind_event . '开始'); Event::emit(GoogleAdsCustomers::newbind_event, []); }); //临时调试shopify店铺定时任务 // new Crontab('*/20 * * * * *', function () { // dump(CURRENT_TIME . '更新' . ShopifyOrders::event . '开始'); // Event::emit(ShopifyOrders::event, ['storeName' => 'fefc94-67', 'token' => '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']); // PSA shop // Event::emit(ShopifyOrders::event, ['storeName' => 'aeb0e7-b3', 'token' => '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']);// VIVI shop // } // ); // 每15分钟执行一次 // new Crontab('58 */15 * * * *', function () { // dump(CURRENT_TIME . '更新' . GoogleAdsCampaigns::type . '开始'); // Event::emit(GoogleAdsCampaigns::type, ['customer_id'=>4060397299]); // // }); // 每30分钟执行一次 // new Crontab('0 */30 * * * *', function () { // dump(CURRENT_TIME . '更新' . V2ex::type . '开始'); // Event::emit(V2ex::type, null); // // dump(CURRENT_TIME . '更新' . GitHub::type . '开始'); // Event::emit(GitHub::type, null); // // dump(CURRENT_TIME . '更新' . JueJin::type . '开始'); // Event::emit(JueJin::type, null); // }); } }