Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4d090b7f
authored
Jul 05, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20346 Загрузка наборов минус фраз
1 parent
71665f50
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
409 additions
and
0 deletions
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Commands/NegativeKeywordSharedSetsLoad.php
app/Models/NegativeKeywordSharedSet.php
app/Models/Pivots/GoalNegativeKeywordSharedSet.php
app/Service/Requests/Direct/GetNegativeKeywordSharedSets.php
database/migrations/2021_07_05_131633_create_negative_keyword_shared_sets_table.php
database/migrations/2021_07_05_136255_create_goal_negative_keyword_shared_sets_table.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
4d090b7
...
...
@@ -110,6 +110,16 @@ class DictionaryCampaignsSyncByCampaign extends Command
"
);
}
//грузим наборы минус-фраз которых по какой то причне нет в целевых.
DB
::
insert
(
"
INSERT INTO goal_negative_keyword_shared_sets(negative_keyword_shared_set_id, token_id, created_at, updated_at)
SELECT nkss.id, t.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM negative_keyword_shared_sets nkss
INNER JOIN tokens t on t.type != '"
.
Tokens
::
MAIN
.
"'
LEFT JOIN goal_negative_keyword_shared_sets gnkss on nkss.id = gnkss.negative_keyword_shared_set_id and t.id = gnkss.token_id
WHERE gnkss.id is null and nkss.deleted_at is null
"
);
//грузим группы которых по какой то причне нет в целевых.
DB
::
insert
(
"
INSERT INTO goal_ad_groups(ad_group_id, dictionary_campaign_external_id, dictionary_campaign_id, name, negative_keywords, created_at, updated_at)
...
...
app/Console/Commands/NegativeKeywordSharedSetsLoad.php
0 → 100644
View file @
4d090b7
<?php
namespace
App\Console\Commands
;
use
App\Models\Campaigns
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
class
NegativeKeywordSharedSetsLoad
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'negativekeywordsharedsets:load'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Загрузка наборов минус-фраз'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
* @throws \Exception
*/
public
function
handle
()
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'NegativeKeywordSharedSets'
,
'get'
)
->
call
();
return
0
;
}
}
app/Models/NegativeKeywordSharedSet.php
0 → 100644
View file @
4d090b7
<?php
namespace
App\Models
;
use
App\Models\Pivots\GoalNegativeKeywordSharedSet
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
class
NegativeKeywordSharedSet
extends
Model
{
use
SoftDeletes
;
protected
$table
=
'negative_keyword_shared_sets'
;
protected
$fillable
=
[
'external_id'
,
'name'
,
'negative_keywords'
,
'associated'
,
];
protected
$casts
=
[
'negative_keywords'
=>
'array'
,
'associated'
=>
'boolean'
,
];
/**
* @return Collection
*/
static
public
function
getPropertiesWatch
()
{
return
collect
([
'name'
,
'negative_keywords'
,
]);
}
public
function
goalNegativeKeywordSharedSet
()
{
return
$this
->
hasMany
(
GoalNegativeKeywordSharedSet
::
class
,
'negative_keyword_shared_set_id'
);
}
}
app/Models/Pivots/GoalNegativeKeywordSharedSet.php
0 → 100644
View file @
4d090b7
<?php
namespace
App\Models\Pivots
;
use
App\Models\AdExtension
;
use
App\Models\NegativeKeywordSharedSet
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
class
GoalNegativeKeywordSharedSet
extends
Pivot
{
use
SoftDeletes
;
protected
$table
=
'goal_negative_keyword_shared_sets'
;
protected
$fillable
=
[
'external_id'
,
'negative_keyword_shared_set_id'
,
'token_id'
,
'external_upload_at'
,
'external_updated_at'
,
'updated_need'
,
'reserve_create_at'
,
'reserve_update_at'
,
];
protected
$casts
=
[
'external_upload_at'
=>
'datetime'
,
'external_updated_at'
=>
'datetime'
,
'updated_need'
=>
'datetime'
,
'reserve_create_at'
=>
'datetime'
,
'reserve_update_at'
=>
'datetime'
,
];
public
$incrementing
=
true
;
static
public
function
getWithPivot
()
{
return
[
'id'
,
'external_id'
,
'negative_keyword_shared_set_id'
,
'token_id'
,
'external_upload_at'
,
'external_updated_at'
,
'updated_need'
,
'reserve_create_at'
,
'reserve_update_at'
,
];
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForExternal
(
$query
)
{
return
$query
->
whereNotNull
(
'external_id'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotExternal
(
$query
)
{
return
$query
->
whereNull
(
'external_id'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotReserveCreate
(
$query
)
{
return
$query
->
whereNull
(
'reserve_create_at'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotReserveUpdate
(
$query
)
{
return
$query
->
whereNull
(
'reserve_update_at'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
return
$query
->
whereNotNull
(
'updated_need'
);
}
public
function
negativeKeywordSharedSet
()
{
return
$this
->
belongsTo
(
NegativeKeywordSharedSet
::
class
,
'negative_keyword_shared_set_id'
);
}
}
app/Service/Requests/Direct/GetNegativeKeywordSharedSets.php
0 → 100644
View file @
4d090b7
<?php
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdExtension
;
use
App\Models\AdGroup
;
use
App\Models\Advertisement
;
use
App\Models\NegativeKeywordSharedSet
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
GetNegativeKeywordSharedSets
extends
DirectRequest
{
protected
$max_count
=
-
1
;
protected
$max_count_Ids
=
30
;
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
public
function
getObjectsCount
()
{
$params
=
$this
->
getParams
();
if
(
isset
(
$params
[
'SelectionCriteria'
][
'Ids'
]))
{
return
count
(
$params
[
'SelectionCriteria'
][
'Ids'
]);
}
return
-
1
;
}
public
function
slice
(
$maxObjects
)
:
?
APIRequest
{
$params
=
$this
->
getParams
();
if
(
isset
(
$params
[
'SelectionCriteria'
][
'Ids'
]))
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'Ids'
]);
}
return
null
;
}
function
handle
(
$response
)
{
try
{
dd
(
$response
);
if
(
isset
(
$response
[
'result'
][
'NegativeKeywordSharedSets'
]))
{
foreach
(
$response
[
'result'
][
'NegativeKeywordSharedSets'
]
as
$negative_keyword_shared_sets
)
{
$external_id
=
(
string
)
$negative_keyword_shared_sets
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
$data
=
[
'external_id'
=>
$external_id
,
'name'
=>
$negative_keyword_shared_sets
[
'Name'
],
'negative_keywords'
=>
$negative_keyword_shared_sets
[
'NegativeKeywords'
],
'associated'
=>
$negative_keyword_shared_sets
[
'Associated'
]
===
'YES'
,
];
$adExtension
=
NegativeKeywordSharedSet
::
updateOrCreate
([
'external_id'
=>
$external_id
],
$data
);
if
(
$adExtension
->
wasChanged
(
$adExtension
::
getPropertiesWatch
()
->
toArray
()))
{
$adExtension
->
goalNegativeKeywordSharedSet
()
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
]);
}
}
else
{
//
}
}
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
throw
$e
;
}
}
private
function
requestPrepare
(
$filter
)
{
$this
->
setService
(
'NegativeKeywordSharedSets'
);
$this
->
setMethod
(
'get'
);
$params
=
[
"FieldNames"
=>
[
"Id"
,
"Name"
,
"NegativeKeywords"
,
"Associated"
,
],
];
if
(
isset
(
$filter
[
'Ids'
]))
{
$this
->
max_count
=
$this
->
max_count_Ids
;
$params
[
'SelectionCriteria'
]
=
[
'Ids'
=>
$filter
[
'Ids'
],
];
}
$this
->
setParams
(
$params
);
}
}
database/migrations/2021_07_05_131633_create_negative_keyword_shared_sets_table.php
0 → 100644
View file @
4d090b7
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateNegativeKeywordSharedSetsTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'negative_keyword_shared_sets'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'external_id'
);
$table
->
string
(
'name'
);
$table
->
json
(
'negative_keywords'
);
$table
->
boolean
(
'associated'
);
$table
->
softDeletes
();
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'negative_keyword_shared_sets'
);
}
}
database/migrations/2021_07_05_136255_create_goal_negative_keyword_shared_sets_table.php
0 → 100644
View file @
4d090b7
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateGoalNegativeKeywordSharedSetsTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'goal_negative_keyword_shared_sets'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'external_id'
)
->
nullable
();
$table
->
bigInteger
(
'negative_keyword_shared_set_id'
)
->
unsigned
();
$table
->
bigInteger
(
'token_id'
)
->
unsigned
();
$table
->
timestamp
(
'external_upload_at'
)
->
nullable
();
$table
->
timestamp
(
'external_updated_at'
)
->
nullable
();
$table
->
timestamp
(
'updated_need'
)
->
nullable
();
$table
->
timestamp
(
'reserve_create_at'
)
->
nullable
();
$table
->
timestamp
(
'reserve_update_at'
)
->
nullable
();
$table
->
foreign
(
'negative_keyword_shared_set_id'
,
'`gnkss_nkss_id_foreign'
)
->
references
(
'id'
)
->
on
(
'negative_keyword_shared_sets'
)
->
cascadeOnDelete
();
$table
->
foreign
(
'token_id'
)
->
references
(
'id'
)
->
on
(
'tokens'
)
->
cascadeOnDelete
();
$table
->
softDeletes
();
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'goal_negative_keyword_shared_sets'
);
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment