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 4ed87cea
authored
Aug 05, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Доработал удаление фраз
1 parent
744d5464
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
6 deletions
app/Console/Commands/AdvertisementsAdd.php
app/Jobs/ProcessCallLimitedAPI.php
app/Service/Limits.php
app/Service/Requests/Direct/DeleteKeywords.php
app/Service/Requests/Direct/GetBidModifiers.php
database/migrations/2021_07_12_130456_add_retargetinglists_external_id_column.php
tests/Unit/ProcessCallSliceTest.php
app/Console/Commands/AdvertisementsAdd.php
View file @
4ed87ce
...
...
@@ -56,7 +56,7 @@ class AdvertisementsAdd extends Command
->
leftJoin
(
'ad_images'
,
'advertisements.ad_image_hash'
,
'='
,
'ad_images.hash'
)
->
leftJoin
(
'goal_ad_images'
,
function
(
$join
)
use
(
$token
)
{
$join
->
on
(
'goal_ad_images.ad_image_id'
,
'='
,
'ad_images.id'
);
$join
->
on
(
'goal_ad_images.token_id'
,
'='
,
$token
->
id
);
$join
->
on
(
'goal_ad_images.token_id'
,
'='
,
DB
::
raw
(
$token
->
id
)
);
})
->
whereNotExists
(
function
(
Builder
$query
)
{
$query
->
select
(
DB
::
raw
(
1
))
...
...
app/Jobs/ProcessCallLimitedAPI.php
View file @
4ed87ce
...
...
@@ -43,13 +43,15 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
$objects
=
$limits
->
countObjectsLimit
(
$this
->
api
);
if
(
!
$objects
)
{
//нет свободных баллов, замораживаем до следующего часа
Log
::
debug
(
'Нет баллов? '
.
$objects
);
Log
::
debug
(
'Нет баллов? '
.
$objects
.
' '
.
$this
->
api
->
getService
()
.
' '
.
$this
->
api
->
getMethod
()
);
$this
->
reRunHour
();
return
;
}
try
{
//резервируем на это количетсво
$limit
=
$limits
->
getSpent
(
$objects
,
$this
->
api
);
Log
::
debug
(
'Резервируем баллы '
.
$limit
.
' на объекты '
.
$objects
.
' '
.
$this
->
api
->
getService
()
.
' '
.
$this
->
api
->
getMethod
());
$limitId
=
$limits
->
doRezerv
(
$this
->
api
,
$objects
);
}
catch
(
\Exception
$e
){
...
...
app/Service/Limits.php
View file @
4ed87ce
...
...
@@ -64,6 +64,8 @@ class Limits implements \App\Service\Contract\Limits {
*/
function
countObjectsLimit
(
\App\Service\Contract\APIRequest
$request
)
:
int
{
if
(
$this
->
current
()
==
0
)
return
0
;
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
$maxCount
=
$request
->
getMaxCount
();
...
...
@@ -122,7 +124,7 @@ class Limits implements \App\Service\Contract\Limits {
$limit
=
$this
->
getSpent
(
$objects
,
$request
);
if
(
$this
->
token
->
limits
->
count
()
>
0
&&
$this
->
token
->
limit
<
$limit
)
{
throw
new
\Exception
(
'Недостаточно баллов
'
);
throw
new
\Exception
(
'Недостаточно баллов
'
.
' '
.
$request
->
getService
()
.
' '
.
$request
->
getMethod
()
);
}
DB
::
beginTransaction
();
...
...
app/Service/Requests/Direct/DeleteKeywords.php
View file @
4ed87ce
...
...
@@ -51,6 +51,12 @@ class DeleteKeywords extends DirectRequest
Log
::
debug
(
"DeleteKeywords, empty Id"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
]);
if
(
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
){
//объекта по какой то причине нет
if
(
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
]){
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
}
continue
;
}
...
...
@@ -75,6 +81,7 @@ class DeleteKeywords extends DirectRequest
'Ids'
=>
$params
[
'ids'
],
],
];
Log
::
debug
(
$params
);
$this
->
setParams
(
$params
);
}
...
...
app/Service/Requests/Direct/GetBidModifiers.php
View file @
4ed87ce
...
...
@@ -59,7 +59,6 @@ class GetBidModifiers extends DirectRequest
if
(
!
isset
(
$response
[
'result'
][
'BidModifiers'
]))
{
return
;
}
Log
::
debug
(
print_r
(
$response
[
'result'
],
true
));
$campaigns_external_ids
=
[];
$ad_groups_external_ids
=
[];
...
...
database/migrations/2021_07_12_130456_add_retargetinglists_external_id_column.php
View file @
4ed87ce
...
...
@@ -14,7 +14,7 @@ class AddRetargetinglistsExternalIdColumn extends Migration
public
function
up
()
{
Schema
::
table
(
'retargetinglists'
,
function
(
Blueprint
$table
)
{
$table
->
bigInteger
(
'external_id'
);
$table
->
bigInteger
(
'external_id'
)
->
nullable
()
;
});
}
...
...
tests/Unit/ProcessCallSliceTest.php
View file @
4ed87ce
...
...
@@ -13,6 +13,7 @@ use App\Models\Variable;
use
App\Service\Contract\API
;
use
App\Service\Limits
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\Direct\DeleteKeywords
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
...
...
@@ -130,8 +131,37 @@ class ProcessCallSliceTest extends TestCase
}
public
function
test
Handle
Api
()
public
function
test
SliceDeleteKeyword
Api
()
{
$rezerv
=
new
\App\Models\Limits
();
$rezerv
->
token
=
$this
->
token
->
id
;
$rezerv
->
service
=
'Keywords'
;
$rezerv
->
method
=
'delete'
;
$rezerv
->
spent
=
'100'
;
$rezerv
->
day
=
'100'
;
$rezerv
->
current
=
'6757'
;
$rezerv
->
reserved
=
0
;
$rezerv
->
save
();
Queue
::
fake
();
$this
->
token
->
limit
=
6657
;
$request
=
new
DeleteKeywords
();
$request
->
setToken
(
$this
->
token
)
->
call
([
'ids'
=>
range
(
1
,
10005
)
]);
$limits
=
Limits
::
getInstance
(
$request
->
getToken
());
$maxObjects
=
$limits
->
countObjectsLimit
(
$request
);
$this
->
assertEquals
(
$maxObjects
,
$this
->
token
->
limit
-
10
);
$limit
=
$limits
->
getSpent
(
$maxObjects
,
$request
);
$this
->
assertEquals
(
$maxObjects
,
$limit
-
10
);
$requestR
=
$request
->
slice
(
$maxObjects
);
$this
->
assertEquals
(
$this
->
token
->
limit
-
10
,
$request
->
getObjectsCount
());
$this
->
assertEquals
(
10005
-
$maxObjects
,
$requestR
->
getObjectsCount
());
}
}
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