Commit d573b582 by Vladislav

#20794 Сделать чтобы в целевых РК оставалась одна карточка (исправление удаление…

… AudienceTarget при создании, если не найдена группа)
1 parent 29956596
...@@ -75,6 +75,8 @@ class KeywordsAdd extends Command ...@@ -75,6 +75,8 @@ class KeywordsAdd extends Command
]) ])
->get(); ->get();
if ($goalKeywords->count()) {
foreach (array_chunk($goalKeywords->pluck('id')->toArray(), 1000) as $items) { foreach (array_chunk($goalKeywords->pluck('id')->toArray(), 1000) as $items) {
GoalKeyword::whereIn('id', $items) GoalKeyword::whereIn('id', $items)
->update([ ->update([
...@@ -87,6 +89,9 @@ class KeywordsAdd extends Command ...@@ -87,6 +89,9 @@ class KeywordsAdd extends Command
->call([ ->call([
'goalKeywords' => $goalKeywords, 'goalKeywords' => $goalKeywords,
]); ]);
}
} }
return 0; return 0;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Models\Pivots; namespace App\Models\Pivots;
use App\Models\AudienceTarget; use App\Models\AudienceTarget;
use App\Models\YandexError;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
...@@ -145,4 +146,9 @@ class GoalAudienceTarget extends Pivot ...@@ -145,4 +146,9 @@ class GoalAudienceTarget extends Pivot
return $this->belongsTo(DictionaryCampaign::class, 'dictionary_campaign_id'); return $this->belongsTo(DictionaryCampaign::class, 'dictionary_campaign_id');
} }
public function errors()
{
return $this->morphMany(YandexError::class, 'cause');
}
} }
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace App\Service\Requests\Direct; namespace App\Service\Requests\Direct;
use App\Jobs\ProcessCallLimitedAPI; use App\Jobs\ProcessCallLimitedAPI;
use App\Models\AudienceTarget;
use App\Models\Pivots\GoalAudienceTarget; use App\Models\Pivots\GoalAudienceTarget;
use App\Service\Contract\APIRequest; use App\Service\Contract\APIRequest;
use App\Service\Requests\DirectRequest; use App\Service\Requests\DirectRequest;
...@@ -16,7 +15,7 @@ class AddAudienceTargets extends DirectRequest ...@@ -16,7 +15,7 @@ class AddAudienceTargets extends DirectRequest
protected $max_count = 30; protected $max_count = 30;
protected $timestamp; protected $timestamp;
/* @var Collection|AudienceTarget[] */ /* @var Collection|GoalAudienceTarget[] */
protected $goalAudienceTargets; protected $goalAudienceTargets;
public function call($params = null) public function call($params = null)
...@@ -56,10 +55,35 @@ class AddAudienceTargets extends DirectRequest ...@@ -56,10 +55,35 @@ class AddAudienceTargets extends DirectRequest
$goalAudienceTarget = $this->goalAudienceTargets->get($key); $goalAudienceTarget = $this->goalAudienceTargets->get($key);
$data = $this->getParams()['AudienceTargets'][$key];
if (!isset($add_result['Id'])) { if (!isset($add_result['Id'])) {
if (isset($add_result['Errors'][0]['Message']) && $add_result['Errors'][0]['Message'] === 'Object not found') {
GoalAudienceTarget::where('id', $goalAudienceTarget->getKey())
->forceDelete();
continue;
} elseif (isset($add_result['Errors']) && count($add_result['Errors'])) {
$goalAudienceTarget->errors()->create([
'token_id' => $this->getToken()->getKey(),
'service' => $this->getService(),
'method' => $this->getMethod(),
'params' => $data,
'errors' => $add_result['Errors'],
]);
GoalAudienceTarget::where('id', $goalAudienceTarget->getKey())
->update([
'reserve_create_at' => null,
]);
continue;
}
Log::debug("AddAudienceTarget, empty Id, token_id {$this->getToken()->getKey()}"); Log::debug("AddAudienceTarget, empty Id, token_id {$this->getToken()->getKey()}");
Log::debug($add_result); Log::debug($add_result);
Log::debug($this->getParams()['AudienceTargets'][$key]); Log::debug($data);
GoalAudienceTarget::where('id', $goalAudienceTarget->getKey()) GoalAudienceTarget::where('id', $goalAudienceTarget->getKey())
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!