Commit 27516d79 by Vladislav

#19496 Запрос измененных объявлений

1 parent 7be069a6
......@@ -83,7 +83,7 @@ class AdvertisementsAdd extends Command
'advertisements.title2 as title2',
'advertisements.href as href',
'advertisements.display_url_path as display_url_path',
'advertisements.v_card_id as v_card_id',
'advertisements.v_card_external_id as v_card_external_id',
'advertisements.ad_image_hash as ad_image_hash',
'advertisements.site_link_set_id as site_link_set_id',
DB::raw('JSON_ARRAYAGG(goal_ad_extensions.external_id) as ad_extension_ids'),
......
......@@ -73,7 +73,7 @@ class AdvertisementsUpdate extends Command
'advertisements.title2 as title2',
'advertisements.href as href',
'advertisements.display_url_path as display_url_path',
'advertisements.v_card_id as v_card_id',
'advertisements.v_card_external_id as v_card_external_id',
'advertisements.ad_image_hash as ad_image_hash',
'advertisements.site_link_set_id as site_link_set_id',
DB::raw("JSON_OBJECTAGG('AdExtensionId', goal_ad_extensions.external_id, 'Operation', 'SET') as ad_extensions"),
......
......@@ -167,13 +167,15 @@ class DictionaryCampaignsSyncByCampaign extends Command
//грузим объявления которых по какой то причне нет в целевых.
DB::insert("
INSERT INTO goal_advertisements(dictionary_campaign_external_id, goal_ad_group_external_id, dictionary_campaign_id,
goal_ad_group_id, advertisement_id, created_at, updated_at)
SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, ad.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
goal_ad_group_id, advertisement_id, goal_v_card_id, goal_v_card_external_id, created_at, updated_at)
SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, ad.id, gvc.id, gvc.external_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM advertisements ad
INNER JOIN ad_groups ag on ad.ad_group_id = ag.id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
LEFT JOIN goal_advertisements gad on ad.id = gad.advertisement_id AND gad.goal_ad_group_id=gag.id
WHERE gad.advertisement_id is null and ad.campaign_id is not null
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id
LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gag.dictionary_campaign_id = gvc.dictionary_campaign_id
WHERE gad.advertisement_id is null and ad.campaign_id is not null
");
//грузим связь объевлений к расширения которых по какой то причне нет в целевых.
......
......@@ -83,7 +83,7 @@ class Advertisement extends Model
'mobile',
'display_domain',
'display_url_path',
'v_card_id',
'v_card_external_id',
'ad_image_hash',
'site_link_set_id',
'display_url_path_moderation',
......@@ -128,7 +128,7 @@ class Advertisement extends Model
'text',
'href',
'display_url_path',
'v_card_id',
'v_card_external_id',
'ad_image_hash',
'site_link_set_id',
'ad_extensions',
......
......@@ -12,9 +12,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
*
* @property int $id
* @property int|null $external_id
* @property int|null $goal_v_card_external_id
* @property int|null $dictionary_campaign_external_id
* @property int|null $goal_ad_group_external_id
* @property int $dictionary_campaign_id
* @property int|null $goal_v_card_id
* @property int $goal_ad_group_id
* @property int $advertisement_id
* @property \Illuminate\Support\Carbon|null $external_upload_at
......@@ -53,8 +55,10 @@ class GoalAdvertisement extends Pivot
protected $fillable = [
'external_id',
'goal_v_card_external_id',
'goal_ad_group_external_id',
'dictionary_campaign_external_id',
'goal_v_card_id',
'goal_ad_group_id',
'dictionary_campaign_id',
'advertisement_id',
......@@ -80,8 +84,10 @@ class GoalAdvertisement extends Pivot
return [
'id',
'external_id',
'goal_v_card_external_id',
'goal_ad_group_external_id',
'dictionary_campaign_external_id',
'goal_v_card_id',
'goal_ad_group_id',
'dictionary_campaign_id',
'advertisement_id',
......@@ -148,6 +154,11 @@ class GoalAdvertisement extends Pivot
return $this->belongsTo(DictionaryCampaign::class, 'dictionary_campaign_id');
}
public function goalVCard()
{
return $this->belongsTo(GoalVCard::class, 'goal_v_card_id');
}
public function goalAdExtensions()
{
return $this->belongsToMany(GoalAdExtension::class, GoalAdvertisementGoalAdExtension::getModel()->getTable(), 'goal_advertisement_id', 'goal_ad_extension_id')
......
......@@ -2,7 +2,7 @@
namespace App\Models;
use App\Models\Pivots\GoalNegativeKeywordSharedSet;
use App\Models\Pivots\GoalAdvertisement;
use App\Models\Pivots\GoalVCard;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
......@@ -72,4 +72,9 @@ class VCard extends Model
return $this->hasMany(GoalVCard::class, 'v_card_id');
}
public function goalAdvertisement()
{
return $this->hasMany(GoalAdvertisement::class, 'v_card_id');
}
}
......@@ -146,8 +146,8 @@ class AddAds extends DirectRequest
$data['TextAd']['DisplayUrlPath'] = $goalAdvertisement->display_url_path;
}
if ($goalAdvertisement->v_card_id) {
$data['TextAd']['VCardId'] = $goalAdvertisement->v_card_id;
if ($goalAdvertisement->v_card_external_id) {
$data['TextAd']['VCardId'] = $goalAdvertisement->v_card_external_id;
}
if ($goalAdvertisement->ad_image_hash) {
......
......@@ -80,6 +80,10 @@ class AddVCards extends DirectRequest
'reserve_create_at' => null,
]);
$goalVCard->goalAdvertisement()->update([
''
]);
}
} catch (\Exception $e) {
Log::debug($e);
......
......@@ -122,7 +122,7 @@ class GetAds extends DirectRequest
'mobile' => $ad['TextAd']['Mobile'] === 'YES',
'display_domain' => $ad['TextAd']['DisplayDomain'],
'display_url_path' => $ad['TextAd']['DisplayUrlPath'],
'v_card_id' => $ad['TextAd']['VCardId'],
'v_card_external_id' => $ad['TextAd']['VCardId'],
'ad_image_hash' => $ad['TextAd']['AdImageHash'],
'site_link_set_id' => $ad['TextAd']['SitelinkSetId'],
'display_url_path_moderation' => $ad['TextAd']['DisplayUrlPathModeration'],
......
......@@ -130,8 +130,8 @@ class UpdateAds extends DirectRequest
$data['TextAd']['DisplayUrlPath'] = StrReplaceByVariables::getInstance($goalAdvertisement->display_url_path, $list)->get();
}
if ($goalAdvertisement->v_card_id) {
$data['TextAd']['VCardId'] = $goalAdvertisement->v_card_id;
if ($goalAdvertisement->v_card_external_id) {
$data['TextAd']['VCardId'] = $goalAdvertisement->v_card_external_id;
}
if ($goalAdvertisement->ad_image_hash) {
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeAdvertisementsColumnVCardId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('advertisements', function (Blueprint $table) {
$table->renameColumn('v_card_id', 'v_card_external_id');
});
Schema::table('goal_advertisements', function (Blueprint $table) {
$table->bigInteger('goal_v_card_id')->nullable();
$table->bigInteger('goal_v_card_external_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!