Commit 295f4037 by Vladislav

#21624 Наборы ссылок, связать с рк, обновление (Связь наборы ссылок с рк)

1 parent eed479dd
......@@ -136,11 +136,13 @@ class DictionaryCampaignsSyncByCampaign extends Command
//грузим расширения которых по какой то причне нет в целевых.
DB::insert("
INSERT INTO goal_sitelinks(sitelink_id, token_id, created_at, updated_at)
SELECT s.id, t.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
INSERT INTO goal_sitelinks(sitelink_id, token_id, dictionary_campaign_id, created_at, updated_at)
SELECT s.id, t.id, dc.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM sitelinks s
INNER JOIN tokens t on t.type != '" . Tokens::MAIN . "'
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and t.id = gs.token_id AND gs.deleted_at is null
INNER JOIN dictionaries d on t.id = d.token_id
INNER JOIN dictionary_campaigns dc on dc.dictionary_id = d.id AND dc.deleted_at is null
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and t.id = gs.token_id AND gs.dictionary_campaign_id = dc.id AND gs.deleted_at is null
WHERE gs.sitelink_id is null AND s.deleted_at is null
");
$this->info('goal_sitelinks successful!');
......@@ -169,7 +171,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id AND vc.deleted_at is null
LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gag.dictionary_campaign_id = gvc.dictionary_campaign_id and gvc.deleted_at is null
LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id AND s.deleted_at is null
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.deleted_at is null
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.dictionary_campaign_id = gag.dictionary_campaign_id AND gs.deleted_at is null
WHERE ad.deleted_at is null AND gad.advertisement_id is null and ad.state != '" . Advertisement::STATE_ARCHIVED . "' and ad.archived_need is null and ad.campaign_id is not null
and (ad.sitelink_external_id is null or (ad.sitelink_external_id is not null and s.id is not null))
and (ad.v_card_external_id is null or (ad.v_card_external_id is not null and vc.id is not null))
......@@ -189,7 +191,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
// LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id AND vc.deleted_at is null
// LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gad.dictionary_campaign_id = gvc.dictionary_campaign_id
// LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id AND s.deleted_at is null
// LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.deleted_at is null
// LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.dictionary_campaign_id = gad.dictionary_campaign_id AND gs.deleted_at is null
//
//
// SET gad.goal_v_card_id = gvc.id,
......@@ -227,7 +229,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id AND vc.deleted_at is null
LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gad.dictionary_campaign_id = gvc.dictionary_campaign_id and gvc.deleted_at is null
LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id AND s.deleted_at is null
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.deleted_at is null
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id AND gs.dictionary_campaign_id = gad.dictionary_campaign_id AND gs.deleted_at is null
SET gad.goal_v_card_id = gvc.id,
......
......@@ -58,12 +58,12 @@ class SitelinksAdd extends Command
$goalSitelinks = $token->goalSitelinksForNotExternalForNotReserveCreate;
// foreach (array_chunk($goalSitelinks->pluck('id')->toArray(), 100) as $items) {
// GoalSitelink::whereIn('id', $items)
// ->update([
// 'reserve_create_at' => Carbon::now(),
// ]);
// }
foreach (array_chunk($goalSitelinks->pluck('id')->toArray(), 100) as $items) {
GoalSitelink::whereIn('id', $items)
->update([
'reserve_create_at' => Carbon::now(),
]);
}
$request = new AddSitelinks();
$request->setToken($token)
......
......@@ -97,23 +97,27 @@ class GoalAudienceTarget extends Pivot
*/
public function scopeNeedDeleted($query)
{
return $query->forExternal()->whereExists(function (\Illuminate\Database\Query\Builder $query) {
$query->select(DB::raw(1))
->from('goal_ad_groups')
->join('ad_groups', 'goal_ad_groups.ad_group_id', '=', 'ad_groups.id')
->join('goal_retargetinglists', 'goal_audience_targets.goal_retargetinglist_id', '=', 'goal_retargetinglists.id')
->join('retargetinglists', 'goal_retargetinglists.retargetinglist_id', '=', 'retargetinglists.id')
->where(function ($query) {
$query->where(function ($query) {
return $query->forExternal()->where(function (\Illuminate\Database\Eloquent\Builder $query) {
$query->whereExists(function (\Illuminate\Database\Query\Builder $query) {
$query->select(DB::raw(1))
->from('goal_ad_groups')
->join('ad_groups', 'goal_ad_groups.ad_group_id', '=', 'ad_groups.id')
->where(function ($query) {
$query->whereNull('goal_ad_groups.deleted_at')
->whereNotNull('goal_ad_groups.external_id')
->whereNotNull('ad_groups.deleted_at')
->whereColumn('goal_audience_targets.goal_ad_group_id', 'goal_ad_groups.id');
})->orWhere(function ($query) {
});
})->orWhereExists(function (\Illuminate\Database\Query\Builder $query) {
$query->select(DB::raw(1))
->from('goal_retargetinglists')
->join('retargetinglists', 'goal_retargetinglists.retargetinglist_id', '=', 'retargetinglists.id')
->whereColumn('goal_audience_targets.goal_retargetinglist_external_id', 'goal_retargetinglists.external_id')
->where(function ($query) {
$query->whereNotNull('retargetinglists.deleted_at')
->orWhereNotNull('goal_retargetinglists.deleted_at');
});
});
});
});
}
......
......@@ -3,6 +3,7 @@
namespace App\Models\Pivots;
use App\Models\Sitelink;
use App\Models\Tokens;
use App\Models\YandexError;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Pivot;
......@@ -18,6 +19,7 @@ class GoalSitelink extends Pivot
'external_id',
'sitelink_id',
'token_id',
'dictionary_campaign_id',
'external_upload_at',
'external_updated_at',
'updated_need',
......@@ -95,6 +97,16 @@ class GoalSitelink extends Pivot
return $query->whereNotNull('updated_need');
}
public function token()
{
return $this->belongsTo(Tokens::class, 'token_id');
}
public function dictionaryCampaign()
{
return $this->belongsTo(DictionaryCampaign::class, 'dictionary_campaign_id');
}
public function sitelink()
{
return $this->belongsTo(Sitelink::class, 'sitelink_id');
......
......@@ -39,8 +39,6 @@ class DeleteRetargetinglists extends DirectRequest
return;
}
\Log::debug($response);
foreach (DirectResponseHelper::getExternalIdsChunkByResult($response['result']['DeleteResults']) as $external_ids) {
if ($this->getToken()->isMain()) {
Retargetinglist::whereIn('external_id', $external_ids)
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateColumnGoalSitelinksDictionaryCampaignId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('goal_sitelinks', function (Blueprint $table) {
$table->bigInteger('dictionary_campaign_id')->unsigned()->nullable();
$table->foreign('dictionary_campaign_id')->references('id')->on('dictionary_campaigns')
->cascadeOnDelete();
});
foreach(\App\Models\Pivots\GoalSitelink::with('token')->whereNull('dictionary_campaign_id')->get() as $goal_sitelink) {
$goal_sitelink->dictionaryCampaign()->associate($goal_sitelink->token->dictionaryCampaigns()->orderBy('id', 'ASC')->first());
$goal_sitelink->save();
}
Schema::table('goal_sitelinks', function (Blueprint $table) {
$table->bigInteger('dictionary_campaign_id')->unsigned()->nullable(false)->change();
});
}
/**
* 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!