update
This commit is contained in:
parent
d35f926f8b
commit
1b38f977ec
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\model\GoogleAdsAsset;
|
||||
use app\model\GoogleAdsAd;
|
||||
use app\model\GoogleAdsAssetRelations;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class SyncGoogleAdsAsset extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sync:google_ads_asset')
|
||||
->setDescription('Synchronize Google Ads Asset relations');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// 获取所有素材
|
||||
$assets = GoogleAdsAsset::where('status', 1)->select();
|
||||
|
||||
foreach ($assets as $asset) {
|
||||
// 获取广告表中的所有广告
|
||||
$ads = GoogleAdsAd::where('status', 1)->select();
|
||||
|
||||
foreach ($ads as $ad) {
|
||||
// 检查广告的 metadata 是否包含素材的 resource_name
|
||||
if (isset($ad->metadata) && strpos($ad->metadata, $asset->resource_name) !== false) {
|
||||
// 插入关联记录
|
||||
$existingRelation = GoogleAdsAssetRelations::where('asset_id', $asset->asset_id)
|
||||
->where('ad_id', $ad->ad_id)
|
||||
->where('date', date('Y-m-d'))
|
||||
->find();
|
||||
|
||||
if (!$existingRelation) {
|
||||
// 如果没有现有记录,则插入新的关联
|
||||
GoogleAdsAssetRelations::create([
|
||||
'asset_id' => $asset->asset_id,
|
||||
'ad_id' => $ad->ad_id,
|
||||
'ad_group_id' => $ad->ad_group_id,
|
||||
'campaign_id' => $ad->campaign_id,
|
||||
'date' => date('Y-m-d')
|
||||
]);
|
||||
|
||||
$output->writeln("Inserted relation for Asset ID: {$asset->asset_id} and Ad ID: {$ad->ad_id}");
|
||||
} else {
|
||||
$output->writeln("Relation already exists for Asset ID: {$asset->asset_id} and Ad ID: {$ad->ad_id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('Google Ads Asset synchronization completed.');
|
||||
}
|
||||
}
|
@ -45,7 +45,8 @@
|
||||
"firebase/php-jwt": "^6.10",
|
||||
"spiral/roadrunner-cli": "^2.6",
|
||||
"spiral/roadrunner-grpc": "^3.4",
|
||||
"webman/redis-queue": "^1.3"
|
||||
"webman/redis-queue": "^1.3",
|
||||
"webman/console": "^v1.2.35"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-event": "For better performance. "
|
||||
|
55
composer.lock
generated
55
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c99bb5201649417c649c7a5fb8b36d3a",
|
||||
"content-hash": "cd3b1caf96f62b54bf6f76861680b014",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -5623,6 +5623,59 @@
|
||||
},
|
||||
"time": "2022-08-18T12:14:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/console",
|
||||
"version": "v1.3.15",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/webman-php/console.git",
|
||||
"reference": "edadb1906e55c050fa8b5cadd20ee8a95599e13f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/webman-php/console/zipball/edadb1906e55c050fa8b5cadd20ee8a95599e13f",
|
||||
"reference": "edadb1906e55c050fa8b5cadd20ee8a95599e13f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/inflector": "^2.0",
|
||||
"symfony/console": ">=5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"workerman/webman": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\Console\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "walkor",
|
||||
"email": "walkor@workerman.net",
|
||||
"homepage": "http://www.workerman.net",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Webman console",
|
||||
"homepage": "http://www.workerman.net",
|
||||
"keywords": [
|
||||
"webman console"
|
||||
],
|
||||
"support": {
|
||||
"email": "walkor@workerman.net",
|
||||
"forum": "http://www.workerman.net/questions",
|
||||
"issues": "https://github.com/webman-php/console/issues",
|
||||
"source": "https://github.com/webman-php/console",
|
||||
"wiki": "http://www.workerman.net/doc/webman"
|
||||
},
|
||||
"time": "2025-01-07T06:44:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/event",
|
||||
"version": "v1.0.5",
|
||||
|
Loading…
Reference in New Issue
Block a user