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 77167224
authored
Jul 14, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19500 Синхронизация модификаторов
1 parent
e2d55379
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
183 additions
and
18 deletions
app/Console/Commands/BidModifiersAdd.php
app/Console/Commands/BidModifiersDelete.php
app/Console/Kernel.php
app/Models/BidModifier.php
app/Models/Pivots/DictionaryCampaign.php
app/Service/Requests/Direct/DeleteBidModifiers.php
app/Service/Requests/Direct/GetBidModifiers.php
app/Console/Commands/BidModifiersAdd.php
View file @
7716722
...
@@ -43,7 +43,7 @@ class BidModifiersAdd extends Command
...
@@ -43,7 +43,7 @@ class BidModifiersAdd extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalSynchronized.goalBidModifiers.bidModifier'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalSynchronized.goalBidModifiers
ForNotExternal
.bidModifier'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -79,6 +79,10 @@ class BidModifiersAdd extends Command
...
@@ -79,6 +79,10 @@ class BidModifiersAdd extends Command
])
])
->
get
();
->
get
();
if
(
!
$goalBidModifiers
->
count
())
{
continue
;
}
foreach
(
array_chunk
(
$goalBidModifiers
->
pluck
(
'ids'
)
->
map
(
function
(
$ids
)
{
foreach
(
array_chunk
(
$goalBidModifiers
->
pluck
(
'ids'
)
->
map
(
function
(
$ids
)
{
return
json_decode
(
$ids
);
return
json_decode
(
$ids
);
})
->
collapse
()
->
toArray
(),
1000
)
as
$items
)
{
})
->
collapse
()
->
toArray
(),
1000
)
as
$items
)
{
...
...
app/Console/Commands/BidModifiersDelete.php
0 → 100644
View file @
7716722
<?php
namespace
App\Console\Commands
;
use
App\Models\Tokens
;
use
App\Service\Requests\Direct\DeleteBidModifiers
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\DB
;
class
BidModifiersDelete
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'bidmodifiers:delete'
;
/**
* 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
()
{
foreach
(
Tokens
::
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
()
as
$token
)
{
$ids
=
DB
::
table
(
'goal_bid_modifiers'
)
->
join
(
'bid_modifiers'
,
'goal_bid_modifiers.bid_modifier_id'
,
'='
,
'bid_modifiers.id'
)
->
join
(
'dictionary_campaigns'
,
'goal_bid_modifiers.dictionary_campaign_id'
,
'='
,
'dictionary_campaigns.id'
)
->
join
(
'dictionaries'
,
'dictionary_campaigns.dictionary_id'
,
'='
,
'dictionaries.id'
)
->
whereNotNull
(
'bid_modifiers.deleted_at'
)
->
where
(
'dictionaries.token_id'
,
$token
->
id
)
->
pluck
(
'goal_bid_modifiers.external_id'
);
if
(
!
$ids
->
count
())
{
continue
;
}
$request
=
new
DeleteBidModifiers
();
$request
->
setToken
(
$token
)
->
call
([
'ids'
=>
$ids
->
toArray
(),
]);
}
return
0
;
}
}
app/Console/Kernel.php
View file @
7716722
...
@@ -11,6 +11,7 @@ use App\Console\Commands\AdvertisementsAdd;
...
@@ -11,6 +11,7 @@ use App\Console\Commands\AdvertisementsAdd;
use
App\Console\Commands\AdvertisementsLoadUpdated
;
use
App\Console\Commands\AdvertisementsLoadUpdated
;
use
App\Console\Commands\AdvertisementsUpdate
;
use
App\Console\Commands\AdvertisementsUpdate
;
use
App\Console\Commands\BidModifiersAdd
;
use
App\Console\Commands\BidModifiersAdd
;
use
App\Console\Commands\BidModifiersDelete
;
use
App\Console\Commands\BidModifiersUpdate
;
use
App\Console\Commands\BidModifiersUpdate
;
use
App\Console\Commands\CampaignsAdd
;
use
App\Console\Commands\CampaignsAdd
;
use
App\Console\Commands\CampaignsCheckChange
;
use
App\Console\Commands\CampaignsCheckChange
;
...
@@ -95,6 +96,7 @@ class Kernel extends ConsoleKernel
...
@@ -95,6 +96,7 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
AdGroupsAdd
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
AdGroupsAdd
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
AdGroupsUpdate
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
AdGroupsUpdate
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
BidModifiersDelete
::
class
)
->
hourlyAt
(
30
);
$schedule
->
command
(
BidModifiersAdd
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
BidModifiersAdd
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
BidModifiersUpdate
::
class
)
->
hourlyAt
(
35
);
$schedule
->
command
(
BidModifiersUpdate
::
class
)
->
hourlyAt
(
35
);
...
...
app/Models/BidModifier.php
View file @
7716722
...
@@ -40,6 +40,9 @@ class BidModifier extends Model
...
@@ -40,6 +40,9 @@ class BidModifier extends Model
'retargeting_adjustment'
,
'retargeting_adjustment'
,
'updated_self'
,
'updated_self'
,
'updated_at'
,
'deleted_at'
,
];
];
protected
$casts
=
[
protected
$casts
=
[
...
@@ -64,6 +67,19 @@ class BidModifier extends Model
...
@@ -64,6 +67,19 @@ class BidModifier extends Model
]);
]);
}
}
public
function
getBidModifierValueAttribute
()
{
if
(
$this
->
mobile_adjustment
)
{
return
$this
->
mobile_adjustment
[
'BidModifier'
];
}
elseif
(
$this
->
desktop_adjustment
)
{
return
$this
->
desktop_adjustment
[
'BidModifier'
];
}
elseif
(
$this
->
demographics_adjustment
)
{
return
$this
->
demographics_adjustment
[
'BidModifier'
];
}
elseif
(
$this
->
retargeting_adjustment
)
{
return
$this
->
retargeting_adjustment
[
'BidModifier'
];
}
}
/**
/**
* @param Builder $query
* @param Builder $query
* @return Builder
* @return Builder
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
7716722
...
@@ -508,7 +508,7 @@ class DictionaryCampaign extends Pivot
...
@@ -508,7 +508,7 @@ class DictionaryCampaign extends Pivot
public
function
goalBidModifiersForNotExternal
()
public
function
goalBidModifiersForNotExternal
()
{
{
return
$this
->
goal
Advertisement
s
()
->
forNotExternal
();
return
$this
->
goal
BidModifier
s
()
->
forNotExternal
();
}
}
public
function
goalVCards
()
public
function
goalVCards
()
...
...
app/Service/Requests/Direct/DeleteBidModifiers.php
0 → 100644
View file @
7716722
<?php
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalBidModifier
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
class
DeleteBidModifiers
extends
DirectRequest
{
protected
$max_count
=
10000
;
protected
$timestamp
;
public
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
public
function
getObjectsCount
()
{
return
count
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
]);
}
public
function
slice
(
$maxObjects
)
:
?
APIRequest
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'Ids'
]);
}
public
function
handle
(
$response
)
{
try
{
if
(
!
isset
(
$response
[
'result'
][
'DeleteResults'
]))
{
return
;
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
Log
::
debug
(
"DeleteBidModifier, empty Id"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
]);
continue
;
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
GoalBidModifier
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
throw
$e
;
}
}
private
function
requestPrepare
(
$params
)
{
$this
->
setService
(
'BidModifiers'
);
$this
->
setMethod
(
'delete'
);
$params
=
[
'SelectionCriteria'
=>
[
'Ids'
=>
$params
[
'ids'
],
],
];
$this
->
setParams
(
$params
);
}
}
app/Service/Requests/Direct/GetBidModifiers.php
View file @
7716722
...
@@ -128,13 +128,18 @@ class GetBidModifiers extends DirectRequest
...
@@ -128,13 +128,18 @@ class GetBidModifiers extends DirectRequest
'retargeting_adjustment'
=>
$bid_modifier
[
'RetargetingAdjustment'
]
??
null
,
'retargeting_adjustment'
=>
$bid_modifier
[
'RetargetingAdjustment'
]
??
null
,
'updated_self'
=>
null
,
'updated_self'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
'deleted_at'
=>
null
,
];
];
$bidModifierOld
=
BidModifier
::
firstWhere
(
'external_id'
,
$external_id
);
$bidModifier
=
BidModifier
::
updateOrCreate
([
$bidModifier
=
BidModifier
::
updateOrCreate
([
'external_id'
=>
$external_id
'external_id'
=>
$external_id
],
$data
);
],
$data
);
if
(
!
$bidModifier
->
wasRecentlyCreated
&&
$bidModifier
->
wasChanged
(
$bidModifier
::
getPropertiesWatch
()
->
toArray
())
)
{
if
(
$bidModifierOld
&&
$bidModifier
->
bidModifierValue
!==
$bidModifierOld
->
bidModifierValue
)
{
$bidModifier
->
goalBidModifiers
()
->
has
(
'dictionaryCampaign'
)
->
forExternal
()
->
update
([
$bidModifier
->
goalBidModifiers
()
->
has
(
'dictionaryCampaign'
)
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
'updated_need'
=>
Carbon
::
now
(),
]);
]);
...
@@ -146,8 +151,8 @@ class GetBidModifiers extends DirectRequest
...
@@ -146,8 +151,8 @@ class GetBidModifiers extends DirectRequest
}
}
if
(
!
empty
(
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds
'
]))
{
if
(
!
isset
(
$response
[
'result'
][
'LimitedBy
'
]))
{
if
(
!
isset
(
$response
[
'result'
][
'LimitedBy
'
]))
{
if
(
!
empty
(
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds
'
]))
{
$ag_group_external_ids
=
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds'
];
$ag_group_external_ids
=
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds'
];
...
@@ -162,23 +167,23 @@ class GetBidModifiers extends DirectRequest
...
@@ -162,23 +167,23 @@ class GetBidModifiers extends DirectRequest
AdGroup
::
whereIn
(
'external_id'
,
$ag_group_external_ids
)
->
update
([
AdGroup
::
whereIn
(
'external_id'
,
$ag_group_external_ids
)
->
update
([
'bid_modifiers_loaded_at'
=>
Carbon
::
now
()
'bid_modifiers_loaded_at'
=>
Carbon
::
now
()
]);
]);
}
}
elseif
(
!
empty
(
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
]))
{
}
elseif
(
!
empty
(
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
]))
{
$campaign_external_ids
=
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
];
$campaign_external_ids
=
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
];
$sql
=
"UPDATE bid_modifiers bm
$sql
=
"UPDATE bid_modifiers bm
INNER JOIN campaigns ca ON bm.campaign_id = ca.id
INNER JOIN campaigns ca ON bm.campaign_id = ca.id
SET bm.deleted_at = now()
SET bm.deleted_at = now()
WHERE bm.updated_at <= ca.bid_modifiers_loaded_at
WHERE bm.updated_at <= ca.bid_modifiers_loaded_at
AND bm.deleted_at is null
AND bm.deleted_at is null
AND ca.external_id in ("
.
implode
(
", "
,
$campaign_external_ids
)
.
")"
;
AND ca.external_id in ("
.
implode
(
", "
,
$campaign_external_ids
)
.
")"
;
DB
::
update
(
$sql
);
DB
::
update
(
$sql
);
Campaigns
::
whereIn
(
'external_id'
,
$campaign_external_ids
)
->
update
([
Campaigns
::
whereIn
(
'external_id'
,
$campaign_external_ids
)
->
update
([
'bid_modifiers_loaded_at'
=>
Carbon
::
now
()
'bid_modifiers_loaded_at'
=>
Carbon
::
now
()
]);
]);
}
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
...
...
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