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 309600cd
authored
May 25, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19466 Остановка РК
1 parent
1359384c
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
439 additions
and
42 deletions
app/Console/Commands/CampaignsAdd.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsResume.php
app/Console/Commands/CampaignsSuspend.php
app/Console/Commands/CampaignsUpdate.php
app/Http/Controllers/TokensController.php
app/Models/Campaigns.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Tokens.php
app/Service/Requests/Direct/ResumeCampaigns.php
app/Service/Requests/Direct/SuspendCampaigns.php
app/Service/Requests/Direct/UpdateCampaigns.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
resources/js/Pages/Tokens/CampaignsSettings.vue
resources/js/Pages/Tokens/CitySettings.vue
resources/js/Pages/Tokens/Edit.vue
routes/web.php
tests/Unit/AddCampaignsTest.php
app/Console/Commands/CampaignsAdd.php
View file @
309600c
...
...
@@ -42,12 +42,12 @@ class CampaignsAdd extends Command
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsForNotExternal'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaigns
Enabled
ForNotExternal'
)
->
with
([
'dictionaryCampaignsForNotExternal'
=>
function
(
HasManyThrough
$query
)
{
'dictionaryCampaigns
Enabled
ForNotExternal'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
10
);
},
'dictionaryCampaignsForNotExternal.campaign'
'dictionaryCampaigns
Enabled
ForNotExternal.campaign'
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
...
...
@@ -57,7 +57,7 @@ class CampaignsAdd extends Command
$factory
->
getRequest
(
'campaigns'
,
'add'
)
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsForNotExternal
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaigns
Enabled
ForNotExternal
,
'variables'
=>
Variable
::
all
(),
]);
}
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
309600c
...
...
@@ -11,6 +11,7 @@ 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
CampaignsLoadUpdated
extends
Command
...
...
@@ -70,16 +71,21 @@ class CampaignsLoadUpdated extends Command
})
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsForExternalSynchronizedUpdatedSelf'
)
->
with
(
'dictionaryCampaignsForExternalSynchronizedUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf'
)
->
with
([
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
10
);
},
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'change'
,
'checkCampaigns'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsForExternalSynchronizedUpdatedSelf
->
map
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
'ids'
=>
$token
->
dictionaryCampaigns
Enabled
ForExternalSynchronizedUpdatedSelf
->
map
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
return
$dictionaryCampaign
->
external_id
;
})
]);
...
...
app/Console/Commands/CampaignsResume.php
0 → 100644
View file @
309600c
<?php
namespace
App\Console\Commands
;
use
App\Models\Tokens
;
use
App\Models\Variable
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
class
CampaignsResume
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'campaigns:resume'
;
/**
* 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
()
{
$token_main
=
Tokens
::
whereHas
(
'campaignsEnabledDisabled'
)
->
with
([
'campaignsEnabledDisabled'
=>
function
(
HasMany
$query
)
{
return
$query
->
limit
(
1000
);
},
])
->
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
$token_main
){
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token_main
);
$factory
->
getRequest
(
'campaigns'
,
'resume'
)
->
call
([
'ids'
=>
$token_main
->
campaignsEnabledDisabled
->
pluck
(
'external_id'
),
]);
}
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalDisabled'
)
->
with
([
'dictionaryCampaignsEnabledForExternalDisabled'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
1000
);
},
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'campaigns'
,
'resume'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalDisabled
->
pluck
(
'external_id'
),
]);
}
return
0
;
}
}
app/Console/Commands/CampaignsSuspend.php
0 → 100644
View file @
309600c
<?php
namespace
App\Console\Commands
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
class
CampaignsSuspend
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'campaigns:suspend'
;
/**
* 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
()
{
$token_main
=
Tokens
::
whereHas
(
'campaignsNotEnabledNotDisabled'
)
->
with
([
'campaignsNotEnabledNotDisabled'
=>
function
(
HasMany
$query
)
{
return
$query
->
limit
(
1000
);
},
])
->
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
$token_main
){
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token_main
);
$factory
->
getRequest
(
'campaigns'
,
'suspend'
)
->
call
([
'ids'
=>
$token_main
->
campaignsNotEnabledNotDisabled
->
pluck
(
'external_id'
),
]);
}
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsNotEnabledForExternalNotDisabled'
)
->
with
([
'dictionaryCampaignsNotEnabledForExternalNotDisabled'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
1000
);
},
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'campaigns'
,
'suspend'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsNotEnabledForExternalNotDisabled
->
pluck
(
'external_id'
),
]);
}
return
0
;
}
}
app/Console/Commands/CampaignsUpdate.php
View file @
309600c
...
...
@@ -42,12 +42,12 @@ class CampaignsUpdate extends Command
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsForExternalNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaigns
Enabled
ForExternalNeedUpdated'
)
->
with
([
'dictionaryCampaignsForExternalNeedUpdated'
=>
function
(
HasManyThrough
$query
)
{
'dictionaryCampaigns
Enabled
ForExternalNeedUpdated'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
10
);
},
'dictionaryCampaignsForExternalNeedUpdated.campaign'
'dictionaryCampaigns
Enabled
ForExternalNeedUpdated.campaign'
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
...
...
@@ -57,7 +57,7 @@ class CampaignsUpdate extends Command
$factory
->
getRequest
(
'campaigns'
,
'update'
)
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsForExternalNeedUpdated
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaigns
Enabled
ForExternalNeedUpdated
,
'variables'
=>
Variable
::
all
(),
]);
}
...
...
app/Http/Controllers/TokensController.php
View file @
309600c
...
...
@@ -201,7 +201,7 @@ class TokensController extends Controller
'updated'
=>
!!
request
(
'updated'
),
]);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'Campaign updated.'
);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'C
ity c
ampaign updated.'
);
}
public
function
syncedCityCampaign
(
Tokens
$token
,
Dictionary
$dictionary
,
$campaign_id
)
...
...
@@ -220,7 +220,26 @@ class TokensController extends Controller
'synced'
=>
!!
request
(
'synced'
),
]);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City synced.'
);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City campaign synced.'
);
}
public
function
enabledCityCampaign
(
Tokens
$token
,
Dictionary
$dictionary
,
$campaign_id
)
{
if
(
$token
->
isMain
())
{
return
Redirect
::
back
();
}
$campaign
=
$dictionary
->
campaigns
()
->
find
(
$campaign_id
);
if
(
!
$campaign
)
{
return
Redirect
::
back
();
}
$campaign
->
pivot
->
update
([
'enabled'
=>
!!
request
(
'enabled'
),
]);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City campaign '
.
(
$campaign
->
pivot
->
enabled
?
'enabled'
:
'disabled'
)
.
'.'
);
}
public
function
destroyCity
(
Tokens
$token
,
Dictionary
$dictionary
)
...
...
app/Models/Campaigns.php
View file @
309600c
...
...
@@ -48,6 +48,8 @@ use Illuminate\Support\Collection;
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns notDisabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns disabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdatedSelf()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdatedChildren()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newModelQuery()
...
...
@@ -104,6 +106,7 @@ class Campaigns extends Model
'updated_children'
,
'manage'
,
'enabled'
,
'disabled_at'
,
];
protected
$casts
=
[
...
...
@@ -121,6 +124,7 @@ class Campaigns extends Model
'updated_children'
=>
'datetime'
,
'manage'
=>
'boolean'
,
'enabled'
=>
'boolean'
,
'disabled_at'
=>
'datetime'
,
];
/**
...
...
@@ -195,7 +199,7 @@ class Campaigns extends Model
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
$campaign
->
dictionaryCampaigns
()
->
synchronized
()
->
update
(
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
synchronized
()
->
update
(
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
)
);
}
...
...
@@ -203,7 +207,7 @@ class Campaigns extends Model
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
$campaign
->
dictionaryCampaigns
()
->
synchronized
()
->
forExternal
()
->
update
([
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
synchronized
()
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
]);
}
...
...
@@ -259,4 +263,14 @@ class Campaigns extends Model
$query
->
where
(
'enabled'
,
$enabled
);
}
public
function
scopeDisabled
(
Builder
$query
)
{
return
$query
->
whereNotNull
(
'disabled_at'
);
}
public
function
scopeNotDisabled
(
Builder
$query
)
{
return
$query
->
whereNull
(
'disabled_at'
);
}
}
app/Models/Pivots/DictionaryCampaign.php
View file @
309600c
...
...
@@ -25,6 +25,7 @@ use Illuminate\Support\Collection;
* @property string|null $name
* @property array|null $negative_keywords
* @property array|null $excluded_sites
* @property bool $enabled
* @property bool $updated
* @property bool $synced
* @property \Illuminate\Support\Carbon|null $external_upload_at
...
...
@@ -33,8 +34,11 @@ use Illuminate\Support\Collection;
* @property-read int|null $dictionary_campaign_variables_count
* @property-read int|null $variables_count
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forExternal()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign notDisabled()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign disabled()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forNotExternal()
* @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 updated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
...
...
@@ -75,8 +79,10 @@ class DictionaryCampaign extends Pivot
'updated_need'
,
'updated_self'
,
'updated_children'
,
'enabled'
,
'updated'
,
'synced'
,
'disabled_at'
,
];
protected
$casts
=
[
...
...
@@ -90,8 +96,10 @@ class DictionaryCampaign extends Pivot
'updated_need'
=>
'datetime'
,
'updated_self'
=>
'datetime'
,
'updated_children'
=>
'datetime'
,
'enabled'
=>
'boolean'
,
'updated'
=>
'boolean'
,
'synced'
=>
'boolean'
,
'disabled_at'
=>
'datetime'
,
];
static
public
function
getWithPivot
()
...
...
@@ -107,8 +115,10 @@ class DictionaryCampaign extends Pivot
'updated_need'
,
'updated_self'
,
'updated_children'
,
'enabled'
,
'updated'
,
'synced'
,
'disabled_at'
,
];
}
...
...
@@ -147,6 +157,16 @@ class DictionaryCampaign extends Pivot
})
->
all
();
}
public
function
scopeDisabled
(
Builder
$query
)
{
return
$query
->
whereNotNull
(
'disabled_at'
);
}
public
function
scopeNotDisabled
(
Builder
$query
)
{
return
$query
->
whereNull
(
'disabled_at'
);
}
public
function
scopeForExternal
(
Builder
$query
)
{
return
$query
->
whereNotNull
(
'external_id'
);
...
...
@@ -157,6 +177,11 @@ class DictionaryCampaign extends Pivot
return
$query
->
whereNull
(
'external_id'
);
}
public
function
scopeEnabled
(
Builder
$query
,
$enabled
=
true
)
{
return
$query
->
where
(
'enabled'
,
$enabled
);
}
public
function
scopeUpdated
(
Builder
$query
,
$updated
=
true
)
{
return
$query
->
where
(
'updated'
,
$updated
);
...
...
app/Models/Tokens.php
View file @
309600c
...
...
@@ -20,14 +20,18 @@ use Illuminate\Database\Eloquent\Model;
* @property int $limit
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @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\Dictionary[] $cities
* @property-read int|null $cities_count
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaigns
* @property-read int|null $dictionary_campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternalNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsNotForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Limits[] $limits
...
...
@@ -88,6 +92,16 @@ class Tokens extends Model
->
orderBy
(
'updated_at'
,
'DESC'
);
}
public
function
campaignsNotEnabledNotDisabled
()
{
return
$this
->
campaigns
()
->
forEnabled
(
false
)
->
notDisabled
();
}
public
function
campaignsEnabledDisabled
()
{
return
$this
->
campaigns
()
->
forEnabled
()
->
disabled
();
}
public
function
cities
()
{
return
$this
->
hasMany
(
Dictionary
::
class
,
'token_id'
,
'id'
)
...
...
@@ -101,24 +115,34 @@ class Tokens extends Model
->
orderBy
(
DictionaryCampaign
::
getModel
()
->
getTable
()
.
'.'
.
DictionaryCampaign
::
getModel
()
->
getKeyName
(),
'ASC'
);
}
public
function
dictionaryCampaignsForNotExternal
()
public
function
dictionaryCampaignsForExternal
()
{
return
$this
->
dictionaryCampaigns
()
->
forExternal
();
}
public
function
dictionaryCampaignsEnabledForNotExternal
()
{
return
$this
->
dictionaryCampaigns
()
->
forNotExternal
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forNotExternal
();
}
public
function
dictionaryCampaigns
ForExternal
()
public
function
dictionaryCampaigns
NotEnabledForExternalNotDisabled
()
{
return
$this
->
dictionaryCampaigns
()
->
forExternal
();
return
$this
->
dictionaryCampaigns
()
->
enabled
(
false
)
->
forExternal
()
->
notDisabled
();
}
public
function
dictionaryCampaignsEnabledForExternalDisabled
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
disabled
();
}
public
function
dictionaryCampaignsForExternalNeedUpdated
()
public
function
dictionaryCampaigns
Enabled
ForExternalNeedUpdated
()
{
return
$this
->
dictionaryCampaigns
()
->
forExternal
()
->
needUpdated
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
needUpdated
();
}
public
function
dictionaryCampaignsForExternalSynchronizedUpdatedSelf
()
public
function
dictionaryCampaigns
Enabled
ForExternalSynchronizedUpdatedSelf
()
{
return
$this
->
dictionaryCampaignsForExternal
()
->
synchronized
()
->
forUpdatedSelf
();
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
()
->
synchronized
()
->
forUpdatedSelf
();
}
public
function
campaignsForManaged
()
...
...
app/Service/Requests/Direct/ResumeCampaigns.php
0 → 100644
View file @
309600c
<?php
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
ResumeCampaigns
extends
DirectRequest
{
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
function
handle
(
$response
)
{
try
{
foreach
(
$response
[
'result'
][
'ResumeResults'
]
as
$resume_result
)
{
$external_id
=
$resume_result
[
'Id'
]
??
''
;
if
(
!
$external_id
)
{
Log
::
debug
(
"resumeCampaigns, empty Id"
,
$resume_result
);
continue
;
}
if
(
$this
->
getToken
()
->
isMain
())
{
Campaigns
::
where
(
'external_id'
,
$external_id
)
->
update
([
'disabled_at'
=>
null
,
]);
}
else
{
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
->
update
([
'disabled_at'
=>
null
,
]);
}
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
}
}
private
function
requestPrepare
(
$filter
)
{
$this
->
setService
(
'campaigns'
);
$this
->
setMethod
(
'resume'
);
$params
=
[
'SelectionCriteria'
=>
[
'Ids'
=>
$filter
[
'ids'
],
],
];
$this
->
setParams
(
$params
);
}
}
app/Service/Requests/Direct/SuspendCampaigns.php
0 → 100644
View file @
309600c
<?php
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
SuspendCampaigns
extends
DirectRequest
{
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
function
handle
(
$response
)
{
try
{
foreach
(
$response
[
'result'
][
'SuspendResults'
]
as
$suspend_result
)
{
$external_id
=
$suspend_result
[
'Id'
]
??
''
;
if
(
!
$external_id
)
{
Log
::
debug
(
"SuspendCampaigns, empty Id"
,
$suspend_result
);
continue
;
}
if
(
$this
->
getToken
()
->
isMain
())
{
Campaigns
::
where
(
'external_id'
,
$external_id
)
->
update
([
'disabled_at'
=>
Carbon
::
now
(),
]);
}
else
{
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
->
update
([
'disabled_at'
=>
Carbon
::
now
(),
]);
}
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
}
}
private
function
requestPrepare
(
$filter
)
{
$this
->
setService
(
'campaigns'
);
$this
->
setMethod
(
'suspend'
);
$params
=
[
'SelectionCriteria'
=>
[
'Ids'
=>
$filter
[
'ids'
],
],
];
$this
->
setParams
(
$params
);
}
}
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
309600c
...
...
@@ -30,17 +30,16 @@ class UpdateCampaigns extends DirectRequest
public
function
handle
(
$response
)
{
try
{
Log
::
debug
(
$response
);
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$add_result
)
{
$id
=
$add_result
[
'Id'
]
??
''
;
$
external_
id
=
$add_result
[
'Id'
]
??
''
;
if
(
!
$id
)
{
if
(
!
$
external_
id
)
{
Log
::
debug
(
"AddCampaigns, empty Id, [dictionary_campaigns.id =
{
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
getKey
()
}
]"
,
$add_result
);
continue
;
}
DictionaryCampaign
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$id
)
->
where
(
'external_id'
,
$
external_
id
)
->
update
([
'updated_need'
=>
null
,
]);
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
309600c
...
...
@@ -36,6 +36,7 @@ class CreateCampaignsTable extends Migration
$table
->
boolean
(
'manage'
)
->
default
(
0
);
$table
->
boolean
(
'enabled'
)
->
default
(
1
);
$table
->
timestamp
(
'groups_loaded_at'
)
->
nullable
();
$table
->
timestamp
(
'disabled_at'
)
->
nullable
();
$table
->
timestamps
();
$table
->
foreign
(
'token'
)
->
references
(
'id'
)
->
on
(
'tokens'
);
...
...
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
View file @
309600c
...
...
@@ -23,11 +23,13 @@ class CreateDictionaryCampaignsTable extends Migration
$table
->
text
(
'excluded_sites'
)
->
nullable
();
$table
->
boolean
(
'synced'
)
->
default
(
1
);
$table
->
boolean
(
'updated'
)
->
default
(
0
);
$table
->
boolean
(
'enabled'
)
->
default
(
1
);
$table
->
timestamp
(
'external_upload_at'
)
->
nullable
();
$table
->
timestamp
(
'external_updated_at'
)
->
nullable
();
$table
->
timestamp
(
'updated_need'
)
->
nullable
();
$table
->
timestamp
(
'updated_self'
)
->
nullable
();
$table
->
timestamp
(
'updated_children'
)
->
nullable
();
$table
->
timestamp
(
'disabled_at'
)
->
nullable
();
$table
->
timestamps
();
...
...
resources/js/Pages/Tokens/CampaignsSettings.vue
View file @
309600c
...
...
@@ -39,13 +39,16 @@
type=
"checkbox"
>
<label
:for=
"'campaign-enabled-' + campaign.id"
>
Enabled
</label>
<button
class=
"text-red-600 hover:underline"
</td>
<td
class=
"border-t w-px"
>
<div
class=
"px-6 py-4"
>
<button
class=
"px-4 flex items-center"
tabindex=
"-1"
type=
"button"
@
click=
"destroy(campaign.id)"
>
Delete Campaign
<icon
name=
"trash"
class=
"block w-6 h-6 fill-gray-400"
/>
</button>
</div>
</td>
</tr>
<tr
v-if=
"token.campaigns.length === 0"
>
...
...
resources/js/Pages/Tokens/CitySettings.vue
View file @
309600c
...
...
@@ -48,7 +48,8 @@
<th
class=
"px-6 pt-6 pb-4"
>
Кампания
</th>
<th
class=
"px-6 pt-6 pb-4"
>
Обновлять?
</th>
<th
class=
"px-6 pt-6 pb-4"
>
Синхронизировать?
</th>
<th
class=
"px-6 pt-6 pb-4"
colspan=
"2"
></th>
<th
class=
"px-6 pt-6 pb-4"
>
Включено?
</th>
<th
class=
"px-6 pt-6 pb-4"
></th>
</tr>
<tr
v-if=
"city.dictionary_campaigns.length"
:key=
"dictionary_campaign.id"
v-for=
"dictionary_campaign in city.dictionary_campaigns"
>
<td
class=
"border-t"
></td>
...
...
@@ -75,7 +76,13 @@
type=
"checkbox"
>
</td>
<td
class=
"border-t"
colspan=
"2"
></td>
<td
class=
"border-t text-center"
>
<input
:checked=
"dictionary_campaign.enabled"
@
change=
"enabled(city.id, dictionary_campaign.campaign_id, !dictionary_campaign.enabled)"
type=
"checkbox"
>
</td>
<td
class=
"border-t"
></td>
</tr>
</
template
>
<tr
v-if=
"token.cities.length === 0"
>
...
...
@@ -99,7 +106,6 @@
main_token_campaigns
:
Array
,
},
data
()
{
console
.
log
(
this
.
token
.
cities
[
0
]);
return
{
city
:
false
}
...
...
@@ -121,6 +127,9 @@
updated
(
city_id
,
campaign_id
,
updated
)
{
this
.
$emit
(
'updated'
,
city_id
,
campaign_id
,
updated
)
},
enabled
(
city_id
,
campaign_id
,
updated
)
{
this
.
$emit
(
'enabled'
,
city_id
,
campaign_id
,
updated
)
},
}
}
</
script
>
resources/js/Pages/Tokens/Edit.vue
View file @
309600c
...
...
@@ -51,8 +51,9 @@
:main_token_campaigns=
"main_token_campaigns"
v-on:add=
"cityAdd"
v-on:delete=
"cityDelete"
v-on:updated=
"campaignUpdated"
v-on:synced=
"campaignSynced"
v-on:updated=
"cityUpdated"
v-on:synced=
"citySynced"
v-on:enabled=
"cityEnabled"
></city-settings>
</div>
</
template
>
...
...
@@ -104,16 +105,21 @@ export default {
cityAdd
(
id
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.store'
,
[
this
.
token
.
id
,
id
]))
},
c
ampaign
Updated
(
city_id
,
campaign_id
,
updated
)
{
c
ity
Updated
(
city_id
,
campaign_id
,
updated
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.updated'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
updated
:
updated
?
1
:
0
,
})
},
c
ampaign
Synced
(
city_id
,
campaign_id
,
synced
)
{
c
ity
Synced
(
city_id
,
campaign_id
,
synced
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.synced'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
updated
:
synced
?
1
:
0
,
})
},
cityEnabled
(
city_id
,
campaign_id
,
enabled
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.enabled'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
enabled
:
enabled
?
1
:
0
,
})
},
cityDelete
(
id
)
{
if
(
confirm
(
'Are you sure you want to delete this city?'
))
{
this
.
$inertia
.
delete
(
this
.
route
(
'token.city.destroy'
,
[
this
.
token
.
id
,
id
]))
...
...
routes/web.php
View file @
309600c
...
...
@@ -193,6 +193,8 @@ Route::group(['middleware' => 'auth'], function () {
->
name
(
'token.city.campaign.updated'
);
Route
::
post
(
'token/city/campaign/synced/{token}/{dictionary}/{campaign_id}'
,
[
TokensController
::
class
,
'syncedCityCampaign'
])
->
name
(
'token.city.campaign.synced'
);
Route
::
post
(
'token/city/campaign/enabled/{token}/{dictionary}/{campaign_id}'
,
[
TokensController
::
class
,
'enabledCityCampaign'
])
->
name
(
'token.city.campaign.enabled'
);
Route
::
delete
(
'token/city/{token}/{dictionary}'
,
[
TokensController
::
class
,
'destroyCity'
])
->
name
(
'token.city.destroy'
);
...
...
tests/Unit/AddCampaignsTest.php
View file @
309600c
...
...
@@ -74,7 +74,7 @@ class AddCampaignsTest extends TestCase
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
count
());
$this
->
params
=
[
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsForNotExternal
,
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaigns
Enabled
ForNotExternal
,
'variables'
=>
Variable
::
all
(),
];
...
...
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