Commit 4878202b by Vladislav
2 parents 2c3b3cef ffa2f3e0
......@@ -129,7 +129,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
INNER JOIN ad_groups ag on k.ad_group_id = ag.id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
LEFT JOIN goal_keywords gk on k.id = gk.keyword_id AND gk.goal_ad_group_id=gag.id
WHERE gk.keyword_id is null
WHERE gk.keyword_id is null AND k.deleted_at is null
");
//грузим объявления которых по какой то причне нет в целевых.
......
......@@ -6,6 +6,7 @@ use App\Models\Tokens;
use App\Service\API\API;
use App\Service\Requests\APIRequest;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class KeywordsDelete extends Command
{
......@@ -47,16 +48,27 @@ class KeywordsDelete extends Command
->where('type', '!=', Tokens::MAIN)
->get();
foreach ($tokens as $token) {
foreach (Tokens::where('type', '!=', Tokens::MAIN)->get() as $token) {
$sql = "SELECT gk.external_id
FROM goal_keywords gk
INNER JOIN keywords k ON gk.keyword_id=k.id
INNER JOIN dictionary_campaigns c ON c.id=gk.dictionary_campaign_id
INNER JOIN dictionaries d ON d.id=c.dictionary_id
WHERE k.deleted_at is not null AND d.token_id=" . $token->id;
$result = DB::select($sql);
$ids = [];
foreach ($result as $item){
$ids[] = $item->external_id;
}
$factory = APIRequest::getInstance(API::YANDEX);
$factory->setToken($token);
$factory->getRequest('Keywords', 'delete')
->call([
'ids' => $token->dictionaryCampaignsForExternalWithTrashed->pluck('goalKeywordsDelete')
->collapse()
->pluck('external_id')
->toArray(),
'ids' => $ids
]);
}
......
......@@ -31,6 +31,7 @@ class TokensController extends Controller
'login' => $token->login,
'type' => $token->type,
'api' => $token->api,
'limit' => $token->limit,
];
}),
]);
......
......@@ -111,21 +111,21 @@ class Keyword extends Model
{
parent::boot();
static::deleted(function (Keyword $keyword) {
if (!$keyword->isForceDeleting()) {
$keyword->goalKeywords->each(function (GoalKeyword $goalKeyword) {
GoalKeywordDelete::updateOrCreateByMain($goalKeyword);
$goalKeyword->delete();
});
}
});
// static::deleted(function (Keyword $keyword) {
//
// if (!$keyword->isForceDeleting()) {
//
// $keyword->goalKeywords->each(function (GoalKeyword $goalKeyword) {
//
// GoalKeywordDelete::updateOrCreateByMain($goalKeyword);
//
// $goalKeyword->delete();
//
// });
//
// }
//
// });
}
public function goalKeywords()
......
......@@ -105,7 +105,7 @@ class Limits implements \App\Service\Contract\Limits {
function countObjectsLimitReserve(\App\Service\Contract\APIRequest $request, \App\Models\Limits $limit): int
{
$cost = $this->limitCosts->getCostObject($request);
return floor(($limit->spent - $this->limitCosts->getCostCall($request)) / $cost);
return $cost > 0 ? floor(($limit->spent - $this->limitCosts->getCostCall($request)) / $cost) : self::NAN;
}
/**
......
......@@ -61,7 +61,7 @@ class DeleteKeywords extends DirectRequest
$external_id = (string)$delete_result['Id'];
GoalKeywordDelete::where('external_id', $external_id)->delete();
GoalKeyword::where('external_id', $external_id)->delete();
}
} catch (\Exception $e) {
......
......@@ -120,6 +120,7 @@ class GetKeywords extends DirectRequest
'state' => $keyword['State'],
'status' => $keyword['Status'],
'serving_status' => $keyword['ServingStatus'],
'updated_at' => DB::raw('now()'),
'deleted_at' => null//не забыть убрать признак удаления, если вдруг опять пришла удаленная ранее фраза
];
......@@ -141,7 +142,12 @@ class GetKeywords extends DirectRequest
}
foreach (array_chunk($insertData, 1000) as $data) {
$items = [];
foreach ($data as $item){
$items[] = $item['external_id'];
}
Keyword::insertOrIgnore($data);
Keyword::whereIn('external_id', $items)->update(['updated_at' => DB::raw('now()')]);
}
......@@ -194,13 +200,16 @@ class GetKeywords extends DirectRequest
//это означает что этой фразы не было в результатах и в БД она по этой причине не обновилась
//надо такие пометить на удаление
//при удалении для всех таких надо будет удалить фразы из целевых и потом удалить их сами
$sql = "UPDATE keywords k
INNER JOIN ad_groups ag ON k.ad_group_id=ag.id
SET k.deleted_at = now(),
ag.keywords_loaded_at=now()
WHERE k.updated_at>ag.keywords_loaded_at
SET k.deleted_at = now()
WHERE k.updated_at<=ag.keywords_loaded_at
AND k.deleted_at is null
AND ag.id in (" . implode(", ", $ag_groups) . ")";
AND ag.external_id in (" . implode(", ", $ag_groups) . ")";
DB::update($sql);
$sql = "UPDATE ad_groups SET keywords_loaded_at=now() WHERE external_id in (" . implode(", ", $ag_groups) . ")";
DB::update($sql);
}
} catch (\Exception $e) {
......
......@@ -21,6 +21,7 @@
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Login</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>
</tr>
<tr v-for="token in tokens.data" :key="token.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
......@@ -36,6 +37,11 @@
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
{{ token.limit }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
{{ types[token.type] }}
</inertia-link>
</td>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!