trafficmonitor/app/Services/TrafficService.php
2025-11-05 18:58:37 +09:00

58 lines
2.0 KiB
PHP

<?php
namespace App\Services;
use App\Entities\TrafficEntity;
use App\Forms\TrafficForm;
use App\Models\TrafficModel;
use DateTimeImmutable;
use DateTimeZone;
class TrafficService extends CommonService
{
public function __construct(
TrafficModel $model,
private TrafficForm $formService,
) {
parent::__construct($model);
$this->formServiceInstance = $this->formService;
// FormService에 Model 메타데이터를 설정
$this->formServiceInstance->setAttributes([
'pk_field' => $this->model->getPKField(),
'title_field' => $this->model->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
]);
$this->addClassPath('Service');
}
public function getFormService(): TrafficForm
{
if ($this->formServiceInstance === null) {
throw new \RuntimeException('FormService는 ' . static::class . '에서 초기화되어야 합니다.');
}
return $this->formServiceInstance;
}
//필수함수
// public function getNewServiceEntities(int $interval, string $status = ServiceEntity::DEFAULT_STATUS): array
// {
// return $this->getEntities(sprintf("start_at >= NOW()-INTERVAL {$interval} DAY AND status = '%s'", $status));
// }
// //서비스별 총 금액
// public function getTotalAmounts($where = []): array
// {
// $rows = $this->model->groupBy('clientinfo_uid')->select("clientinfo_uid,SUM(amount) AS amount")
// ->where($where)
// ->get()->getResult();
// $amounts = [];
// foreach ($rows as $row) {
// $amounts[$row->clientinfo_uid] = $row->amount;
// }
// return $amounts;
// }
// public function registerServiceAndGetId(array $context): array
// {
// $this->model->create($context);
// return $context;
// }
}