dbms_primeidc/extdbms/lib/Services/ServiceService.php
2025-04-23 14:09:36 +09:00

105 lines
4.0 KiB
PHP

<?php
namespace lib\Services;
use lib\Entities\ClientEntity;
use lib\Entities\ServiceEntity as Entity;
use lib\Entities\ServiceEntity;
use lib\Models\AddDbModel;
use lib\Models\ClientModel;
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 getEntitiesForNonPayment(int $curPage, int $perPage, array $exclude_clients): array
{
$table = $this->getModel()->getTable();
$clientTable = ClientModel::TABLE;
$addDbTable = AddDbModel::TABLE;
$this->getModel()->select("{$clientTable}.Client_Name,{$table}.service_code,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,addDB_case,addDB_nonpayment,addDB_payment,addDB_accountStatus,addDB_ip,addDB_payment_date");
$this->getModel()->join($clientTable, "{$table}.client_code = {$clientTable}.Client_Code");
$this->getModel()->join($addDbTable, "{$table}.service_code = {$addDbTable}.service_code");
$this->getModel()->whereNotIn("{$addDbTable}.client_code", $exclude_clients);
$this->getModel()->whereNotIn("{$addDbTable}.addDB_accountStatus", ["complete"]);
$this->getModel()->orderBy("service_payment_date", "DESC");
//Query문 Rest여부 -> 같은조건에 Count 받고, 결과값을 받고 싶을때는 continue()
$this->getModel()->setContinue(true);
$total = $this->getCount();
//limit, offset 설정
$this->getModel()->limit($perPage);
$this->getModel()->offset(($curPage - 1) * $perPage);
return [$total, $this->getEntities()];
}
//지역(치바,도쿄등)에 따른 DASHBOARD용 서비스 카운트
private function getDistrictCountForDashboard(string $where, string $type, array $switchcodes): int
{
$switchcode_begin = $switchcodes['begin'];
$switchcode_end = $switchcodes['end'];
$this->getModel()->where($where);
$this->getModel()->where(["service_line" => $type, "service_status" => 'o']);
$this->getModel()->where("service_sw BETWEEN '{$switchcode_begin}' AND '$switchcode_end'");
$count = $this->getModel()->count();
// echo "<BR>" . $this->getModel()->getLastQuery();
return $count;
}
final public function getTotalCountForDashboard(array $siteinfo): array
{
$temps = array();
foreach ($siteinfo['totalcount_customers'] as $customer => $where) {
$temps[$customer] = [];
foreach ($siteinfo['totalcount_types'] as $type) {
foreach (DBMS_SERVICE_SWITCHCODE as $district => $switchcodes) {
$temps[$customer][$type][$district] = $this->getDistrictCountForDashboard($where, $type, $switchcodes);
}
} //foreach
// echo var_dump($temps);
} //foreach
return $temps;
}
//도메인쿠폰 사용용
public function useCouponByService(ServiceEntity $service, int $coupon): bool
{
if ($coupon < 0) {
throw new \Exception("쿠폰수량이 잘못되었습니다. 쿠폰수량 : $coupon");
}
$this->getModel()->where("service_code", $service->getServiceCode());
$this->getModel()->update(["coupon=(coupon-{$coupon})" => null, "coupon_use=(coupon_use+{$coupon})" => null]);
return true;
}
//도메인쿠폰 Reset
public function resetCouponByClient(ClientEntity $client, int $coupon): bool
{
if ($coupon < 0) {
throw new \Exception("쿠폰수량이 잘못되었습니다. 쿠폰수량 : $coupon");
}
$this->getModel()->where("client_code", $client->getClientCode());
$this->getModel()->where("server_code", $client->getTitle() . "_일회성");
$this->getModel()->update(["coupon" => $coupon, "coupon_use" => 0]);
return true;
} //setCoupon
}