dbms_primeidc/extdbms/lib/Services/ServiceService.php
2025-04-03 17:48:09 +09:00

84 lines
2.7 KiB
PHP

<?php
namespace lib\Services;
use lib\Entities\ServiceEntity as Entity;
use lib\Models\ServiceModel as Model;
class ServiceService extends CommonService
{
public function __construct()
{
parent::__construct();
}
final public function getClassName(): string
{
return "Service";
}
final public function getClassPath(): string
{
return $this->getClassName();
}
public function getModelClass(): string
{
return Model::class;
}
public function getEntityClass(): string
{
return Entity::class;
}
public function getEntityByCode(string $key): Entity|null|false
{
$this->getModel()->where('service_code', $key);
return $this->getEntity();
}
public function getNewServerCount(int $day, array $excepts): int|string
{
$this->getModel()->where("service_open_date > DATE_ADD(now(), INTERVAL -{$day} DAY)");
$this->getModel()->where("service_status", 'o');
$this->getModel()->whereNotIn("service_line", $excepts);
$count = $this->getModel()->countAllResults();
// echo __FUNCTION__ . ":" . $this->getModel()->getLastQuery();
return $count;
}
public function getUnPaymentCount(array $excepts): int|string
{
$this->getModel()->where("service_payment_date > now()");
$this->getModel()->where("service_status", 'o');
$this->getModel()->whereNotIn("service_line", $excepts);
$count = $this->getModel()->countAllResults();
// echo __FUNCTION__ . ":" . $this->getModel()->getLastQuery();
return $count;
}
private function getTotalCountByDistriction(string $where, string $type, string $switch_code1, string $switch_code2): int
{
$this->getModel()->where($where);
$this->getModel()->where(["service_line" => $type, "service_status" => 'o']);
$this->getModel()->where("service_sw BETWEEN '{$switch_code1}' AND '{$switch_code2}'");
$count = $this->getModel()->countAllResults();
// echo "<BR>" . $this->getModel()->getLastQuery();
return $count;
}
final public function getTotalCount(array $siteinfo): array
{
$temps = array();
foreach ($siteinfo['totalcount_customers'] as $customer => $where) {
$temps[$customer] = [];
foreach ($siteinfo['totalcount_types'] as $type) {
$temps[$customer][$type]['Chiba'] = $this->getTotalCountByDistriction($where, $type, 'C00%', 'C64%');
$temps[$customer][$type]['Tokyo'] = $this->getTotalCountByDistriction($where, $type, 'C80%', 'C99%');
} //foreach
// echo var_dump($temps);
} //foreach
return $temps;
}
public function getNews(int $limit): array
{
$this->getModel()->orderBy($this->getModel()->getPKField(), 'DESC');
$this->getModel()->limit($limit);
return $this->getEntities();
}
}