* переписал функции прототипов в сервисы

* оптимизация доставки контента до клиента
* переписал запросы выборок
* убрал из подсчета переведенных
* добавил сохранение метрикам для вывода в дашборд
This commit is contained in:
brusnitsyn
2026-02-04 17:05:13 +09:00
parent 9ee33bc517
commit eab78a0291
16 changed files with 1644 additions and 737 deletions

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Services;
use Carbon\Carbon;
use Illuminate\Support\Collection;
readonly class DateRange
{
public function __construct(
public Carbon $startDate,
public Carbon $endDate,
public string $startDateRaw,
public string $endDateRaw,
public bool $isOneDay
) {}
/**
* Получить начало диапазона в Carbon
*/
public function start(): Carbon
{
return $this->startDate;
}
/**
* Получить конец диапазона в Carbon
*/
public function end(): Carbon
{
return $this->endDate;
}
/**
* Получить начало диапазона в SQL формате
*/
public function startSql(): string
{
return $this->startDate->format('Y-m-d H:i:s');
}
/**
* Получить конец диапазона в SQL формате
*/
public function endSql(): string
{
return $this->endDate->format('Y-m-d H:i:s');
}
/**
* Получить начало диапазона как timestamp
*/
public function startTimestamp(): int
{
return $this->startDate->getTimestampMs();
}
/**
* Получить конец диапазона как timestamp
*/
public function endTimestamp(): int
{
return $this->endDate->getTimestampMs();
}
/**
* Проверить, является ли дата сегодняшней
*/
public function isEndDateToday(): bool
{
return $this->endDate->isToday();
}
/**
* Получить диапазон дней
*/
public function getDaysRange(): Collection
{
$days = collect();
$current = $this->startDate->copy();
while ($current->lte($this->endDate)) {
$days->push($current->copy());
$current->addDay();
}
return $days;
}
}