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 76e0f902
authored
Jun 09, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into ticket_19473
2 parents
7c551ac6
422f5e7d
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
528 additions
and
242 deletions
app/Console/Commands/AdGroupLoadUpdated.php
app/Console/Commands/AdGroupsAdd.php
app/Console/Commands/AdGroupsLoadUpdated.php
app/Console/Commands/AdGroupsUpdate.php
app/Console/Commands/CampaignsCheckChange.php
app/Console/Commands/CampaignsLoadUpdatedChildrenAdGroups.php → app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsUpdate.php
app/Console/Kernel.php
app/Http/Controllers/CampaignVariablesController.php
app/Http/Controllers/TokensController.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Contact.php
app/Models/Dictionary.php
app/Models/Limits.php
app/Models/Organization.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdGroup.php
app/Models/Tokens.php
app/Models/User.php
app/Models/Variable.php
app/Service/Limits.php
app/Service/Requests/Direct/CheckCampaignsChanges.php
app/Service/Requests/Direct/CheckChanges.php
app/Service/Requests/DirectRequest.php
resources/js/Pages/Tokens/CitySettings.vue
resources/js/Pages/Tokens/Edit.vue
routes/web.php
tests/Unit/CallLimitedApiTest.php
tests/Unit/CheckCampaignsTest.php
tests/Unit/CheckChangesAdGroupsTest.php
tests/Unit/LimitsTest.php
tests/Unit/ProcessCallSliceTest.php
tests/Unit/ReplaceByVariablesTest.php
tests/Unit/UpdateCampaignsTest.php
app/Console/Commands/AdGroupLoadUpdated.php
deleted
100644 → 0
View file @
7c551ac
<?php
namespace
App\Console\Commands
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdGroup
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Direct\CheckDictionaries
;
use
App\Service\Direct\GetCampaigns
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\Bus
;
class
AdGroupLoadUpdated
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'adgroups: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
()
{
$campaigns
=
AdGroup
::
forUpdatedSelf
()
->
get
();
if
(
!
$campaigns
->
count
())
{
return
;
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Campaigns'
,
'get'
)
->
call
([
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
with
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'Ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'groupsForExternalForUpdatedSelf'
)
->
collapse
()
->
all
(),
]);
}
return
0
;
}
}
app/Console/Commands/AdGroupsAdd.php
View file @
76e0f90
...
@@ -42,10 +42,10 @@ class AdGroupsAdd extends Command
...
@@ -42,10 +42,10 @@ class AdGroupsAdd extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal.groupsForNotExternal'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Synchronized
.groupsForNotExternal'
)
->
with
([
->
with
([
'dictionaryCampaignsEnabledForExternal.groupsForNotExternal.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal
Synchronized
.groupsForNotExternal.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal.groupsForNotExternal.group'
,
'dictionaryCampaignsEnabledForExternal
Synchronized
.groupsForNotExternal.group'
,
])
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -54,10 +54,9 @@ class AdGroupsAdd extends Command
...
@@ -54,10 +54,9 @@ class AdGroupsAdd extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'add'
)
$factory
->
getRequest
(
'AdGroups'
,
'add'
)
->
call
([
->
call
([
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
->
pluck
(
'groupsForNotExternal'
)
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Synchronized
->
pluck
(
'groupsForNotExternal'
)
->
collapse
(),
->
collapse
(),
]);
]);
}
}
...
...
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
76e0f90
...
@@ -2,11 +2,18 @@
...
@@ -2,11 +2,18 @@
namespace
App\Console\Commands
;
namespace
App\Console\Commands
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdGroup
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Direct\CheckDictionaries
;
use
App\Service\Direct\GetCampaigns
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\Bus
;
class
AdGroupsLoadUpdated
extends
Command
class
AdGroupsLoadUpdated
extends
Command
{
{
...
@@ -22,7 +29,7 @@ class AdGroupsLoadUpdated extends Command
...
@@ -22,7 +29,7 @@ class AdGroupsLoadUpdated extends Command
*
*
* @var string
* @var string
*/
*/
protected
$description
=
'Загрузка измененны
х групп
'
;
protected
$description
=
'Загрузка измененны
е группы
'
;
/**
/**
* Create a new command instance.
* Create a new command instance.
...
@@ -38,27 +45,43 @@ class AdGroupsLoadUpdated extends Command
...
@@ -38,27 +45,43 @@ class AdGroupsLoadUpdated extends Command
* Execute the console command.
* Execute the console command.
*
*
* @return int
* @return int
* @throws \Exception
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$
token
=
Tokens
::
has
(
'campaignsAdGroupsForUpdatedSelf'
)
$
adGroups
=
AdGroup
::
forUpdatedSelf
()
->
get
();
->
with
(
'campaignsAdGroupsForUpdatedSelf'
)
if
(
!
$adGroups
->
count
())
{
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
return
;
->
first
();
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
if
(
!
$token
)
{
return
0
;
throw
new
\Exception
(
'Не найден токен блин'
)
;
}
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
->
call
([
'Ids'
=>
$adGroups
->
pluck
(
'external_id'
)
->
all
(),
'CampaignIds'
=>
$token
->
campaignsAdGroupsForUpdatedSelf
->
pluck
(
'campaign_external_id'
)
->
all
(),
]);
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
with
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'Ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'groupsForExternalForUpdatedSelf'
)
->
collapse
()
->
pluck
(
'external_id'
)
->
all
(),
]);
}
return
0
;
return
0
;
}
}
}
}
app/Console/Commands/AdGroupsUpdate.php
View file @
76e0f90
...
@@ -42,10 +42,10 @@ class AdGroupsUpdate extends Command
...
@@ -42,10 +42,10 @@ class AdGroupsUpdate extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Updated
.groupsForExternalForNeedUpdated'
)
->
with
([
->
with
([
'dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal
Updated
.groupsForExternalForNeedUpdated.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated.group'
,
'dictionaryCampaignsEnabledForExternal
Updated
.groupsForExternalForNeedUpdated.group'
,
])
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -57,7 +57,7 @@ class AdGroupsUpdate extends Command
...
@@ -57,7 +57,7 @@ class AdGroupsUpdate extends Command
$factory
->
getRequest
(
'AdGroup'
,
'update'
)
$factory
->
getRequest
(
'AdGroup'
,
'update'
)
->
call
([
->
call
([
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
->
pluck
(
'groupsForExternalForNeedUpdated'
)
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Updated
->
pluck
(
'groupsForExternalForNeedUpdated'
)
->
collapse
(),
->
collapse
(),
]);
]);
}
}
...
...
app/Console/Commands/CampaignsCheckChange.php
View file @
76e0f90
...
@@ -50,7 +50,8 @@ class CampaignsCheckChange extends Command
...
@@ -50,7 +50,8 @@ class CampaignsCheckChange extends Command
->
call
();
->
call
();
}
}
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternal'
)
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternalUpdated'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
foreach
(
$tokens
as
$token
)
{
...
...
app/Console/Commands/Campaigns
Load
UpdatedChildrenAdGroups.php
→
app/Console/Commands/Campaigns
Check
UpdatedChildrenAdGroups.php
View file @
76e0f90
...
@@ -14,21 +14,21 @@ use Illuminate\Console\Command;
...
@@ -14,21 +14,21 @@ use Illuminate\Console\Command;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\Bus
;
use
Illuminate\Support\Facades\Bus
;
class
Campaigns
Load
UpdatedChildrenAdGroups
extends
Command
class
Campaigns
Check
UpdatedChildrenAdGroups
extends
Command
{
{
/**
/**
* The name and signature of the console command.
* The name and signature of the console command.
*
*
* @var string
* @var string
*/
*/
protected
$signature
=
'campaigns:
load
UpdatedChildrenAdGroups'
;
protected
$signature
=
'campaigns:
check
UpdatedChildrenAdGroups'
;
/**
/**
* The console command description.
* The console command description.
*
*
* @var string
* @var string
*/
*/
protected
$description
=
'
Загрузка измененных РК
'
;
protected
$description
=
'
Проверка наличия изменения в дочерних элементах
'
;
/**
/**
* Create a new command instance.
* Create a new command instance.
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
76e0f90
...
@@ -47,7 +47,7 @@ class CampaignsLoadUpdated extends Command
...
@@ -47,7 +47,7 @@ class CampaignsLoadUpdated extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$campaigns
=
Campaigns
::
forUpdatedSelf
()
->
get
();
$campaigns
=
Campaigns
::
for
Enabled
()
->
for
UpdatedSelf
()
->
get
();
if
(
!
$campaigns
->
count
())
{
if
(
!
$campaigns
->
count
())
{
return
;
return
;
}
}
...
...
app/Console/Commands/CampaignsUpdate.php
View file @
76e0f90
...
@@ -42,8 +42,8 @@ class CampaignsUpdate extends Command
...
@@ -42,8 +42,8 @@ class CampaignsUpdate extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Updated
NeedUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternalNeedUpdated.campaign'
)
->
with
(
'dictionaryCampaignsEnabledForExternal
Updated
NeedUpdated.campaign'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -53,7 +53,7 @@ class CampaignsUpdate extends Command
...
@@ -53,7 +53,7 @@ class CampaignsUpdate extends Command
$factory
->
getRequest
(
'Campaigns'
,
'update'
)
$factory
->
getRequest
(
'Campaigns'
,
'update'
)
->
call
([
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternalNeedUpdated
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Updated
NeedUpdated
,
]);
]);
}
}
...
...
app/Console/Kernel.php
View file @
76e0f90
...
@@ -7,8 +7,8 @@ use App\Console\Commands\AdGroupsLoadUpdated;
...
@@ -7,8 +7,8 @@ use App\Console\Commands\AdGroupsLoadUpdated;
use
App\Console\Commands\AdGroupsUpdate
;
use
App\Console\Commands\AdGroupsUpdate
;
use
App\Console\Commands\CampaignsAdd
;
use
App\Console\Commands\CampaignsAdd
;
use
App\Console\Commands\CampaignsCheckChange
;
use
App\Console\Commands\CampaignsCheckChange
;
use
App\Console\Commands\CampaignsCheckUpdatedChildrenAdGroups
;
use
App\Console\Commands\CampaignsLoadGroups
;
use
App\Console\Commands\CampaignsLoadGroups
;
use
App\Console\Commands\CampaignsLoadUpdatedChildrenAdGroups
;
use
App\Console\Commands\CampaignsResume
;
use
App\Console\Commands\CampaignsResume
;
use
App\Console\Commands\CampaignsSuspend
;
use
App\Console\Commands\CampaignsSuspend
;
use
App\Console\Commands\CampaignsUpdate
;
use
App\Console\Commands\CampaignsUpdate
;
...
@@ -40,12 +40,14 @@ class Kernel extends ConsoleKernel
...
@@ -40,12 +40,14 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
RefreshLimits
::
class
)
->
hourly
();
$schedule
->
command
(
RefreshLimits
::
class
)
->
hourly
();
$schedule
->
command
(
DictionariesLoad
::
class
)
->
saturdays
()
->
at
(
'05:00'
);
$schedule
->
command
(
DictionariesLoad
::
class
)
->
saturdays
()
->
at
(
'05:00'
);
$schedule
->
command
(
CampaignsCheckChange
::
class
)
->
hourlyAt
(
5
);
$schedule
->
command
(
CampaignsCheckChange
::
class
)
->
hourlyAt
(
5
);
$schedule
->
command
(
CampaignsLoadUpdated
::
class
)
->
hourlyAt
(
15
);
$schedule
->
command
(
CampaignsCheckUpdatedChildrenAdGroups
::
class
)
->
hourlyAt
(
10
);
$schedule
->
command
(
CampaignsLoadUpdated
::
class
)
->
hourlyAt
(
10
);
$schedule
->
command
(
CampaignsAdd
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsAdd
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsUpdate
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsUpdate
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsResume
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsResume
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsSuspend
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsSuspend
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
CampaignsLoadUpdatedChildrenAdGroups
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
CampaignsLoadGroups
::
class
)
->
hourlyAt
(
40
);
$schedule
->
command
(
CampaignsLoadGroups
::
class
)
->
hourlyAt
(
40
);
$schedule
->
command
(
AdGroupsLoadUpdated
::
class
)
->
hourlyAt
(
45
);
$schedule
->
command
(
AdGroupsLoadUpdated
::
class
)
->
hourlyAt
(
45
);
$schedule
->
command
(
AdGroupsAdd
::
class
)
->
hourlyAt
(
50
);
$schedule
->
command
(
AdGroupsAdd
::
class
)
->
hourlyAt
(
50
);
...
...
app/Http/Controllers/CampaignVariablesController.php
View file @
76e0f90
...
@@ -193,6 +193,7 @@ class CampaignVariablesController extends Controller
...
@@ -193,6 +193,7 @@ class CampaignVariablesController extends Controller
}
}
if
(
$dictionary_campaign
->
external_id
)
{
$dictionary_campaign
->
update
([
$dictionary_campaign
->
update
([
'updated_need'
=>
Carbon
::
now
(),
'updated_need'
=>
Carbon
::
now
(),
]);
]);
...
@@ -200,6 +201,7 @@ class CampaignVariablesController extends Controller
...
@@ -200,6 +201,7 @@ class CampaignVariablesController extends Controller
$dictionary_campaign
->
groups
()
->
update
([
$dictionary_campaign
->
groups
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
'updated_need'
=>
Carbon
::
now
(),
]);
]);
}
}
}
...
...
app/Http/Controllers/TokensController.php
View file @
76e0f90
...
@@ -116,8 +116,14 @@ class TokensController extends Controller
...
@@ -116,8 +116,14 @@ class TokensController extends Controller
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$enabled
=
!!
request
(
'enabled'
);
$campaign
->
update
([
$campaign
->
update
([
'enabled'
=>
!!
request
(
'enabled'
),
'enabled'
=>
$enabled
,
]);
$campaign
->
dictionaryCampaigns
()
->
update
([
'enabled'
=>
$enabled
,
]);
]);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign '
.
(
$campaign
->
enabled
?
'enabled'
:
'disabled'
)
.
'.'
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign '
.
(
$campaign
->
enabled
?
'enabled'
:
'disabled'
)
.
'.'
);
...
...
app/Models/AdGroup.php
View file @
76e0f90
...
@@ -106,8 +106,6 @@ class AdGroup extends Model
...
@@ -106,8 +106,6 @@ class AdGroup extends Model
protected
$casts
=
[
protected
$casts
=
[
'campaign_id'
=>
'int'
,
'campaign_id'
=>
'int'
,
'external_id'
=>
'int'
,
'campaign_external_id'
=>
'int'
,
'region_ids'
=>
'array'
,
'region_ids'
=>
'array'
,
'negative_keywords'
=>
'json'
,
'negative_keywords'
=>
'json'
,
'negative_keyword_shared_set_ids'
=>
'json'
,
'negative_keyword_shared_set_ids'
=>
'json'
,
...
@@ -128,7 +126,6 @@ class AdGroup extends Model
...
@@ -128,7 +126,6 @@ class AdGroup extends Model
static
public
function
getPropertiesWatch
()
static
public
function
getPropertiesWatch
()
{
{
return
collect
([
return
collect
([
'campaign_external_id'
,
'name'
,
'name'
,
'region_ids'
,
'region_ids'
,
'negative_keywords'
,
'negative_keywords'
,
...
@@ -158,15 +155,19 @@ class AdGroup extends Model
...
@@ -158,15 +155,19 @@ class AdGroup extends Model
if
(
GoalAdGroup
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
if
(
GoalAdGroup
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
}))
{
}))
{
if
(
!
is_null
(
$ad_group
->
campaign_id
)
&&
is_null
(
$ad_group
->
getOriginal
(
'campaign_id'
)))
{
$ad_group
->
campaign
->
copyGroupInGoalGroup
();
}
else
{
$ad_group
->
goalGroups
()
->
update
(
$ad_group
->
goalGroups
()
->
update
(
GoalAdGroup
::
copyPropertyFromMain
(
$ad_group
)
GoalAdGroup
::
copyPropertyFromMain
(
$ad_group
)
);
);
}
}
}
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
}))
{
}))
{
$ad_group
->
goalGroups
()
->
update
([
$ad_group
->
goalGroups
()
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
'updated_need'
=>
Carbon
::
now
(),
]);
]);
}
}
...
@@ -174,9 +175,13 @@ class AdGroup extends Model
...
@@ -174,9 +175,13 @@ class AdGroup extends Model
});
});
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
"
{
$query
->
getModel
()
->
getTable
()
}
.updated_self"
);
return
$query
->
whereNotNull
(
"
{
$query
->
getModel
()
->
getTable
()
}
.updated_self"
);
}
}
public
function
goalGroups
()
public
function
goalGroups
()
...
...
app/Models/Campaigns.php
View file @
76e0f90
...
@@ -111,7 +111,6 @@ class Campaigns extends Model
...
@@ -111,7 +111,6 @@ class Campaigns extends Model
];
];
protected
$casts
=
[
protected
$casts
=
[
'external_id'
=>
'int'
,
'time_targeting'
=>
'array'
,
'time_targeting'
=>
'array'
,
'negative_keywords'
=>
'array'
,
'negative_keywords'
=>
'array'
,
'blocked_ips'
=>
'array'
,
'blocked_ips'
=>
'array'
,
...
@@ -194,7 +193,7 @@ class Campaigns extends Model
...
@@ -194,7 +193,7 @@ class Campaigns extends Model
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
}))
{
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
synchroniz
ed
()
->
update
(
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
forUpdat
ed
()
->
update
(
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
)
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
)
);
);
}
}
...
@@ -202,7 +201,7 @@ class Campaigns extends Model
...
@@ -202,7 +201,7 @@ class Campaigns extends Model
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
}))
{
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
synchronized
()
->
forExternal
()
->
update
([
$campaign
->
dictionaryCampaigns
()
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
'updated_need'
=>
Carbon
::
now
(),
]);
]);
}
}
...
@@ -232,7 +231,8 @@ class Campaigns extends Model
...
@@ -232,7 +231,8 @@ class Campaigns extends Model
$campaign
->
groups
()
->
get
()
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
$campaign
->
groups
()
->
get
()
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
$dictionaryCampaign
->
groups
()
->
updateOrCreate
([
$dictionaryCampaign
->
groups
()
->
updateOrCreate
([
'campaign_id'
=>
$dictionaryCampaign
->
external_id
,
'campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'ad_group_id'
=>
$adGroup
->
getKey
(),
],
GoalAdGroup
::
copyPropertyFromMain
(
$adGroup
));
],
GoalAdGroup
::
copyPropertyFromMain
(
$adGroup
));
});
});
...
@@ -339,37 +339,67 @@ class Campaigns extends Model
...
@@ -339,37 +339,67 @@ class Campaigns extends Model
->
withTimestamps
();
->
withTimestamps
();
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
scopeForUpdatedChildren
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedChildren
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_children'
);
return
$query
->
whereNotNull
(
'updated_children'
);
}
}
public
function
scopeForGroupsLoadable
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForGroupsLoadable
(
$query
)
{
{
$query
->
whereNull
(
'groups_loaded_at'
);
return
$query
->
whereNull
(
'groups_loaded_at'
);
}
}
public
function
scopeForManaged
(
Builder
$query
,
$manage
=
true
)
/**
* @param Builder $query
* @param bool $manage
* @return Builder
*/
public
function
scopeForManaged
(
$query
,
$manage
=
true
)
{
{
$query
->
where
(
'manage'
,
$manage
);
return
$query
->
where
(
'manage'
,
$manage
);
}
}
public
function
scopeForEnabled
(
Builder
$query
,
$enabled
=
true
)
/**
* @param Builder $query
* @param bool $enabled
* @return Builder
*/
public
function
scopeForEnabled
(
$query
,
$enabled
=
true
)
{
{
$query
->
where
(
'enabled'
,
$enabled
);
return
$query
->
where
(
'enabled'
,
$enabled
);
}
}
public
function
scopeDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDisabled
(
$query
)
{
{
return
$query
->
whereNotNull
(
'disabled_at'
);
return
$query
->
whereNotNull
(
'disabled_at'
);
}
}
public
function
scopeNotDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNotDisabled
(
$query
)
{
{
return
$query
->
whereNull
(
'disabled_at'
);
return
$query
->
whereNull
(
'disabled_at'
);
}
}
...
...
app/Models/Contact.php
View file @
76e0f90
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
/**
/**
...
@@ -53,24 +54,23 @@ class Contact extends Model
...
@@ -53,24 +54,23 @@ class Contact extends Model
{
{
use
SoftDeletes
;
use
SoftDeletes
;
public
function
organization
()
/**
{
* @param Builder $query
return
$this
->
belongsTo
(
Organization
::
class
);
* @return Builder
}
*/
public
function
getNameAttribute
()
{
return
$this
->
first_name
.
' '
.
$this
->
last_name
;
}
public
function
scopeOrderByName
(
$query
)
public
function
scopeOrderByName
(
$query
)
{
{
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
return
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
...
@@ -87,4 +87,14 @@ class Contact extends Model
...
@@ -87,4 +87,14 @@ class Contact extends Model
}
}
});
});
}
}
public
function
organization
()
{
return
$this
->
belongsTo
(
Organization
::
class
);
}
public
function
getNameAttribute
()
{
return
$this
->
first_name
.
' '
.
$this
->
last_name
;
}
}
}
app/Models/Dictionary.php
View file @
76e0f90
...
@@ -40,7 +40,11 @@ class Dictionary extends Model
...
@@ -40,7 +40,11 @@ class Dictionary extends Model
{
{
CONST
CITY
=
'City'
;
CONST
CITY
=
'City'
;
public
function
scopeDefaultOrderBy
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDefaultOrderBy
(
$query
)
{
{
return
$query
->
orderBy
(
'name'
);
return
$query
->
orderBy
(
'name'
);
}
}
...
...
app/Models/Limits.php
View file @
76e0f90
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
...
@@ -38,8 +39,12 @@ class Limits extends Model
...
@@ -38,8 +39,12 @@ class Limits extends Model
{
{
use
HasFactory
;
use
HasFactory
;
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeComplited
(
$query
)
public
function
scopeComplited
(
$query
)
{
{
$query
->
where
(
'reserved'
,
0
);
return
$query
->
where
(
'reserved'
,
0
);
}
}
}
}
app/Models/Organization.php
View file @
76e0f90
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
/**
/**
...
@@ -53,9 +54,14 @@ class Organization extends Model
...
@@ -53,9 +54,14 @@ class Organization extends Model
return
$this
->
hasMany
(
Contact
::
class
);
return
$this
->
hasMany
(
Contact
::
class
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
'name'
,
'like'
,
'%'
.
$search
.
'%'
);
$query
->
where
(
'name'
,
'like'
,
'%'
.
$search
.
'%'
);
})
->
when
(
$filters
[
'trashed'
]
??
null
,
function
(
$query
,
$trashed
)
{
})
->
when
(
$filters
[
'trashed'
]
??
null
,
function
(
$query
,
$trashed
)
{
if
(
$trashed
===
'with'
)
{
if
(
$trashed
===
'with'
)
{
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
76e0f90
...
@@ -44,7 +44,7 @@ use Illuminate\Support\Collection;
...
@@ -44,7 +44,7 @@ use Illuminate\Support\Collection;
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forNotExternal()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forNotExternal()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign enabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign enabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
u
pdated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
forU
pdated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdatedSelf()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdatedSelf()
...
@@ -102,7 +102,6 @@ class DictionaryCampaign extends Pivot
...
@@ -102,7 +102,6 @@ class DictionaryCampaign extends Pivot
];
];
protected
$casts
=
[
protected
$casts
=
[
'external_id'
=>
'int'
,
'campaign_id'
=>
'int'
,
'campaign_id'
=>
'int'
,
'dictionary_id'
=>
'int'
,
'dictionary_id'
=>
'int'
,
'negative_keywords'
=>
'array'
,
'negative_keywords'
=>
'array'
,
...
@@ -175,67 +174,113 @@ class DictionaryCampaign extends Pivot
...
@@ -175,67 +174,113 @@ class DictionaryCampaign extends Pivot
})
->
all
();
})
->
all
();
}
}
public
function
scopeDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDisabled
(
$query
)
{
{
return
$query
->
whereNotNull
(
'disabled_at'
);
return
$query
->
whereNotNull
(
'disabled_at'
);
}
}
public
function
scopeNotDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNotDisabled
(
$query
)
{
{
return
$query
->
whereNull
(
'disabled_at'
);
return
$query
->
whereNull
(
'disabled_at'
);
}
}
public
function
scopeForExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForExternal
(
$query
)
{
{
return
$query
->
whereNotNull
(
'external_id'
);
return
$query
->
whereNotNull
(
'external_id'
);
}
}
public
function
scopeForNotExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotExternal
(
$query
)
{
{
return
$query
->
whereNull
(
'external_id'
);
return
$query
->
whereNull
(
'external_id'
);
}
}
public
function
scopeEnabled
(
Builder
$query
,
$enabled
=
true
)
/**
* @param Builder $query
* @param bool $enabled
* @return Builder
*/
public
function
scopeEnabled
(
$query
,
$enabled
=
true
)
{
{
return
$query
->
where
(
'enabled'
,
$enabled
);
return
$query
->
where
(
'enabled'
,
$enabled
);
}
}
public
function
scopeUpdated
(
Builder
$query
,
$updated
=
true
)
/**
* @param Builder $query
* @param bool $updated
* @return Builder
*/
public
function
scopeForUpdated
(
$query
,
$updated
=
true
)
{
{
return
$query
->
where
(
'updated'
,
$updated
);
return
$query
->
where
(
'updated'
,
$updated
);
}
}
public
function
scopeNeedUpdated
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
{
return
$query
->
whereNotNull
(
'updated_need'
);
return
$query
->
whereNotNull
(
'updated_need'
);
}
}
public
function
scopeSynced
(
Builder
$query
,
$synced
=
true
)
/**
* @param Builder $query
* @param bool $synced
* @return Builder
*/
public
function
scopeSynced
(
$query
,
$synced
=
true
)
{
{
return
$query
->
where
(
'synced'
,
$synced
);
return
$query
->
where
(
'synced'
,
$synced
);
}
}
public
function
scopeSynchronized
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeSynchronized
(
$query
)
{
{
return
$query
->
synced
()
return
$query
->
synced
()
->
forUpdated
();
->
where
(
function
(
Builder
$query
)
{
$query
->
updated
()
->
orWhere
(
function
(
Builder
$query
)
{
$query
->
updated
(
false
)
->
forNotExternal
();
});
});
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
scopeForUpdatedChildren
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedChildren
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_children'
);
return
$query
->
whereNotNull
(
'updated_children'
);
}
}
public
function
scopeJoinDictionaries
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeJoinDictionaries
(
$query
)
{
{
$dictionary_model
=
Dictionary
::
getModel
();
$dictionary_model
=
Dictionary
::
getModel
();
...
...
app/Models/Pivots/GoalAdGroup.php
View file @
76e0f90
...
@@ -72,8 +72,6 @@ class GoalAdGroup extends Pivot
...
@@ -72,8 +72,6 @@ class GoalAdGroup extends Pivot
];
];
protected
$casts
=
[
protected
$casts
=
[
'external_id'
=>
'int'
,
'campaign_external_id'
=>
'int'
,
'ad_group_id'
=>
'int'
,
'ad_group_id'
=>
'int'
,
'dictionary_campaign_id'
=>
'int'
,
'dictionary_campaign_id'
=>
'int'
,
'negative_keywords'
=>
'array'
,
'negative_keywords'
=>
'array'
,
...
@@ -139,24 +137,40 @@ class GoalAdGroup extends Pivot
...
@@ -139,24 +137,40 @@ class GoalAdGroup extends Pivot
->
all
();
->
all
();
}
}
public
function
scopeForExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForExternal
(
$query
)
{
{
return
$query
->
whereNotNull
(
'external_id'
);
return
$query
->
whereNotNull
(
'external_id'
);
}
}
public
function
scopeForNotExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotExternal
(
$query
)
{
{
return
$query
->
whereNull
(
'external_id'
);
return
$query
->
whereNull
(
'external_id'
);
}
}
public
function
scopeNeedUpdated
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
{
return
$query
->
whereNotNull
(
'updated_need'
);
return
$query
->
whereNotNull
(
'updated_need'
);
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
group
()
public
function
group
()
...
...
app/Models/Tokens.php
View file @
76e0f90
...
@@ -4,6 +4,7 @@ namespace App\Models;
...
@@ -4,6 +4,7 @@ namespace App\Models;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaign
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
/**
/**
...
@@ -27,8 +28,8 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -27,8 +28,8 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @property-read int|null $campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaignsAdGroups
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaignsAdGroups
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaignsAdGroupsForUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaigns
ForEnabled
AdGroupsForUpdatedSelf
* @property-read int|null $campaigns_ad_groups_count
* @property-read int|null $campaigns_
for_enabled_
ad_groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsNotEnabledNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsNotEnabledNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledNotDisabledUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledNotDisabledUpdatedChildren
...
@@ -39,9 +40,11 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -39,9 +40,11 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronized
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronized
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
...
@@ -112,9 +115,14 @@ class Tokens extends Model
...
@@ -112,9 +115,14 @@ class Tokens extends Model
:
Carbon
::
now
()
->
addDays
(
-
1
);
:
Carbon
::
now
()
->
addDays
(
-
1
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'login'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'login'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
'login'
,
'like'
,
'%'
.
$search
.
'%'
);
$query
->
where
(
'login'
,
'like'
,
'%'
.
$search
.
'%'
);
})
->
when
(
$filters
[
'type'
]
??
null
,
function
(
$query
,
$type
)
{
})
->
when
(
$filters
[
'type'
]
??
null
,
function
(
$query
,
$type
)
{
$query
->
where
(
'type'
,
$type
);
$query
->
where
(
'type'
,
$type
);
...
@@ -145,9 +153,9 @@ class Tokens extends Model
...
@@ -145,9 +153,9 @@ class Tokens extends Model
return
$this
->
hasManyThrough
(
AdGroup
::
class
,
Campaigns
::
class
,
'token'
,
'campaign_id'
);
return
$this
->
hasManyThrough
(
AdGroup
::
class
,
Campaigns
::
class
,
'token'
,
'campaign_id'
);
}
}
public
function
campaignsAdGroupsForUpdatedSelf
()
public
function
campaigns
ForEnabled
AdGroupsForUpdatedSelf
()
{
{
return
$this
->
campaignsAdGroups
()
->
forUpdatedSelf
();
return
$this
->
campaignsAdGroups
()
->
forUpdatedSelf
()
->
where
(
Campaigns
::
getModel
()
->
getTable
()
.
'.enabled'
,
true
)
;
}
}
public
function
campaignsNotEnabledNotDisabled
()
public
function
campaignsNotEnabledNotDisabled
()
...
@@ -185,7 +193,17 @@ class Tokens extends Model
...
@@ -185,7 +193,17 @@ class Tokens extends Model
public
function
dictionaryCampaignsEnabledForExternal
()
public
function
dictionaryCampaignsEnabledForExternal
()
{
{
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
();
}
public
function
dictionaryCampaignsEnabledForExternalUpdated
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
forUpdated
();
}
public
function
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
forUpdated
()
->
needUpdated
();
}
}
public
function
dictionaryCampaignsEnabledForNotExternal
()
public
function
dictionaryCampaignsEnabledForNotExternal
()
...
@@ -195,32 +213,27 @@ class Tokens extends Model
...
@@ -195,32 +213,27 @@ class Tokens extends Model
public
function
dictionaryCampaignsNotEnabledForExternalNotDisabled
()
public
function
dictionaryCampaignsNotEnabledForExternalNotDisabled
()
{
{
return
$this
->
dictionaryCampaigns
ForExternal
()
->
enabled
(
false
)
->
notDisabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
(
false
)
->
forExternal
(
)
->
notDisabled
();
}
}
public
function
dictionaryCampaignsEnabledForExternalDisabled
()
public
function
dictionaryCampaignsEnabledForExternalDisabled
()
{
{
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
()
->
disabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
disabled
();
}
public
function
dictionaryCampaignsEnabledForExternalNeedUpdated
()
{
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
()
->
needUpdated
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronized
()
public
function
dictionaryCampaignsEnabledForExternalSynchronized
()
{
{
return
$this
->
dictionaryCampaigns
ForExternal
()
->
enabled
()
->
synchronized
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
synchronized
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
()
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
()
{
{
return
$this
->
dictionaryCampaigns
EnabledForExternalS
ynchronized
()
->
forUpdatedSelf
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
s
ynchronized
()
->
forUpdatedSelf
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
()
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
()
{
{
return
$this
->
dictionaryCampaigns
EnabledForExternalS
ynchronized
()
->
forUpdatedChildren
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
s
ynchronized
()
->
forUpdatedChildren
();
}
}
public
function
campaignsForManaged
()
public
function
campaignsForManaged
()
...
...
app/Models/User.php
View file @
76e0f90
...
@@ -5,6 +5,7 @@ namespace App\Models;
...
@@ -5,6 +5,7 @@ namespace App\Models;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Illuminate\Support\Facades\App
;
use
Illuminate\Support\Facades\App
;
...
@@ -87,22 +88,37 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
...
@@ -87,22 +88,37 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return
$this
->
email
===
'johndoe@example.com'
;
return
$this
->
email
===
'johndoe@example.com'
;
}
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeOrderByName
(
$query
)
public
function
scopeOrderByName
(
$query
)
{
{
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
return
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
}
}
/**
* @param Builder $query
* @param string $role
* @return Builder
*/
public
function
scopeWhereRole
(
$query
,
$role
)
public
function
scopeWhereRole
(
$query
,
$role
)
{
{
switch
(
$role
)
{
switch
(
$role
)
{
case
'user'
:
return
$query
->
where
(
'owner'
,
false
);
case
'user'
:
return
$query
->
where
(
'owner'
,
false
);
case
'owner'
:
return
$query
->
where
(
'owner'
,
true
);
case
'owner'
:
return
$query
->
where
(
'owner'
,
true
);
}
}
return
$query
;
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
...
...
app/Models/Variable.php
View file @
76e0f90
...
@@ -59,7 +59,11 @@ class Variable extends Model
...
@@ -59,7 +59,11 @@ class Variable extends Model
return
$variable_list
;
return
$variable_list
;
}
}
public
function
scopeDefaultOrderBy
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDefaultOrderBy
(
$query
)
{
{
return
$query
->
orderBy
(
'name'
);
return
$query
->
orderBy
(
'name'
);
}
}
...
...
app/Service/Limits.php
View file @
76e0f90
...
@@ -66,16 +66,23 @@ class Limits implements \App\Service\Contract\Limits {
...
@@ -66,16 +66,23 @@ class Limits implements \App\Service\Contract\Limits {
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
$maxCount
=
$request
->
getMaxCount
();
$maxCount
=
$request
->
getMaxCount
();
if
(
$cost
==
0
||
$maxCount
===
self
::
NAN
){
return
self
::
NAN
;
}
$objectsCount
=
$request
->
getObjectsCount
();
if
(
$this
->
token
->
limits
->
count
()
>
0
){
if
(
$this
->
limitCosts
->
getCostCall
(
$request
)
>
$this
->
current
()){
if
(
$this
->
limitCosts
->
getCostCall
(
$request
)
>
$this
->
current
()){
return
0
;
return
0
;
}
}
if
(
$cost
==
0
||
$maxCount
===
self
::
NAN
){
$allowCount
=
floor
((
$this
->
current
()
-
$this
->
limitCosts
->
getCostCall
(
$request
))
/
$cost
);
return
self
::
NAN
;
}
else
{
$allowCount
=
$objectsCount
;
//не было еще запросов, считаем что баллов хватает
}
}
$allowCount
=
floor
((
$this
->
current
()
-
$this
->
limitCosts
->
getCostCall
(
$request
))
/
$cost
);
$objectsCount
=
$request
->
getObjectsCount
();
if
(
$objectsCount
>
$maxCount
)
{
if
(
$objectsCount
>
$maxCount
)
{
$objectsCount
=
$maxCount
;
$objectsCount
=
$maxCount
;
...
@@ -99,7 +106,8 @@ class Limits implements \App\Service\Contract\Limits {
...
@@ -99,7 +106,8 @@ class Limits implements \App\Service\Contract\Limits {
function
doRezerv
(
\App\Service\Contract\APIRequest
$request
,
int
$objects
)
:
int
function
doRezerv
(
\App\Service\Contract\APIRequest
$request
,
int
$objects
)
:
int
{
{
$limit
=
$this
->
getSpent
(
$objects
,
$request
);
$limit
=
$this
->
getSpent
(
$objects
,
$request
);
if
(
$this
->
token
->
limit
<
$limit
){
if
(
$this
->
token
->
limits
->
count
()
>
0
&&
$this
->
token
->
limit
<
$limit
)
{
throw
new
\Exception
(
'Недостаточно баллов'
);
throw
new
\Exception
(
'Недостаточно баллов'
);
}
}
...
@@ -189,7 +197,7 @@ class Limits implements \App\Service\Contract\Limits {
...
@@ -189,7 +197,7 @@ class Limits implements \App\Service\Contract\Limits {
}
}
}
}
private
function
getSpent
(
$objects
,
\App\Service\Contract\APIRequest
$request
)
:
int
function
getSpent
(
$objects
,
\App\Service\Contract\APIRequest
$request
)
:
int
{
{
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
...
...
app/Service/Requests/Direct/CheckCampaignsChanges.php
View file @
76e0f90
...
@@ -31,7 +31,7 @@ class CheckCampaignsChanges extends DirectRequest
...
@@ -31,7 +31,7 @@ class CheckCampaignsChanges extends DirectRequest
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
])
||
in_array
(
self
::
CHILDREN
,
$campaign_data
[
'ChangesIn'
]))
{
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
])
||
in_array
(
self
::
CHILDREN
,
$campaign_data
[
'ChangesIn'
]))
{
$data
=
[];
$data
=
[];
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
]))
{
if
(
$this
->
getToken
()
->
isMain
()
&&
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
]))
{
$data
[
'updated_self'
]
=
Carbon
::
now
();
$data
[
'updated_self'
]
=
Carbon
::
now
();
}
}
...
@@ -52,10 +52,16 @@ class CheckCampaignsChanges extends DirectRequest
...
@@ -52,10 +52,16 @@ class CheckCampaignsChanges extends DirectRequest
}
else
{
}
else
{
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
->
find
(
$external_id
);
$dictionaryCampaign
=
DictionaryCampaign
::
firstWhere
(
'external_id'
,
$external_id
);
if
(
$dictionaryCampaign
)
{
if
(
$dictionaryCampaign
)
{
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
if
(
$dictionaryCampaign
->
updated
)
{
$data
[
'updated_need'
]
=
Carbon
::
now
();
}
$dictionaryCampaign
->
update
(
$data
);
$dictionaryCampaign
->
update
(
$data
);
}
}
...
...
app/Service/Requests/Direct/CheckChanges.php
View file @
76e0f90
...
@@ -72,15 +72,22 @@ class CheckChanges extends DirectRequest
...
@@ -72,15 +72,22 @@ class CheckChanges extends DirectRequest
$adGroup
->
update
([
$adGroup
->
update
([
'updated_self'
=>
Carbon
::
now
(),
'updated_self'
=>
Carbon
::
now
(),
]);
]);
}
else
{
$adGroup
=
AdGroup
::
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'external_id'
=>
$ad_group_id
,
'updated_self'
=>
Carbon
::
now
(),
]);
}
}
}
else
{
}
else
{
$goalAdGroup
=
GoalAdGroup
::
where
(
'external_id'
,
$ad_group_id
)
->
first
();
$goalAdGroup
=
GoalAdGroup
::
w
ith
(
'dictionaryCampaign'
)
->
firstW
here
(
'external_id'
,
$ad_group_id
)
->
first
();
if
(
$goalAdGroup
)
{
if
(
$goalAdGroup
&&
$goalAdGroup
->
dictionaryCampaign
&&
$goalAdGroup
->
dictionaryCampaign
->
updated
)
{
$goalAdGroup
->
update
([
$goalAdGroup
->
update
([
'updated_
self
'
=>
Carbon
::
now
(),
'updated_
need
'
=>
Carbon
::
now
(),
]);
]);
}
}
}
}
}
}
...
...
app/Service/Requests/DirectRequest.php
View file @
76e0f90
...
@@ -11,6 +11,7 @@ namespace App\Service\Requests;
...
@@ -11,6 +11,7 @@ namespace App\Service\Requests;
class
DirectRequest
extends
APIRequest
class
DirectRequest
extends
APIRequest
{
{
CONST
MAX_COUNT
=
10000
;
protected
$max_count
=
-
1
;
protected
$max_count
=
-
1
;
private
$url
;
private
$url
;
...
...
resources/js/Pages/Tokens/CitySettings.vue
View file @
76e0f90
...
@@ -78,6 +78,7 @@
...
@@ -78,6 +78,7 @@
</td>
</td>
<td
class=
"border-t text-center"
>
<td
class=
"border-t text-center"
>
<input
:checked=
"dictionary_campaign.enabled"
<input
:checked=
"dictionary_campaign.enabled"
disabled=
"disabled"
@
change=
"enabled(city.id, dictionary_campaign.campaign_id, !dictionary_campaign.enabled)"
@
change=
"enabled(city.id, dictionary_campaign.campaign_id, !dictionary_campaign.enabled)"
type=
"checkbox"
type=
"checkbox"
>
>
...
...
resources/js/Pages/Tokens/Edit.vue
View file @
76e0f90
...
@@ -112,13 +112,13 @@ export default {
...
@@ -112,13 +112,13 @@ export default {
},
},
citySynced
(
city_id
,
campaign_id
,
synced
)
{
citySynced
(
city_id
,
campaign_id
,
synced
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.synced'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.synced'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
updat
ed
:
synced
?
1
:
0
,
sync
ed
:
synced
?
1
:
0
,
})
})
},
},
cityEnabled
(
city_id
,
campaign_id
,
enabled
)
{
cityEnabled
(
city_id
,
campaign_id
,
enabled
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.enabled'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
//
this.$inertia.post(this.route('token.city.campaign.enabled', [this.token.id, city_id, campaign_id]), {
enabled
:
enabled
?
1
:
0
,
//
enabled: enabled ? 1 : 0,
})
//
})
},
},
cityDelete
(
id
)
{
cityDelete
(
id
)
{
if
(
confirm
(
'Are you sure you want to delete this city?'
))
{
if
(
confirm
(
'Are you sure you want to delete this city?'
))
{
...
...
routes/web.php
View file @
76e0f90
...
@@ -191,8 +191,8 @@ Route::group(['middleware' => 'auth'], function () {
...
@@ -191,8 +191,8 @@ Route::group(['middleware' => 'auth'], function () {
->
name
(
'token.city.campaign.updated'
);
->
name
(
'token.city.campaign.updated'
);
Route
::
post
(
'token/city/campaign/synced/{token}/{dictionary}/{campaign_id}'
,
[
TokensController
::
class
,
'syncedCityCampaign'
])
Route
::
post
(
'token/city/campaign/synced/{token}/{dictionary}/{campaign_id}'
,
[
TokensController
::
class
,
'syncedCityCampaign'
])
->
name
(
'token.city.campaign.synced'
);
->
name
(
'token.city.campaign.synced'
);
Route
::
post
(
'token/city/campaign/enabled/{token}/{dictionary}/{campaign_id}'
,
[
TokensController
::
class
,
'enabledCityCampaign'
])
//
Route::post('token/city/campaign/enabled/{token}/{dictionary}/{campaign_id}', [TokensController::class, 'enabledCityCampaign'])
->
name
(
'token.city.campaign.enabled'
);
//
->name('token.city.campaign.enabled');
Route
::
delete
(
'token/city/{token}/{dictionary}'
,
[
TokensController
::
class
,
'destroyCity'
])
Route
::
delete
(
'token/city/{token}/{dictionary}'
,
[
TokensController
::
class
,
'destroyCity'
])
->
name
(
'token.city.destroy'
);
->
name
(
'token.city.destroy'
);
...
...
tests/Unit/CallLimitedApiTest.php
View file @
76e0f90
...
@@ -56,12 +56,6 @@ class CallLimitedApiTest extends TestCase
...
@@ -56,12 +56,6 @@ class CallLimitedApiTest extends TestCase
dispatch
(
$process
)
->
onQueue
(
'limits'
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
,
2
);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
,
2
);
$this
->
token
->
limit
=
14
;
$this
->
request
->
setService
(
'AdGroups'
);
$this
->
request
->
setMethod
(
'get'
);
$process
->
handle
();
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
,
3
);
$this
->
token
->
limit
=
15
;
$this
->
token
->
limit
=
15
;
$this
->
request
->
setService
(
'AdGroups'
);
$this
->
request
->
setService
(
'AdGroups'
);
$this
->
request
->
setMethod
(
'get'
);
$this
->
request
->
setMethod
(
'get'
);
...
...
tests/Unit/CheckCampaignsTest.php
View file @
76e0f90
...
@@ -131,6 +131,38 @@ class CheckCampaignsTest extends TestCase
...
@@ -131,6 +131,38 @@ class CheckCampaignsTest extends TestCase
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
count
());
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
count
());
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$campaign
->
pivot
->
update
([
'external_id'
=>
1
,
]);
$this
->
request
->
handle
([
'result'
=>
[
'Timestamp'
=>
1622459200
,
'Campaigns'
=>
[
[
'ChangesIn'
=>
[
'SELF'
,
'CHILDREN'
],
'CampaignId'
=>
1
]
]
]
]);
$this
->
assertEquals
(
$this
->
request
->
getToken
()
->
check_changes_campaign_at
->
timestamp
,
1622459200
);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
true
,
$campaign
->
pivot
->
updated
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_need
);
$campaign
->
pivot
->
update
([
'external_updated_at'
=>
null
,
'updated_need'
=>
null
,
'updated'
=>
false
,
]);
$this
->
request
->
handle
([
$this
->
request
->
handle
([
'result'
=>
[
'result'
=>
[
'Timestamp'
=>
1622459200
,
'Timestamp'
=>
1622459200
,
...
@@ -147,9 +179,16 @@ class CheckCampaignsTest extends TestCase
...
@@ -147,9 +179,16 @@ class CheckCampaignsTest extends TestCase
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
false
,
$campaign
->
pivot
->
updated
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_self
);
$this
->
assertNull
(
$campaign
->
pivot
->
updated_need
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_children
);
$campaign
->
pivot
->
update
([
'updated'
=>
true
,
]);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$campaign
->
pivot
->
update
([
$campaign
->
pivot
->
update
([
'external_id'
=>
1
,
'external_id'
=>
1
,
...
@@ -169,7 +208,7 @@ class CheckCampaignsTest extends TestCase
...
@@ -169,7 +208,7 @@ class CheckCampaignsTest extends TestCase
$campaign
->
pivot
->
update
([
$campaign
->
pivot
->
update
([
'
sync
ed'
=>
false
,
'
updat
ed'
=>
false
,
]);
]);
$campaign
->
update
([
$campaign
->
update
([
...
...
tests/Unit/CheckChangesAdGroupsTest.php
View file @
76e0f90
...
@@ -139,7 +139,15 @@ class CheckChangesAdGroupsTest extends TestCase
...
@@ -139,7 +139,15 @@ class CheckChangesAdGroupsTest extends TestCase
$this
->
assertEquals
(
0
,
AdGroup
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
0
,
AdGroup
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
1
,
Campaigns
::
forUpdatedChildren
()
->
count
());
$this
->
assertEquals
(
1
,
Campaigns
::
forUpdatedChildren
()
->
count
());
$this
->
assertEquals
(
$this
->
ad_group
->
name
,
GoalAdGroup
::
first
()
->
name
);
$goalAdGroup
=
GoalAdGroup
::
first
();
$goalAdGroup
->
update
([
'external_id'
=>
1
,
]);
$goalAdGroup
->
refresh
();
$this
->
assertEquals
(
$this
->
ad_group
->
name
,
$goalAdGroup
->
name
);
$this
->
request_main
->
setParams
(
$this
->
request_main_params
);
$this
->
request_main
->
setParams
(
$this
->
request_main_params
);
...
@@ -168,13 +176,10 @@ class CheckChangesAdGroupsTest extends TestCase
...
@@ -168,13 +176,10 @@ class CheckChangesAdGroupsTest extends TestCase
$this
->
assertEquals
(
0
,
AdGroup
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
0
,
AdGroup
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
$this
->
ad_group
->
name
);
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
$this
->
ad_group
->
name
);
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
GoalAdGroup
::
first
()
->
name
);
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
GoalAdGroup
::
first
()
->
name
);
$this
->
assertEquals
(
1
,
GoalAdGroup
::
needUpdated
()
->
count
());
$
goalAdGroup
=
GoalAdGroup
::
needUpdated
()
->
first
(
);
$
this
->
assertEquals
(
1
,
GoalAdGroup
::
needUpdated
()
->
count
()
);
$goalAdGroup
->
update
([
$goalAdGroup
->
refresh
();
'external_id'
=>
1
,
]);
$this
->
request_main
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
$this
->
request_main
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$this
->
token_main
)
->
setToken
(
$this
->
token_main
)
...
...
tests/Unit/LimitsTest.php
View file @
76e0f90
...
@@ -159,14 +159,22 @@ class LimitsTest extends TestCase
...
@@ -159,14 +159,22 @@ class LimitsTest extends TestCase
Queue
::
fake
();
Queue
::
fake
();
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'get'
);
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'get'
);
$this
->
token
->
limit
=
191
;
$this
->
token
->
limit
=
191
;
$this
->
token
->
save
();
$requestCmpgn
->
call
();
$requestCmpgn
->
call
();
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$this
->
assertEquals
(
$objects
,
-
1
);
$this
->
limitService
->
doRezerv
(
$requestCmpgn
,
$objects
);
$this
->
token
->
refresh
();
$this
->
assertEquals
(
$this
->
token
->
limit
,
181
);
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'update'
);
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'update'
);
$this
->
token
->
limit
=
191
;
$this
->
token
->
limit
=
191
;
$requestCmpgn
->
call
([
$requestCmpgn
->
call
([
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsEnabledForExternalNeedUpdated
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsEnabledForExternal
Updated
NeedUpdated
]);
]);
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$this
->
assertEquals
(
$objects
,
0
);
$this
->
assertEquals
(
$objects
,
0
);
...
@@ -184,6 +192,18 @@ class LimitsTest extends TestCase
...
@@ -184,6 +192,18 @@ class LimitsTest extends TestCase
$request
->
setService
(
'AdExtensions'
);
$request
->
setService
(
'AdExtensions'
);
$request
->
setMethod
(
'add'
);
$request
->
setMethod
(
'add'
);
$rezerv
=
new
\App\Models\Limits
();
$rezerv
->
token
=
$this
->
token
->
id
;
$rezerv
->
service
=
'dsd'
;
$rezerv
->
method
=
'asdas'
;
$rezerv
->
spent
=
1
;
$rezerv
->
day
=
0
;
$rezerv
->
current
=
$this
->
token
->
limit
;
$rezerv
->
reserved
=
1
;
$rezerv
->
save
();
$this
->
token
->
refresh
();
//т.к. для первого вызова не будет происходить проверки баллов
$this
->
expectException
(
\Exception
::
class
);
$this
->
expectException
(
\Exception
::
class
);
$this
->
limitService
->
doRezerv
(
$request
,
$this
->
token
->
limit
);
$this
->
limitService
->
doRezerv
(
$request
,
$this
->
token
->
limit
);
}
}
...
...
tests/Unit/ProcessCallSliceTest.php
View file @
76e0f90
...
@@ -98,10 +98,9 @@ class ProcessCallSliceTest extends TestCase
...
@@ -98,10 +98,9 @@ class ProcessCallSliceTest extends TestCase
$this
->
request
->
call
(
$this
->
params
);
$this
->
request
->
call
(
$this
->
params
);
$this
->
request_resume
->
call
([
$this
->
request_resume
->
call
([
'ids'
=>
range
(
0
,
$this
->
dictionaries_count
-
1
)
'ids'
=>
range
(
1
,
2005
)
]);
]);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
$limits
=
Limits
::
getInstance
(
$this
->
request
->
getToken
());
$limits
=
Limits
::
getInstance
(
$this
->
request
->
getToken
());
...
@@ -113,8 +112,8 @@ class ProcessCallSliceTest extends TestCase
...
@@ -113,8 +112,8 @@ class ProcessCallSliceTest extends TestCase
$requestR
=
$this
->
request
->
slice
(
$maxObjects
);
$requestR
=
$this
->
request
->
slice
(
$maxObjects
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
2
,
$this
->
request
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
request
->
getMaxCount
()
,
$this
->
request
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
2
,
$requestR
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
$this
->
request
->
getMaxCount
()
,
$requestR
->
getObjectsCount
());
$limits
=
Limits
::
getInstance
(
$this
->
request_resume
->
getToken
());
$limits
=
Limits
::
getInstance
(
$this
->
request_resume
->
getToken
());
...
@@ -126,8 +125,8 @@ class ProcessCallSliceTest extends TestCase
...
@@ -126,8 +125,8 @@ class ProcessCallSliceTest extends TestCase
$requestR
=
$this
->
request_resume
->
slice
(
$maxObjects
);
$requestR
=
$this
->
request_resume
->
slice
(
$maxObjects
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
2
,
$this
->
request_resume
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
request_resume
->
getMaxCount
()
,
$this
->
request_resume
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
2
,
$requestR
->
getObjectsCount
());
$this
->
assertEquals
(
2005
-
$this
->
request_resume
->
getMaxCount
()
,
$requestR
->
getObjectsCount
());
}
}
...
...
tests/Unit/ReplaceByVariablesTest.php
View file @
76e0f90
...
@@ -67,6 +67,12 @@ class ReplaceByVariablesTest extends TestCase
...
@@ -67,6 +67,12 @@ class ReplaceByVariablesTest extends TestCase
$this
->
dictionaryCampaign
=
DictionaryCampaign
::
first
();
$this
->
dictionaryCampaign
=
DictionaryCampaign
::
first
();
$this
->
dictionaryCampaign
->
update
([
'external_id'
=>
1
,
]);
$this
->
dictionaryCampaign
->
refresh
();
$this
->
assertNull
(
$this
->
dictionaryCampaign
->
updated_need
);
$this
->
assertNull
(
$this
->
dictionaryCampaign
->
updated_need
);
$this
->
actingAs
(
$this
->
user
)
$this
->
actingAs
(
$this
->
user
)
...
...
tests/Unit/UpdateCampaignsTest.php
0 → 100644
View file @
76e0f90
<?php
namespace
Tests\Unit
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Service\Contract\API
;
use
App\Service\Requests\APIRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
UpdateCampaignsTest
extends
TestCase
{
use
RefreshDatabase
;
private
$request
;
private
$user
;
private
$token_main
;
protected
function
setUp
()
:
void
{
parent
::
setUp
();
$account
=
Account
::
create
([
'name'
=>
'Acme Corporation'
]);
$this
->
user
=
factory
(
User
::
class
)
->
create
([
'account_id'
=>
$account
->
id
,
'first_name'
=>
'John'
,
'last_name'
=>
'Doe'
,
'email'
=>
'johndoe@example.com'
,
'owner'
=>
true
,
]);
$this
->
token_main
=
factory
(
Tokens
::
class
)
->
create
([
'type'
=>
Tokens
::
MAIN
,
'created_by'
=>
$this
->
user
->
id
,
]);
$this
->
token
=
factory
(
Tokens
::
class
)
->
create
([
'limit'
=>
20
,
'created_by'
=>
$this
->
user
->
getKey
()
]);
$this
->
request
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$this
->
token_main
)
->
getRequest
(
'Campaigns'
,
'update'
);
$this
->
campaign
=
factory
(
Campaigns
::
class
)
->
create
([
'manage'
=>
true
,
'token'
=>
$this
->
token_main
->
getKey
(),
]);
$this
->
dictionaries
=
factory
(
Dictionary
::
class
,
12
)
->
create
([
'token_id'
=>
$this
->
token
->
getKey
(),
'type'
=>
Dictionary
::
CITY
,
]);
$this
->
campaign
->
dictionaries
()
->
syncWithoutDetaching
(
$this
->
dictionaries
->
keyBy
(
Campaigns
::
getModel
()
->
getKeyName
())
->
transform
(
function
(
Dictionary
$dictionary
)
{
return
DictionaryCampaign
::
copyPropertyFromMain
(
$this
->
campaign
);
})
->
all
()
);
}
function
test_get_campaigns_for_update
(){
$dictionaryCampaign
=
DictionaryCampaign
::
first
();
$dictionaryCampaign
[
'external_id'
]
=
1
;
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
if
(
$dictionaryCampaign
->
updated
)
{
$data
[
'updated_need'
]
=
Carbon
::
now
();
}
$dictionaryCampaign
->
update
(
$data
);
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated.campaign'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
Queue
::
fake
();
foreach
(
$tokens
as
$token
)
{
$this
->
assertEquals
(
$dictionaryCampaign
->
toArray
()[
'external_id'
],
$token
->
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
->
toArray
()[
0
][
'external_id'
]);
$this
->
request
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
,
]);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
}
}
}
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