64a76a21c3
ProjectResource.source_change_message = ProjectRuleMessages.sourceChanged (тот же текст, что in-app уведомление 6.2). Диалоги подтверждения (дроуэр + окно Редактировать) тянут его из API с fallback на локальный текст. Бэкенд — единственный источник строк правил, экран и колокольчик не расходятся. Проверено глазами (epic6-unified-rule-text-confirm.png). Тесты: ProjectResource 5/5, дроуэр 27/27, EditProjectDialog 7/7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
3.6 KiB
PHP
72 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Project;
|
|
use App\Services\Project\ProjectRuleMessages;
|
|
use App\Services\Project\SupplierSnapshotGuard;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/** @mixin Project */
|
|
class ProjectResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
// Состояние блокировки источника для UI (read-only). hasLinks — из eager-loaded
|
|
// supplier_projects_count (анти-N+1); fallback на exists() если count не загружен.
|
|
$hasLinks = $this->supplier_projects_count !== null
|
|
? (int) $this->supplier_projects_count > 0
|
|
: $this->supplierProjects()->exists();
|
|
$sourceLock = (new SupplierSnapshotGuard)->lockState(
|
|
hasLinks: $hasLinks,
|
|
isActive: (bool) $this->is_active,
|
|
pausedAt: $this->paused_at,
|
|
);
|
|
|
|
// Эпик 6.3: единый текст правила смены источника (из ProjectRuleMessages) —
|
|
// диалог подтверждения на экране тянет его отсюда, не дублирует строку в JS.
|
|
$sourceChangeMessage = $sourceLock['locked'] && $sourceLock['unlock_at'] !== null
|
|
? (new ProjectRuleMessages)->sourceChanged($sourceLock['unlock_at'])
|
|
: null;
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'signal_type' => $this->signal_type,
|
|
'signal_identifier' => $this->signal_identifier,
|
|
'sms_senders' => $this->sms_senders,
|
|
'sms_keyword' => $this->sms_keyword,
|
|
'daily_limit_target' => $this->daily_limit_target,
|
|
'effective_daily_limit_today' => $this->effective_daily_limit_today,
|
|
'delivered_today' => $this->delivered_today,
|
|
'delivered_in_month' => $this->delivered_in_month,
|
|
'is_active' => $this->is_active,
|
|
'region_mask' => $this->region_mask,
|
|
'region_mode' => $this->region_mode,
|
|
'regions' => $this->regions,
|
|
'delivery_days_mask' => $this->delivery_days_mask,
|
|
'sync_status' => $this->aggregateSyncStatus(),
|
|
'last_synced_at' => $this->aggregateLastSyncedAt(),
|
|
// H (балансовый блок): проект приостановлен из-за нехватки баланса (read-only для UI).
|
|
'balance_blocked' => $this->preflight_blocked_at !== null,
|
|
'supplier_links' => $this->when(
|
|
$request->routeIs('projects.show'),
|
|
fn () => $this->getSupplierLinks(),
|
|
),
|
|
// Task 2.11 (Spec §4.2.5): dynamic attribute, не БД-поле. Установлен
|
|
// ProjectService::update() для slepok-sensitive правок. UI показывает
|
|
// «изменения вступят в силу с DD.MM HH:MM МСК».
|
|
'applies_from' => $this->applies_from?->toIso8601String(),
|
|
// Блокировка смены источника (спека 2026-06-22-project-source-edit-lock-ux).
|
|
'source_locked' => $sourceLock['locked'],
|
|
'source_unlock_at' => $sourceLock['unlock_at']?->toIso8601String(),
|
|
'source_unlock_projected' => $sourceLock['projected'],
|
|
// Эпик 6.3: единый текст правила (бэкенд — источник истины для строк).
|
|
'source_change_message' => $sourceChangeMessage,
|
|
];
|
|
}
|
|
}
|