Начальный коммит: рабочая версия с исправленной авторизацией

This commit is contained in:
root
2026-01-11 19:15:02 +00:00
commit 2d98209ce1
206 changed files with 20957 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Services;
use App\Models\Component;
class BuildValidator
{
/**
* Проверяет базовую совместимость компонентов в сборке.
*
* @param array $componentIds Массив ID компонентов
* @return array ['valid' => bool, 'errors' => array, 'warnings' => array]
*/
public function validateCompatibility(array $componentIds)
{
$components = Component::whereIn('id', $componentIds)->get();
if ($components->count() < 2) {
return [
'valid' => true,
'errors' => [],
'warnings' => []
];
}
$errors = [];
$warnings = [];
// Определяем типы компонентов по component_type_id (адаптируйте под вашу логику!)
$cpu = $components->firstWhere('component_type_id', 1); // 1 = CPU
$motherboard = $components->firstWhere('component_type_id', 3); // 3 = Motherboard
$ram = $components->firstWhere('component_type_id', 4); // 4 = RAM
$psu = $components->firstWhere('component_type_id', 5); // 5 = PSU
// 1. Проверка сокета (CPU ↔ Motherboard)
if ($cpu && $motherboard) {
$cpuSocket = $cpu->specifications['socket'] ?? null;
$mbSocket = $motherboard->specifications['socket'] ?? null;
if (!$cpuSocket || !$mbSocket) {
$warnings[] = "Не указан сокет для процессора или материнской платы.";
} elseif ($cpuSocket !== $mbSocket) {
$errors[] = "Сокет процессора '{$cpuSocket}' не совместим со сокетом материнской платы '{$mbSocket}'.";
}
}
// 2. Проверка типа ОЗУ (RAM ↔ Motherboard)
if ($ram && $motherboard) {
$ramType = $ram->specifications['type'] ?? null;
$mbRamType = $motherboard->specifications['memory_type'] ?? $motherboard->specifications['type'] ?? null;
if (!$ramType || !$mbRamType) {
$warnings[] = "Не указан тип памяти для ОЗУ или материнской платы.";
} elseif ($ramType !== $mbRamType) {
$errors[] = "Тип ОЗУ '{$ramType}' не совместим с типом памяти материнской платы '{$mbRamType}'.";
}
}
// 3. Проверка мощности БП (PSU ≥ сумма TDP)
if ($psu) {
$totalTdp = 0;
foreach ($components as $component) {
// Берём TDP из specifications, или 0 если нет
$tdp = $component->specifications['tdp'] ?? 0;
$totalTdp += (int) $tdp;
}
$psuWattage = $psu->specifications['wattage'] ?? 0;
if ($psuWattage < $totalTdp) {
$errors[] = "Мощность БП ({$psuWattage} Вт) < суммарного TDP ({$totalTdp} Вт). Рекомендуется ≥ {$totalTdp} Вт.";
}
}
return [
'valid' => empty($errors),
'errors' => $errors,
'warnings' => $warnings
];
}
}