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 3e06f003
authored
Jun 21, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19496 Запрос измененных объявлений
1 parent
44836271
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
219 additions
and
52 deletions
app/Console/Commands/AdvertisementsLoadUpdated.php
app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php → app/Console/Commands/CampaignsCheckUpdatedChildren.php
app/Console/Commands/CampaignsFirstLoad.php
app/Console/Commands/CampaignsLoadAds.php
app/Console/Commands/CampaignsLoadGroups.php
app/Models/Advertisement.php
app/Service/Requests/Direct/CheckChanges.php
app/Service/Requests/Direct/GetAdGroups.php
app/Service/Requests/Direct/GetAds.php
app/Service/Requests/Direct/GetCampaigns.php
app/Service/Requests/Direct/GetDictionaries.php
app/Service/Requests/Direct/GetKeywords.php
app/Console/Commands/AdvertisementsLoadUpdated.php
0 → 100644
View file @
3e06f00
<?php
namespace
App\Console\Commands
;
use
App\Models\AdGroup
;
use
App\Models\Advertisement
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Builder
;
class
AdvertisementsLoadUpdated
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'ad:loadUpdated'
;
/**
* 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
*/
public
function
handle
()
{
$advertisements
=
Advertisement
::
where
(
function
(
Builder
$query
)
{
$query
->
where
(
function
(
Builder
$query
)
{
$query
->
has
(
'campaignForEnabledForManaged'
);
})
->
orWhere
(
function
(
Builder
$query
)
{
$query
->
whereNull
(
'campaign_id'
);
});
})
->
forUpdatedSelf
()
->
get
();
if
(
$advertisements
->
count
())
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
$ids
=
$advertisements
->
pluck
(
'external_id'
)
->
toArray
();
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Ads'
,
'get'
)
->
call
([
'Ids'
=>
$ids
,
]);
}
return
0
;
}
}
app/Console/Commands/CampaignsCheckUpdatedChildren
AdGroups
.php
→
app/Console/Commands/CampaignsCheckUpdatedChildren.php
View file @
3e06f00
...
...
@@ -8,14 +8,14 @@ use App\Service\API\API;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
class
CampaignsCheckUpdatedChildren
AdGroups
extends
Command
class
CampaignsCheckUpdatedChildren
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'campaigns:checkUpdatedChildren
AdGroups
'
;
protected
$signature
=
'campaigns:checkUpdatedChildren'
;
/**
* The console command description.
...
...
@@ -48,16 +48,19 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
throw
new
\Exception
(
'Не найден токен блин'
);
}
$campaign_ids_group
=
Campaigns
::
forUpdatedChildren
()
->
pluck
(
'external_id'
)
->
chunk
(
3000
)
->
toArray
();
foreach
(
$campaign_ids_group
as
$campaign_ids
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Changes'
,
'check'
)
->
call
([
'CampaignIds'
=>
Campaigns
::
forUpdatedChildren
()
->
pluck
(
'external_id'
)
->
toArray
()
,
'CampaignIds'
=>
$campaign_ids
,
'FieldNames'
=>
[
'AdGroup
Ids'
,
'AdGroupIds'
,
'Ad
Ids'
,
],
'Timestamp'
=>
$token
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
]);
}
}
...
...
@@ -68,18 +71,22 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
->
get
();
foreach
(
$tokens
as
$token
)
{
$campaign_ids_group
=
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
->
pluck
(
'external_id'
)
->
chunk
(
3000
)
->
toArray
();
foreach
(
$campaign_ids_group
as
$campaign_ids
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Changes'
,
'check'
)
->
call
([
'CampaignIds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
->
pluck
(
'external_id'
)
->
toArray
(),
'CampaignIds'
=>
$campaign_ids
,
'FieldNames'
=>
[
'AdGroup
Ids'
,
'AdGroupIds'
,
'Ad
Ids'
,
],
'Timestamp'
=>
$token
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
]);
}
}
return
0
;
...
...
app/Console/Commands/CampaignsFirstLoad.php
View file @
3e06f00
...
...
@@ -53,6 +53,7 @@ class CampaignsFirstLoad extends Command
Artisan
::
call
(
DictionariesLoad
::
class
);
Artisan
::
call
(
CampaignsLoadGroups
::
class
);
Artisan
::
call
(
AdGroupsLoadKeywords
::
class
);
Artisan
::
call
(
CampaignsLoadAds
::
class
);
return
0
;
}
...
...
app/Console/Commands/CampaignsLoadAds.php
0 → 100644
View file @
3e06f00
<?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
CampaignsLoadAds
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'campaigns:loadAds'
;
/**
* 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
()
{
$campaigns
=
Campaigns
::
forManaged
()
->
forEnabled
()
->
get
();
if
(
!
$campaigns
->
count
())
{
return
;
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
foreach
(
$campaigns
->
pluck
(
'external_id'
)
->
chunk
(
10
)
->
toArray
()
as
$campaign_ids
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Ads'
,
'get'
)
->
call
([
'CampaignIds'
=>
$campaign_ids
,
]);
}
return
0
;
}
}
app/Console/Commands/CampaignsLoadGroups.php
View file @
3e06f00
...
...
@@ -22,7 +22,7 @@ class CampaignsLoadGroups extends Command
*
* @var string
*/
protected
$description
=
'Загрузка
измененных
РК'
;
protected
$description
=
'Загрузка
групп
РК'
;
/**
* Create a new command instance.
...
...
@@ -53,15 +53,17 @@ class CampaignsLoadGroups extends Command
throw
new
\Exception
(
'Не найден токен блин'
);
}
foreach
(
$campaigns
->
pluck
(
'external_id'
)
->
chunk
(
10
)
->
toArray
()
as
$campaign_ids
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$campaign_ids
=
$campaigns
->
pluck
(
'external_id'
)
->
toArray
();
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'CampaignIds'
=>
$campaign_ids
,
]);
}
return
0
;
}
...
...
app/Models/Advertisement.php
View file @
3e06f00
...
...
@@ -97,6 +97,8 @@ class Advertisement extends Model
'turbo_page_moderation'
,
'business_id'
,
'prefer_v_card_over_business'
,
'updated_self'
,
];
protected
$casts
=
[
...
...
@@ -155,4 +157,9 @@ class Advertisement extends Model
return
$this
->
belongsTo
(
Campaigns
::
class
,
'campaign_id'
);
}
public
function
campaignForEnabledForManaged
()
{
return
$this
->
campaign
()
->
forEnabled
()
->
forManaged
();
}
}
app/Service/Requests/Direct/CheckChanges.php
View file @
3e06f00
...
...
@@ -4,6 +4,7 @@ namespace App\Service\Requests\Direct;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdGroup
;
use
App\Models\Advertisement
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdGroup
;
...
...
@@ -70,6 +71,7 @@ class CheckChanges extends DirectRequest
}
if
(
isset
(
$response
[
'result'
][
'Modified'
][
'AdGroupIds'
]))
{
foreach
(
$response
[
'result'
][
'Modified'
][
'AdGroupIds'
]
as
$ad_group_id
)
{
...
...
@@ -103,6 +105,31 @@ class CheckChanges extends DirectRequest
}
}
if
(
isset
(
$response
[
'result'
][
'Modified'
][
'AdIds'
]))
{
foreach
(
$response
[
'result'
][
'Modified'
][
'AdIds'
]
as
$ad_id
)
{
$ad_id
=
(
string
)
$ad_id
;
if
(
$this
->
getToken
()
->
isMain
())
{
$advertisement
=
Advertisement
::
where
(
'external_id'
,
$ad_id
)
->
first
();
if
(
$advertisement
)
{
$advertisement
->
update
([
'updated_self'
=>
Carbon
::
now
(),
]);
}
else
{
$advertisement
=
Advertisement
::
create
([
'external_id'
=>
$ad_id
,
'updated_self'
=>
Carbon
::
now
(),
]);
}
}
else
{
//
}
}
}
if
(
isset
(
$this
->
getParams
()[
'CampaignIds'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
...
...
@@ -134,17 +161,7 @@ class CheckChanges extends DirectRequest
$this
->
setService
(
'Changes'
);
$this
->
setMethod
(
'check'
);
if
(
isset
(
$params
[
'CampaignIds'
])){
$this
->
max_count
=
$this
->
max_count_CampaignIds
;
}
if
(
isset
(
$params
[
'AdGroupIds'
])){
$this
->
max_count
=
$this
->
max_count_AdGroupIds
;
}
if
(
isset
(
$params
[
'AdIds'
])){
$this
->
max_count
=
$this
->
max_count_AdIds
;
}
$params
[
'Timestamp'
]
=
$this
->
getToken
()
->
check_changes_ad_group_at
->
toIso8601ZuluString
();
$this
->
setParams
(
$params
);
}
...
...
app/Service/Requests/Direct/GetAdGroups.php
View file @
3e06f00
...
...
@@ -15,8 +15,9 @@ use Illuminate\Support\Facades\Log;
class
GetAdGroups
extends
DirectRequest
{
protected
$max_count
=
10000
;
protected
$max_count
=
-
1
;
protected
$max_count_CampaignIds
=
10
;
protected
$max_count_Ids
=
10000
;
function
call
(
$params
=
null
)
{
...
...
@@ -191,14 +192,14 @@ class GetAdGroups extends DirectRequest
],
];
if
(
isset
(
$filter
[
'CampaignIds'
]))
{
$this
->
max_count
=
$this
->
max_count_CampaignIds
;
$params
[
'SelectionCriteria'
]
=
[
'CampaignIds'
=>
$filter
[
'CampaignIds'
],
];
}
if
(
isset
(
$filter
[
'Ids'
]))
{
$this
->
max_count
=
$this
->
max_count_Ids
;
$params
[
'SelectionCriteria'
]
=
[
'Ids'
=>
$filter
[
'Ids'
],
];
...
...
app/Service/Requests/Direct/GetAds.php
View file @
3e06f00
...
...
@@ -27,10 +27,10 @@ class GetAds extends DirectRequest
{
$params
=
$this
->
getParams
();
if
(
isset
(
$params
[
'SelectionCriteria'
][
'CampaignIds'
]))
{
return
count
(
$params
[
'SelectionCriteria'
][
'CampaignIds'
])
;
return
-
1
;
}
if
(
isset
(
$params
[
'SelectionCriteria'
][
'AdGroupIds'
]))
{
return
count
(
$params
[
'SelectionCriteria'
][
'AdGroupIds'
])
;
return
-
1
;
}
if
(
isset
(
$params
[
'SelectionCriteria'
][
'Ids'
]))
{
return
count
(
$params
[
'SelectionCriteria'
][
'Ids'
]);
...
...
@@ -42,12 +42,6 @@ class GetAds extends DirectRequest
{
$params
=
$this
->
getParams
();
if
(
isset
(
$params
[
'SelectionCriteria'
][
'CampaignIds'
]))
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'CampaignIds'
]);
}
if
(
isset
(
$params
[
'SelectionCriteria'
][
'AdGroupIds'
]))
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'AdGroupIds'
]);
}
if
(
isset
(
$params
[
'SelectionCriteria'
][
'Ids'
]))
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'Ids'
]);
}
...
...
@@ -85,8 +79,6 @@ class GetAds extends DirectRequest
//
}
$ids
=
[];
foreach
(
$response
[
'result'
][
'Ads'
]
as
$ad
)
{
$ad_group
=
$ad_groups
->
get
((
string
)
$ad
[
'AdGroupId'
]);
...
...
@@ -114,6 +106,11 @@ class GetAds extends DirectRequest
'type'
=>
$ad
[
'Type'
],
'sub_type'
=>
$ad
[
'Subtype'
],
'updated_self'
=>
null
,
];
if
(
isset
(
$ad
[
'TextAd'
]))
{
$data
=
array_merge
(
$data
,[
'title'
=>
$ad
[
'TextAd'
][
'Title'
],
'title2'
=>
$ad
[
'TextAd'
][
'Title2'
],
'text'
=>
$ad
[
'TextAd'
][
'Text'
],
...
...
@@ -135,7 +132,8 @@ class GetAds extends DirectRequest
'turbo_page_moderation'
=>
$ad
[
'TextAd'
][
'TurboPageModeration'
],
'business_id'
=>
$ad
[
'TextAd'
][
'BusinessId'
],
'prefer_v_card_over_business'
=>
$ad
[
'TextAd'
][
'PreferVCardOverBusiness'
],
];
]);
}
Advertisement
::
updateOrCreate
([
'external_id'
=>
$external_id
...
...
@@ -165,17 +163,11 @@ class GetAds extends DirectRequest
],
];
if
(
isset
(
$filter
[
'CampaignIds'
]))
{
$this
->
max_count
=
$this
->
max_count_CampaignIds
;
$params
[
'SelectionCriteria'
]
=
[
'CampaignIds'
=>
$filter
[
'CampaignIds'
],
];
}
if
(
isset
(
$filter
[
'AdGroupIds'
]))
{
$this
->
max_count
=
$this
->
max_count_AdGroupIds
;
$params
[
'SelectionCriteria'
]
=
[
'AdGroupIds'
=>
$filter
[
'AdGroupIds'
],
];
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
3e06f00
...
...
@@ -11,7 +11,8 @@ use Illuminate\Support\Facades\Log;
class
GetCampaigns
extends
DirectRequest
{
protected
$max_count
=
1000
;
protected
$max_count
=
-
1
;
protected
$max_count_Ids
=
1000
;
protected
$timestamp
;
public
function
call
(
$params
=
null
)
...
...
@@ -109,6 +110,9 @@ class GetCampaigns extends DirectRequest
]
];
if
(
!
empty
(
$filter
[
'ids'
]))
{
$this
->
max_count
=
$this
->
max_count_Ids
;
$params
[
'SelectionCriteria'
][
'Ids'
]
=
$filter
[
'ids'
];
}
$this
->
setParams
(
$params
);
...
...
app/Service/Requests/Direct/GetDictionaries.php
View file @
3e06f00
...
...
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log;
class
GetDictionaries
extends
DirectRequest
{
protected
$max_count
=
10000
;
protected
$max_count
=
-
1
;
function
call
(
$params
=
null
)
{
...
...
app/Service/Requests/Direct/GetKeywords.php
View file @
3e06f00
...
...
@@ -213,17 +213,11 @@ class GetKeywords extends DirectRequest
],
];
if
(
isset
(
$filter
[
'CampaignIds'
]))
{
$this
->
max_count
=
$this
->
max_count_CampaignIds
;
$params
[
'SelectionCriteria'
]
=
[
'CampaignIds'
=>
$filter
[
'CampaignIds'
],
];
}
if
(
isset
(
$filter
[
'AdGroupIds'
]))
{
$this
->
max_count
=
$this
->
max_count_AdGroupIds
;
$params
[
'SelectionCriteria'
]
=
[
'AdGroupIds'
=>
$filter
[
'AdGroupIds'
],
];
...
...
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