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 4e1c013a
authored
Jun 23, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19497 Получение кеша объявлений для шаблона
1 parent
d208756f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
194 additions
and
107 deletions
app/Console/Commands/AdvertisementsAdd.php
app/Console/Commands/AdvertisementsUpdate.php
app/Console/Commands/KeywordsUpdate.php
app/Service/Requests/Direct/AddAds.php
app/Service/Requests/Direct/AddKeywords.php
app/Service/Requests/Direct/UpdateAds.php
app/Service/Requests/Direct/UpdateKeywords.php
app/Console/Commands/AdvertisementsAdd.php
View file @
4e1c013
...
...
@@ -7,6 +7,8 @@ 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
;
use
Illuminate\Support\Facades\DB
;
class
AdvertisementsAdd
extends
Command
{
...
...
@@ -48,19 +50,46 @@ class AdvertisementsAdd extends Command
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
'dictionaryCampaignsEnabledForExternalSynchronized
.goalAdvertisementsForNotExternal'
=>
function
(
HasMany
$query
)
{
return
$query
->
has
(
'advertisement'
);
'dictionaryCampaignsEnabledForExternalSynchronized
'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
has
(
'
goalAdvertisementsForNotExternal.
advertisement'
);
},
'dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNotExternal.advertisement'
,
]);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$goalAds
=
DB
::
table
(
'goal_advertisements'
)
->
join
(
'advertisements'
,
'goal_advertisements.advertisement_id'
,
'='
,
'advertisements.id'
)
->
whereNull
(
'advertisements.deleted_at'
)
->
whereNull
(
'goal_advertisements.external_id'
)
->
whereNotNull
(
'goal_advertisements.goal_ad_group_external_id'
)
->
whereNotNull
(
'goal_advertisements.dictionary_campaign_external_id'
)
->
whereIn
(
'goal_advertisements.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_advertisements.id as id'
,
'goal_advertisements.dictionary_campaign_id as dictionary_campaign_id'
,
'goal_advertisements.goal_ad_group_external_id as goal_ad_group_external_id'
,
'advertisements.title as title'
,
'advertisements.text as text'
,
'advertisements.mobile as mobile'
,
'advertisements.title2 as title2'
,
'advertisements.href as href'
,
'advertisements.display_url_path as display_url_path'
,
'advertisements.v_card_id as v_card_id'
,
'advertisements.ad_image_hash as ad_image_hash'
,
'advertisements.site_link_set_id as site_link_set_id'
,
'advertisements.ad_extensions as ad_extensions'
,
'advertisements.video_extension as video_extension'
,
'advertisements.price_extension as price_extension'
,
'advertisements.turbo_page_id as turbo_page_id'
,
'advertisements.business_id as business_id'
,
'advertisements.prefer_v_card_over_business as prefer_v_card_over_business'
,
])
->
get
();
$factory
->
getRequest
(
'Ads'
,
'add'
)
->
call
([
'goalAds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalAdvertisementsForNotExternal'
)
->
collapse
(),
'goalAds'
=>
$goalAds
,
]);
}
...
...
app/Console/Commands/AdvertisementsUpdate.php
View file @
4e1c013
...
...
@@ -7,6 +7,8 @@ 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
;
use
Illuminate\Support\Facades\DB
;
class
AdvertisementsUpdate
extends
Command
{
...
...
@@ -48,19 +50,45 @@ class AdvertisementsUpdate extends Command
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
'dictionaryCampaignsEnabledForExternalSynchronized
.goalAdvertisementsForNeedUpdated'
=>
function
(
HasMany
$query
)
{
return
$query
->
has
(
'advertisement'
);
'dictionaryCampaignsEnabledForExternalSynchronized
'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
has
(
'
goalAdvertisementsForNeedUpdated.
advertisement'
);
},
'dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNeedUpdated.advertisement'
,
]);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Ads'
,
'add'
)
$goalAds
=
DB
::
table
(
'goal_advertisements'
)
->
join
(
'advertisements'
,
'goal_advertisements.advertisement_id'
,
'='
,
'advertisements.id'
)
->
whereNull
(
'advertisements.deleted_at'
)
->
whereNotNull
(
'goal_advertisements.updated_need'
)
->
whereNotNull
(
'goal_advertisements.goal_ad_group_external_id'
)
->
whereNotNull
(
'goal_advertisements.dictionary_campaign_external_id'
)
->
whereIn
(
'goal_advertisements.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_advertisements.id as id'
,
'goal_advertisements.dictionary_campaign_id as dictionary_campaign_id'
,
'advertisements.title as title'
,
'advertisements.text as text'
,
'advertisements.mobile as mobile'
,
'advertisements.title2 as title2'
,
'advertisements.href as href'
,
'advertisements.display_url_path as display_url_path'
,
'advertisements.v_card_id as v_card_id'
,
'advertisements.ad_image_hash as ad_image_hash'
,
'advertisements.site_link_set_id as site_link_set_id'
,
'advertisements.ad_extensions as ad_extensions'
,
'advertisements.video_extension as video_extension'
,
'advertisements.price_extension as price_extension'
,
'advertisements.turbo_page_id as turbo_page_id'
,
'advertisements.business_id as business_id'
,
'advertisements.prefer_v_card_over_business as prefer_v_card_over_business'
,
])
->
get
();
$factory
->
getRequest
(
'Ads'
,
'update'
)
->
call
([
'goalAds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalAdvertisementsForNeedUpdated'
)
->
collapse
(),
'goalAds'
=>
$goalAds
,
]);
}
...
...
app/Console/Commands/KeywordsUpdate.php
View file @
4e1c013
...
...
@@ -7,6 +7,8 @@ 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
;
use
Illuminate\Support\Facades\DB
;
class
KeywordsUpdate
extends
Command
{
...
...
@@ -48,19 +50,33 @@ class KeywordsUpdate extends Command
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
'dictionaryCampaignsEnabledForExternal
Updated.goalKeywordsForNeedUpdated'
=>
function
(
HasMany
$query
)
{
return
$query
->
has
(
'keyword'
);
'dictionaryCampaignsEnabledForExternal
Synchronized'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
has
(
'
goalKeywordsForNeedUpdated.
keyword'
);
},
'dictionaryCampaignsEnabledForExternalUpdated.goalKeywordsForNeedUpdated.keyword'
,
]);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$goalKeywords
=
DB
::
table
(
'goal_keywords'
)
->
join
(
'keywords'
,
'goal_keywords.keyword_id'
,
'='
,
'keywords.id'
)
->
whereNull
(
'keywords.deleted_at'
)
->
whereNotNull
(
'goal_advertisements.updated_need'
)
->
whereNotNull
(
'goal_keywords.goal_ad_group_external_id'
)
->
whereNotNull
(
'goal_keywords.dictionary_campaign_external_id'
)
->
whereIn
(
'goal_keywords.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_keywords.id as id'
,
'goal_keywords.dictionary_campaign_id as dictionary_campaign_id'
,
'keywords.keyword as keyword'
,
'keywords.user_param_1 as user_param_1'
,
'keywords.user_param_2 as user_param_2'
,
])
->
get
();
$factory
->
getRequest
(
'Keywords'
,
'update'
)
->
call
([
'goalKeywords'
=>
$token
->
dictionaryCampaignsEnabledForExternalUpdated
->
pluck
(
'goalKeywordsForNeedUpdated'
)
->
collapse
(),
'goalKeywords'
=>
$goalKeywords
,
]);
}
...
...
app/Service/Requests/Direct/AddAds.php
View file @
4e1c013
...
...
@@ -3,6 +3,7 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Advertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
...
...
@@ -17,7 +18,7 @@ class AddAds extends DirectRequest
protected
$max_count
=
1000
;
protected
$timestamp
;
/* @var Collection|GoalAdvertisement[] */
/* @var Collection|GoalAdvertisement[]
|Advertisement[]|\stdClass[]
*/
protected
$goalAds
;
public
function
call
(
$params
=
null
)
...
...
@@ -50,10 +51,10 @@ class AddAds extends DirectRequest
public
function
handle
(
$response
)
{
try
{
\Log
::
debug
(
$response
);
if
(
isset
(
$response
[
'result'
][
'Errors'
]))
{
Log
::
debug
(
$response
[
'Errors'
]);
Log
::
debug
(
$this
->
getParams
());
//
Log::debug($response['Errors']);
//
Log::debug($this->getParams());
}
if
(
!
isset
(
$response
[
'result'
][
'AddResults'
]))
{
...
...
@@ -70,9 +71,11 @@ class AddAds extends DirectRequest
$external_id
=
(
string
)
$add_result
[
'Id'
];
/* @var $goalAd GoalAdvertisement|Advertisement|\stdClass */
$goalAd
=
$this
->
goalAds
->
get
(
$key
);
$goalAd
->
update
([
GoalAdvertisement
::
whereId
(
$goalAd
->
id
)
->
update
([
'external_id'
=>
$external_id
,
'external_upload_at'
=>
Carbon
::
now
(),
]);
...
...
@@ -101,7 +104,9 @@ class AddAds extends DirectRequest
$lists
=
[];
$this
->
setParams
([
'Ads'
=>
$this
->
goalAds
->
map
(
function
(
GoalAdvertisement
$goalAdvertisement
)
use
(
$variables
,
&
$lists
)
{
'Ads'
=>
$this
->
goalAds
->
map
(
function
(
$goalAdvertisement
)
use
(
$variables
,
&
$lists
)
{
/* @var $goalAdvertisement GoalAdvertisement|Advertisement|\stdClass */
if
(
!
isset
(
$lists
[
$goalAdvertisement
->
dictionary_campaign_id
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalAdvertisement
->
dictionary_campaign_id
,
$variables
);
...
...
@@ -110,73 +115,73 @@ class AddAds extends DirectRequest
$list
=
$lists
[
$goalAdvertisement
->
dictionary_campaign_id
];
}
$advertisement
=
$goalAdvertisement
->
advertisement
;
$data
=
[
'AdGroupId'
=>
$goalAdvertisement
->
goal_ad_group_external_id
,
'TextAd'
=>
[
'Title'
=>
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
title
,
$list
)
->
get
(),
'Text'
=>
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
text
,
$list
)
->
get
(),
'Mobile'
=>
$
a
dvertisement
->
mobile
?
'YES'
:
'NO'
,
'Title'
=>
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
title
,
$list
)
->
get
(),
'Text'
=>
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
text
,
$list
)
->
get
(),
'Mobile'
=>
$
goalA
dvertisement
->
mobile
?
'YES'
:
'NO'
,
],
];
if
(
$
a
dvertisement
->
title2
)
{
$data
[
'TextAd'
][
'Title2'
]
=
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
title2
,
$list
)
->
get
();
if
(
$
goalA
dvertisement
->
title2
)
{
$data
[
'TextAd'
][
'Title2'
]
=
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
title2
,
$list
)
->
get
();
}
if
(
$
a
dvertisement
->
href
)
{
$data
[
'TextAd'
][
'Href'
]
=
$
a
dvertisement
->
href
;
if
(
$
goalA
dvertisement
->
href
)
{
$data
[
'TextAd'
][
'Href'
]
=
$
goalA
dvertisement
->
href
;
}
if
(
$
a
dvertisement
->
display_url_path
)
{
$data
[
'TextAd'
][
'DisplayUrlPath'
]
=
$
a
dvertisement
->
display_url_path
;
if
(
$
goalA
dvertisement
->
display_url_path
)
{
$data
[
'TextAd'
][
'DisplayUrlPath'
]
=
$
goalA
dvertisement
->
display_url_path
;
}
if
(
$
a
dvertisement
->
v_card_id
)
{
$data
[
'TextAd'
][
'VCardId'
]
=
$
a
dvertisement
->
v_card_id
;
if
(
$
goalA
dvertisement
->
v_card_id
)
{
$data
[
'TextAd'
][
'VCardId'
]
=
$
goalA
dvertisement
->
v_card_id
;
}
if
(
$
a
dvertisement
->
ad_image_hash
)
{
$data
[
'TextAd'
][
'AdImageHash'
]
=
$
a
dvertisement
->
ad_image_hash
;
if
(
$
goalA
dvertisement
->
ad_image_hash
)
{
$data
[
'TextAd'
][
'AdImageHash'
]
=
$
goalA
dvertisement
->
ad_image_hash
;
}
if
(
$
a
dvertisement
->
site_link_set_id
)
{
$data
[
'TextAd'
][
'SitelinkSetId'
]
=
$
a
dvertisement
->
site_link_set_id
;
if
(
$
goalA
dvertisement
->
site_link_set_id
)
{
$data
[
'TextAd'
][
'SitelinkSetId'
]
=
$
goalA
dvertisement
->
site_link_set_id
;
}
if
(
$advertisement
->
ad_extensions
)
{
$data
[
'TextAd'
][
'AdExtensionIds'
]
=
array_map
(
function
(
$ad_extension
)
{
return
$ad_extension
[
'AdExtensionId'
];
},
$advertisement
->
ad_extensions
);
if
(
$ad_extensions
=
@
json_decode
(
$goalAdvertisement
->
ad_extensions
,
true
))
{
$data
[
'TextAd'
][
'AdExtensionIds'
]
=
array_map
(
function
(
$ad_extension
)
{
return
$ad_extension
[
'AdExtensionId'
];
},
$ad_extensions
);
}
if
(
$
advertisement
->
video_extension
)
{
if
(
$
video_extension
=
@
json_decode
(
$goalAdvertisement
->
video_extension
,
true
)
)
{
$data
[
'TextAd'
][
'VideoExtension'
]
=
[
'CreativeId'
=>
$
advertisement
->
video_extension
[
'CreativeId'
],
'CreativeId'
=>
$video_extension
[
'CreativeId'
],
];
}
if
(
$
advertisement
->
price_extension
)
{
if
(
$
price_extension
=
@
json_decode
(
$goalAdvertisement
->
price_extension
,
true
)
)
{
$data
[
'TextAd'
][
'PriceExtension'
]
=
[
'Price'
=>
$
advertisement
->
price_extension
[
'Price'
],
'PriceQualifier'
=>
$
advertisement
->
price_extension
[
'PriceQualifier'
],
'PriceCurrency'
=>
$
advertisement
->
price_extension
[
'PriceCurrency'
],
'Price'
=>
$price_extension
[
'Price'
],
'PriceQualifier'
=>
$price_extension
[
'PriceQualifier'
],
'PriceCurrency'
=>
$price_extension
[
'PriceCurrency'
],
];
if
(
isset
(
$
advertisement
->
price_extension
[
'OldPrice'
])
&&
!
is_null
(
$advertisement
->
price_extension
[
'OldPrice'
]))
{
$data
[
'TextAd'
][
'PriceExtension'
][
'OldPrice'
]
=
$
advertisement
->
price_extension
[
'OldPrice'
];
if
(
isset
(
$
price_extension
[
'OldPrice'
])
&&
!
is_null
(
$
price_extension
[
'OldPrice'
]))
{
$data
[
'TextAd'
][
'PriceExtension'
][
'OldPrice'
]
=
$price_extension
[
'OldPrice'
];
}
}
if
(
$
a
dvertisement
->
turbo_page_id
)
{
$data
[
'TextAd'
][
'TurboPageId'
]
=
$
a
dvertisement
->
turbo_page_id
;
if
(
$
goalA
dvertisement
->
turbo_page_id
)
{
$data
[
'TextAd'
][
'TurboPageId'
]
=
$
goalA
dvertisement
->
turbo_page_id
;
}
if
(
$
a
dvertisement
->
business_id
)
{
$data
[
'TextAd'
][
'BusinessId'
]
=
$
a
dvertisement
->
business_id
;
if
(
$
goalA
dvertisement
->
business_id
)
{
$data
[
'TextAd'
][
'BusinessId'
]
=
$
goalA
dvertisement
->
business_id
;
}
if
(
$
a
dvertisement
->
prefer_v_card_over_business
)
{
$data
[
'TextAd'
][
'PreferVCardOverBusiness'
]
=
$
advertisement
->
prefer_v_card_over_business
?
'YES'
:
'NO'
;
if
(
$
goalA
dvertisement
->
prefer_v_card_over_business
)
{
$data
[
'TextAd'
][
'PreferVCardOverBusiness'
]
=
$
goalAdvertisement
->
prefer_v_card_over_business
?
'YES'
:
'NO'
;
}
return
$data
;
...
...
app/Service/Requests/Direct/AddKeywords.php
View file @
4e1c013
...
...
@@ -3,6 +3,7 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Keyword
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
...
...
@@ -17,7 +18,7 @@ class AddKeywords extends DirectRequest
protected
$max_count
=
1000
;
protected
$timestamp
;
/* @var Collection */
/* @var Collection
|GoalKeyword[]|Keyword[]|\stdClass[]
*/
protected
$goalKeywords
;
public
function
call
(
$params
=
null
)
...
...
@@ -72,15 +73,12 @@ class AddKeywords extends DirectRequest
$goalKeyword
=
$this
->
goalKeywords
[
$key
];
$goalKeyword
=
GoalKeyword
::
find
(
$goalKeyword
->
id
);
if
(
$goalKeyword
)
{
$goalKeyword
->
update
([
GoalKeyword
::
whereId
(
$goalKeyword
->
id
)
->
update
([
'external_id'
=>
$external_id
,
'external_upload_at'
=>
Carbon
::
now
(),
'reserve_create_at'
=>
null
,
]);
}
}
}
catch
(
\Exception
$e
)
{
...
...
@@ -116,6 +114,8 @@ class AddKeywords extends DirectRequest
$this
->
setParams
([
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
$goalKeyword
)
use
(
$variables
,
&
$lists
)
{
/* @var $goalKeyword GoalKeyword|Keyword|\stdClass */
if
(
!
isset
(
$lists
[
$goalKeyword
->
dictionary_campaign_id
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionary_campaign_id
,
$variables
);
$lists
[
$goalKeyword
->
dictionary_campaign_id
]
=
$list
;
...
...
app/Service/Requests/Direct/UpdateAds.php
View file @
4e1c013
...
...
@@ -3,6 +3,7 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Advertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
...
...
@@ -17,7 +18,7 @@ class UpdateAds extends DirectRequest
protected
$max_count
=
1000
;
protected
$timestamp
;
/* @var Collection|GoalAdvertisement[] */
/* @var Collection|GoalAdvertisement[]
|Advertisement[]|\stdClass[]
*/
protected
$goalAds
;
public
function
call
(
$params
=
null
)
...
...
@@ -100,7 +101,9 @@ class UpdateAds extends DirectRequest
$lists
=
[];
$this
->
setParams
([
'Ads'
=>
$this
->
goalAds
->
map
(
function
(
GoalAdvertisement
$goalAdvertisement
)
use
(
$variables
,
&
$lists
)
{
'Ads'
=>
$this
->
goalAds
->
map
(
function
(
$goalAdvertisement
)
use
(
$variables
,
&
$lists
)
{
/* @var $goalAdvertisement GoalAdvertisement|Advertisement|\stdClass */
if
(
!
isset
(
$lists
[
$goalAdvertisement
->
dictionary_campaign_id
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalAdvertisement
->
dictionary_campaign_id
,
$variables
);
...
...
@@ -109,81 +112,79 @@ class UpdateAds extends DirectRequest
$list
=
$lists
[
$goalAdvertisement
->
dictionary_campaign_id
];
}
$advertisement
=
$goalAdvertisement
->
advertisement
;
$data
=
[
'Id'
=>
$goalAdvertisement
->
external_id
,
'TextAd'
=>
[
'Title'
=>
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
title
,
$list
)
->
get
(),
'Text'
=>
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
text
,
$list
)
->
get
(),
'Mobile'
=>
$
a
dvertisement
->
mobile
?
'YES'
:
'NO'
,
'AgeLabel'
=>
$
a
dvertisement
->
age_label
,
'Title'
=>
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
title
,
$list
)
->
get
(),
'Text'
=>
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
text
,
$list
)
->
get
(),
'Mobile'
=>
$
goalA
dvertisement
->
mobile
?
'YES'
:
'NO'
,
'AgeLabel'
=>
$
goalA
dvertisement
->
age_label
,
],
];
if
(
$
a
dvertisement
->
title2
)
{
$data
[
'TextAd'
][
'Title2'
]
=
StrReplaceByVariables
::
getInstance
(
$
a
dvertisement
->
title2
,
$list
)
->
get
();
if
(
$
goalA
dvertisement
->
title2
)
{
$data
[
'TextAd'
][
'Title2'
]
=
StrReplaceByVariables
::
getInstance
(
$
goalA
dvertisement
->
title2
,
$list
)
->
get
();
}
if
(
$
a
dvertisement
->
href
)
{
$data
[
'TextAd'
][
'Href'
]
=
$
a
dvertisement
->
href
;
if
(
$
goalA
dvertisement
->
href
)
{
$data
[
'TextAd'
][
'Href'
]
=
$
goalA
dvertisement
->
href
;
}
if
(
$
a
dvertisement
->
display_url_path
)
{
$data
[
'TextAd'
][
'DisplayUrlPath'
]
=
$
a
dvertisement
->
display_url_path
;
if
(
$
goalA
dvertisement
->
display_url_path
)
{
$data
[
'TextAd'
][
'DisplayUrlPath'
]
=
$
goalA
dvertisement
->
display_url_path
;
}
if
(
$
a
dvertisement
->
v_card_id
)
{
$data
[
'TextAd'
][
'VCardId'
]
=
$
a
dvertisement
->
v_card_id
;
if
(
$
goalA
dvertisement
->
v_card_id
)
{
$data
[
'TextAd'
][
'VCardId'
]
=
$
goalA
dvertisement
->
v_card_id
;
}
if
(
$
a
dvertisement
->
ad_image_hash
)
{
$data
[
'TextAd'
][
'AdImageHash'
]
=
$
a
dvertisement
->
ad_image_hash
;
if
(
$
goalA
dvertisement
->
ad_image_hash
)
{
$data
[
'TextAd'
][
'AdImageHash'
]
=
$
goalA
dvertisement
->
ad_image_hash
;
}
if
(
$
a
dvertisement
->
site_link_set_id
)
{
$data
[
'TextAd'
][
'SitelinkSetId'
]
=
$
a
dvertisement
->
site_link_set_id
;
if
(
$
goalA
dvertisement
->
site_link_set_id
)
{
$data
[
'TextAd'
][
'SitelinkSetId'
]
=
$
goalA
dvertisement
->
site_link_set_id
;
}
if
(
$ad
vertisement
->
ad_extensions
)
{
if
(
$ad
_extensions
=
@
json_decode
(
$goalAdvertisement
->
ad_extensions
,
true
)
)
{
$data
[
'TextAd'
][
'CalloutSetting'
]
=
[
'AdExtensions'
=>
array_map
(
function
(
$ad_extension
)
{
return
[
'AdExtensionId'
=>
$ad_extension
[
'AdExtensionId'
],
'Operation'
=>
'SET'
,
];
},
$ad
vertisement
->
ad
_extensions
)
},
$ad_extensions
)
];
}
if
(
$
advertisement
->
video_extension
)
{
if
(
$
video_extension
=
@
json_decode
(
$goalAdvertisement
->
video_extension
,
true
)
)
{
$data
[
'TextAd'
][
'VideoExtension'
]
=
[
'CreativeId'
=>
$
advertisement
->
video_extension
[
'CreativeId'
],
'CreativeId'
=>
$video_extension
[
'CreativeId'
],
];
}
if
(
$
advertisement
->
price_extension
)
{
if
(
$
price_extension
=
@
json_decode
(
$goalAdvertisement
->
price_extension
,
true
)
)
{
$data
[
'TextAd'
][
'PriceExtension'
]
=
[
'Price'
=>
$
advertisement
->
price_extension
[
'Price'
],
'PriceQualifier'
=>
$
advertisement
->
price_extension
[
'PriceQualifier'
],
'PriceCurrency'
=>
$
advertisement
->
price_extension
[
'PriceCurrency'
],
'Price'
=>
$price_extension
[
'Price'
],
'PriceQualifier'
=>
$price_extension
[
'PriceQualifier'
],
'PriceCurrency'
=>
$price_extension
[
'PriceCurrency'
],
];
if
(
isset
(
$
advertisement
->
price_extension
[
'OldPrice'
])
&&
!
is_null
(
$advertisement
->
price_extension
[
'OldPrice'
]))
{
$data
[
'TextAd'
][
'PriceExtension'
][
'OldPrice'
]
=
$
advertisement
->
price_extension
[
'OldPrice'
];
if
(
isset
(
$
price_extension
[
'OldPrice'
])
&&
!
is_null
(
$
price_extension
[
'OldPrice'
]))
{
$data
[
'TextAd'
][
'PriceExtension'
][
'OldPrice'
]
=
$price_extension
[
'OldPrice'
];
}
}
if
(
$
a
dvertisement
->
turbo_page_id
)
{
$data
[
'TextAd'
][
'TurboPageId'
]
=
$
a
dvertisement
->
turbo_page_id
;
if
(
$
goalA
dvertisement
->
turbo_page_id
)
{
$data
[
'TextAd'
][
'TurboPageId'
]
=
$
goalA
dvertisement
->
turbo_page_id
;
}
if
(
$
a
dvertisement
->
business_id
)
{
$data
[
'TextAd'
][
'BusinessId'
]
=
$
a
dvertisement
->
business_id
;
if
(
$
goalA
dvertisement
->
business_id
)
{
$data
[
'TextAd'
][
'BusinessId'
]
=
$
goalA
dvertisement
->
business_id
;
}
if
(
$
a
dvertisement
->
prefer_v_card_over_business
)
{
$data
[
'TextAd'
][
'PreferVCardOverBusiness'
]
=
$
a
dvertisement
->
prefer_v_card_over_business
?
'YES'
:
'NO'
;
if
(
$
goalA
dvertisement
->
prefer_v_card_over_business
)
{
$data
[
'TextAd'
][
'PreferVCardOverBusiness'
]
=
$
goalA
dvertisement
->
prefer_v_card_over_business
?
'YES'
:
'NO'
;
}
return
$data
;
...
...
app/Service/Requests/Direct/UpdateKeywords.php
View file @
4e1c013
...
...
@@ -3,12 +3,13 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Keyword
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Illuminate\
Database\Eloquen
t\Collection
;
use
Illuminate\
Suppor
t\Collection
;
use
Illuminate\Support\Facades\Log
;
class
UpdateKeywords
extends
DirectRequest
...
...
@@ -16,7 +17,7 @@ class UpdateKeywords extends DirectRequest
protected
$max_count
=
1000
;
protected
$timestamp
;
/* @var Collection|GoalKeyword[] */
/* @var Collection|GoalKeyword[]
|Keyword[]|\stdClass[]
*/
protected
$goalKeywords
;
public
function
call
(
$params
=
null
)
...
...
@@ -85,24 +86,31 @@ class UpdateKeywords extends DirectRequest
$variables
=
Variable
::
all
();
$lists
=
[];
$this
->
setParams
([
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
use
(
$variable
s
)
{
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
$goalKeyword
)
use
(
$variables
,
&
$list
s
)
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionary_campaign_id
,
$variables
);
/* @var $goalKeyword GoalKeyword|Keyword|\stdClass */
$keyword
=
$goalKeyword
->
keyword
;
if
(
!
isset
(
$lists
[
$goalKeyword
->
dictionary_campaign_id
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionary_campaign_id
,
$variables
);
$lists
[
$goalKeyword
->
dictionary_campaign_id
]
=
$list
;
}
else
{
$list
=
$lists
[
$goalKeyword
->
dictionary_campaign_id
];
}
$data
=
[
'Id'
=>
$goalKeyword
->
external_id
,
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$
k
eyword
->
keyword
,
$list
)
->
get
(),
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$
goalK
eyword
->
keyword
,
$list
)
->
get
(),
];
if
(
$
k
eyword
->
user_param_1
)
{
$data
[
'UserParam1'
]
=
$
k
eyword
->
user_param_1
;
if
(
$
goalK
eyword
->
user_param_1
)
{
$data
[
'UserParam1'
]
=
$
goalK
eyword
->
user_param_1
;
}
if
(
$
k
eyword
->
user_param_2
)
{
$data
[
'UserParam2'
]
=
$
k
eyword
->
user_param_2
;
if
(
$
goalK
eyword
->
user_param_2
)
{
$data
[
'UserParam2'
]
=
$
goalK
eyword
->
user_param_2
;
}
return
$data
;
...
...
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