diff --git a/app/Config/Database.php b/app/Config/Database.php index 29f6f4a..705d3e6 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -25,29 +25,29 @@ class Database extends Config * @var array */ public array $default = [ - 'DSN' => '', - 'hostname' => 'localhost', - 'username' => '', - 'password' => '', - 'database' => '', - 'DBDriver' => 'MySQLi', - 'DBPrefix' => '', - 'pConnect' => false, - 'DBDebug' => true, - 'charset' => 'utf8mb4', - 'DBCollat' => 'utf8mb4_general_ci', - 'swapPre' => '', - 'encrypt' => false, - 'compress' => false, - 'strictOn' => false, - 'failover' => [], - 'port' => 3306, - 'numberNative' => false, - 'foundRows' => false, - 'dateFormat' => [ - 'date' => 'Y-m-d', + 'DSN' => '', + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'DBDriver' => 'MySQLi', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => true, + 'charset' => 'utf8mb4', + 'DBCollat' => 'utf8mb4_general_ci', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 3306, + 'numberNative' => true, + 'foundRows' => false, + 'dateFormat' => [ + 'date' => 'Y-m-d', 'datetime' => 'Y-m-d H:i:s', - 'time' => 'H:i:s', + 'time' => 'H:i:s', ], ]; @@ -163,29 +163,29 @@ class Database extends Config * @var array */ public array $tests = [ - 'DSN' => '', - 'hostname' => '127.0.0.1', - 'username' => '', - 'password' => '', - 'database' => ':memory:', - 'DBDriver' => 'SQLite3', - 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS - 'pConnect' => false, - 'DBDebug' => true, - 'charset' => 'utf8', - 'DBCollat' => '', - 'swapPre' => '', - 'encrypt' => false, - 'compress' => false, - 'strictOn' => false, - 'failover' => [], - 'port' => 3306, + 'DSN' => '', + 'hostname' => '127.0.0.1', + 'username' => '', + 'password' => '', + 'database' => ':memory:', + 'DBDriver' => 'SQLite3', + 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS + 'pConnect' => false, + 'DBDebug' => true, + 'charset' => 'utf8', + 'DBCollat' => '', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 3306, 'foreignKeys' => true, 'busyTimeout' => 1000, - 'dateFormat' => [ - 'date' => 'Y-m-d', + 'dateFormat' => [ + 'date' => 'Y-m-d', 'datetime' => 'Y-m-d H:i:s', - 'time' => 'H:i:s', + 'time' => 'H:i:s', ], ]; diff --git a/app/Entities/BoardEntity.php b/app/Entities/BoardEntity.php index 7446862..7057d77 100644 --- a/app/Entities/BoardEntity.php +++ b/app/Entities/BoardEntity.php @@ -21,14 +21,14 @@ class BoardEntity extends CommonEntity } final public function getUserUid(): int|null { - return $this->attributes['user_uid'] ?? null; + return $this->user_uid ?? null; } final public function getWorkerUid(): int|null { - return $this->attributes['worker_uid'] ?? null; + return $this->worker_uid ?? null; } final public function getCaregory(): string { - return $this->attributes['category'] ?? ""; + return $this->category ?? ""; } } diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php index 2b0edff..7f32162 100644 --- a/app/Entities/CommonEntity.php +++ b/app/Entities/CommonEntity.php @@ -7,13 +7,20 @@ use CodeIgniter\Entity\Entity; abstract class CommonEntity extends Entity { protected $datamap = []; - protected $dates = ['created_at', 'updated_at', 'deleted_at']; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; //사용법 : $client->created_at->format('Y-m-d') //비교방법 : if ($client->created_at < new \DateTime('2024-01-01')) { public function __construct(array|null $data = null) { parent::__construct($data); } + public function __get(string $key) + { + if (array_key_exists($key, $this->attributes)) { + return $this->attributes[$key]; + } + return parent::__get($key); + } final public function getPK(): int|string { $field = constant("static::PK"); @@ -30,18 +37,18 @@ abstract class CommonEntity extends Entity } final public function getStatus(): string { - return $this->attributes['status'] ?? ""; + return $this->status ?? ""; } final public function getUpdatedAt(): string { - return $this->attributes['updated_at'] ?? ""; + return $this->updated_at ?? ""; } final public function getCreatedAt(): string { - return $this->attributes['created_at'] ?? ""; + return $this->created_at ?? ""; } final public function getDeletedAt(): string { - return $this->attributes['deleted_at'] ?? ""; + return $this->deleted_at ?? ""; } } diff --git a/app/Entities/Customer/ClientEntity.php b/app/Entities/Customer/ClientEntity.php index 7d8d1d9..35ec97e 100644 --- a/app/Entities/Customer/ClientEntity.php +++ b/app/Entities/Customer/ClientEntity.php @@ -27,7 +27,7 @@ class ClientEntity extends CustomerEntity public function getUserUid(): int|null { - return $this->attributes['user_uid'] ?? null; + return $this->user_uid ?? null; } //기본기능 public function getCustomTitle(mixed $title = null): string @@ -36,27 +36,27 @@ class ClientEntity extends CustomerEntity } public function getName(): string { - return $this->attributes['name']; + return $this->name; } public function getSite(): string { - return $this->attributes['site']; + return $this->site; } public function getAccountBalance(): int { - return $this->attributes['account_balance'] ?? 0; + return $this->account_balance ?? 0; } public function getCouponBalance(): int { - return $this->attributes['coupon_balance'] ?? 0; + return $this->coupon_balance ?? 0; } public function getPointBalance(): int { - return $this->attributes['point_balance'] ?? 0; + return $this->point_balance ?? 0; } public function getHistory(): string|null { - return $this->attributes['history']; + return $this->history; } /* * 사용자의 역할을 배열 형태로 반환합니다. @@ -65,7 +65,7 @@ class ClientEntity extends CustomerEntity */ public function getRole(): array { - $role = $this->attributes['role'] ?? null; + $role = $this->role ?? null; // 1. 이미 배열인 경우 (방어적 코딩) if (is_array($role)) { return array_filter($role); @@ -113,6 +113,6 @@ class ClientEntity extends CustomerEntity $cleanedRoles = array_map(fn($item) => trim((string) ($item ?? ''), " \t\n\r\0\x0B\""), $roleArray); $roleArray = array_filter($cleanedRoles); // 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다. - $this->attributes['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray); + $this->role = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray); } } diff --git a/app/Entities/Customer/ServiceEntity.php b/app/Entities/Customer/ServiceEntity.php index f4483ff..e41e5c0 100644 --- a/app/Entities/Customer/ServiceEntity.php +++ b/app/Entities/Customer/ServiceEntity.php @@ -14,8 +14,8 @@ class ServiceEntity extends CustomerEntity 'site' => '', 'location' => '', 'rack' => 0, - 'coupon_balance' => 0, - 'line' => 0, + 'coupon_balance' => 0, + 'line' => 0, 'billing_at' => '', 'sale' => 0, 'amount' => 0, @@ -30,58 +30,58 @@ class ServiceEntity extends CustomerEntity } final public function getUserUid(): int|null { - return $this->attributes['user_uid'] ?? null; + return $this->user_uid ?? null; } - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid'] ?? null; + return $this->clientinfo_uid ?? null; } - final public function getServerInfoUid(): int|null + final public function getServerInfoUid(): int|null { - return $this->attributes['serverinfo_uid'] ?? null; + return $this->serverinfo_uid ?? null; } //기본기능용 final public function getCode(): string { - return $this->attributes['code'] ?? ''; + return $this->code ?? ''; } final public function getSite(): string { - return $this->attributes['site'] ?? ''; + return $this->site ?? ''; } final public function getLocation(): string { - return $this->attributes['location'] ?? ''; + return $this->location ?? ''; } final public function getBillingAt(): string { - return $this->attributes['billing_at'] ?? ''; + return $this->billing_at ?? ''; } //청구금액->기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 //상면비 final public function getRack(): int { - return $this->attributes['rack'] ?? 0; + return $this->rack ?? 0; } //회선비 final public function getLine(): int { - return $this->attributes['line'] ?? 0; + return $this->line ?? 0; } final public function getSale(): int { - return $this->attributes['sale'] ?? 0; + return $this->sale ?? 0; } final public function getAmount(): int { - return $this->attributes['amount'] ?? 0; + return $this->amount ?? 0; } final public function getStartAt(): string { - return $this->attributes['start_at'] ?? ''; + return $this->start_at ?? ''; } public function getHistory(): string { - return $this->attributes['history'] ?? ''; + return $this->history ?? ''; } } diff --git a/app/Entities/Customer/Wallet/AccountEntity.php b/app/Entities/Customer/Wallet/AccountEntity.php index 1dcdca6..086c7e8 100644 --- a/app/Entities/Customer/Wallet/AccountEntity.php +++ b/app/Entities/Customer/Wallet/AccountEntity.php @@ -6,16 +6,22 @@ use App\Models\Customer\Wallet\AccountModel; class AccountEntity extends WalletEntity { - const PK = AccountModel::PK; + const PK = AccountModel::PK; const TITLE = AccountModel::TITLE; + protected $casts = [ + 'clientinfo_uid' => 'integer', + 'user_uid' => '?integer', + ]; protected $attributes = [ + 'clientinfo_uid' => null, + 'user_uid' => null, 'title' => '', 'bank' => '', 'alias' => '', 'issue_at' => '', 'amount' => 0, 'balance' => 0, - 'status' => '', + 'status' => '', 'content' => '' ]; public function __construct(array|null $data = null) @@ -25,14 +31,14 @@ class AccountEntity extends WalletEntity //기본기능 public function getBank(): string { - return $this->attributes['bank'] ?? ''; + return $this->bank ?? ''; } public function getAlias(): string { - return $this->attributes['alias'] ?? ''; + return $this->alias ?? ''; } public function getIssueAt(): string { - return $this->attributes['issue_at'] ?? ''; + return $this->issue_at ?? ''; } } diff --git a/app/Entities/Customer/Wallet/CouponEntity.php b/app/Entities/Customer/Wallet/CouponEntity.php index c2a1b5a..db55119 100644 --- a/app/Entities/Customer/Wallet/CouponEntity.php +++ b/app/Entities/Customer/Wallet/CouponEntity.php @@ -7,13 +7,13 @@ use App\Models\Customer\Wallet\CouponModel; class CouponEntity extends WalletEntity { - const PK = CouponModel::PK; + const PK = CouponModel::PK; const TITLE = CouponModel::TITLE; protected $attributes = [ 'title' => '', 'amount' => 0, 'balance' => 0, - 'status' => '', + 'status' => '', 'content' => '' ]; public function __construct(array|null $data = null) diff --git a/app/Entities/Customer/Wallet/PointEntity.php b/app/Entities/Customer/Wallet/PointEntity.php index 27ba7ed..cdb3ce3 100644 --- a/app/Entities/Customer/Wallet/PointEntity.php +++ b/app/Entities/Customer/Wallet/PointEntity.php @@ -12,7 +12,7 @@ class PointEntity extends WalletEntity 'title' => '', 'amount' => 0, 'balance' => 0, - 'status' => '', + 'status' => '', 'content' => '' ]; public function __construct(array|null $data = null) diff --git a/app/Entities/Customer/Wallet/WalletEntity.php b/app/Entities/Customer/Wallet/WalletEntity.php index d95d08e..3a86dcc 100644 --- a/app/Entities/Customer/Wallet/WalletEntity.php +++ b/app/Entities/Customer/Wallet/WalletEntity.php @@ -13,23 +13,23 @@ abstract class WalletEntity extends CustomerEntity } final public function getUserUid(): int|null { - return $this->attributes['user_uid'] ?? null; + return $this->user_uid ?? null; } - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid'] ?? null; + return $this->clientinfo_uid ?? null; } //기본기능 final public function getAmount(): int { - return $this->attributes['amount'] ?? 0; + return $this->amount ?? 0; } final public function getBalance(): int { - return $this->attributes['balance'] ?? 0; + return $this->balance ?? 0; } final public function getContent(): string { - return $this->attributes['content'] ?? ''; + return $this->content ?? ''; } } diff --git a/app/Entities/Equipment/CHASSISEntity.php b/app/Entities/Equipment/CHASSISEntity.php index 8439082..c467a81 100644 --- a/app/Entities/Equipment/CHASSISEntity.php +++ b/app/Entities/Equipment/CHASSISEntity.php @@ -6,7 +6,7 @@ use App\Models\Equipment\CHASSISModel; class CHASSISEntity extends EquipmentEntity { - const PK = CHASSISModel::PK; + const PK = CHASSISModel::PK; const TITLE = CHASSISModel::TITLE; protected $attributes = [ 'title' => '', @@ -22,45 +22,45 @@ class CHASSISEntity extends EquipmentEntity { parent::__construct($data); } - public function getCPUInfoUid(): int|null + public function getCPUInfoUid(): int|null { - return $this->attributes['cpuinfo_uid'] ?? null; + return $this->cpuinfo_uid ?? null; } - public function getRAMInfoUid(): int|null + public function getRAMInfoUid(): int|null { - return $this->attributes['raminfo_uid'] ?? null; + return $this->raminfo_uid ?? null; } - public function getDISKInfoUid(): int|null + public function getDISKInfoUid(): int|null { - return $this->attributes['diskinfo_uid'] ?? null; + return $this->diskinfo_uid ?? null; } //기본기능 public function getPrice(): int { - return $this->attributes['price'] ?? 0; + return $this->price ?? 0; } public function getStock(): int { - return $this->attributes['stock'] ?? 0; + return $this->stock ?? 0; } public function getUsed(): int { - return $this->attributes['used'] ?? 0; + return $this->used ?? 0; } public function getAvailable(): int { return $this->getStock() - $this->getUsed(); } - public function getCPUCnt(): int + public function getCPUCnt(): int { - return $this->attributes['cpu_cnt'] ?? 0; + return $this->cpu_cnt ?? 0; } - public function getRAMCnt(): int + public function getRAMCnt(): int { - return $this->attributes['ram_cnt'] ?? 0; + return $this->ram_cnt ?? 0; } - public function getDISKCnt(): int + public function getDISKCnt(): int { - return $this->attributes['disk_cnt'] ?? 0; + return $this->disk_cnt ?? 0; } } diff --git a/app/Entities/Equipment/LineEntity.php b/app/Entities/Equipment/LineEntity.php index ed8d27b..c373429 100644 --- a/app/Entities/Equipment/LineEntity.php +++ b/app/Entities/Equipment/LineEntity.php @@ -24,26 +24,26 @@ class LineEntity extends EquipmentEntity const TITLE = LineModel::TITLE; public function getType(): string { - return $this->attributes['type'] ?? ''; + return $this->type ?? ''; } public function getProtocol(): string { - return $this->attributes['protocol'] ?? ''; + return $this->protocol ?? ''; } public function getBandwith(): string { - return $this->attributes['bandwith'] ?? ''; + return $this->bandwith ?? ''; } public function getStartAt(): string { - return $this->attributes['start_at'] ?? ''; + return $this->start_at ?? ''; } public function getEndAt(): string { - return $this->attributes['end_at'] ?? ''; + return $this->end_at ?? ''; } public function getContent(): string { - return $this->attributes['content'] ?? ''; + return $this->content ?? ''; } } diff --git a/app/Entities/Equipment/ServerEntity.php b/app/Entities/Equipment/ServerEntity.php index 1f8c9b0..8745bd9 100644 --- a/app/Entities/Equipment/ServerEntity.php +++ b/app/Entities/Equipment/ServerEntity.php @@ -8,7 +8,13 @@ class ServerEntity extends EquipmentEntity { const PK = ServerModel::PK; const TITLE = ServerModel::TITLE; + protected $attributes = [ + 'user_uid' => null, + 'clientinfo_uid' => null, + 'serviceinfo_uid' => null, + 'chassisinfo_uid' => null, + 'switchinfo_uid' => null, 'code' => '', 'title' => '', 'type' => '', @@ -26,19 +32,23 @@ class ServerEntity extends EquipmentEntity } final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid'] ?? null; + $val = $this->clientinfo_uid ?? null; + return ($val === '' || $val === null) ? null : (int) $val; } final public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid'] ?? null; + $val = $this->serviceinfo_uid ?? null; + return ($val === '' || $val === null) ? null : (int) $val; } final public function getChassisInfoUid(): int|null { - return $this->attributes['chassisinfo_uid'] ?? null; + $val = $this->chassisinfo_uid ?? null; + return ($val === '' || $val === null) ? null : (int) $val; } final public function getSwitchInfoUid(): int|null { - return $this->attributes['switchinfo_uid'] ?? null; + $val = $this->switchinfo_uid ?? null; + return ($val === '' || $val === null) ? null : (int) $val; } //기본기능용 public function getCustomTitle(mixed $title = null): string @@ -47,34 +57,34 @@ class ServerEntity extends EquipmentEntity } final public function getCode(): string { - return $this->attributes['code'] ?? ''; + return $this->code ?? null; } public function getType(): string { - return $this->attributes['type'] ?? ''; + return $this->type ?? null; } public function getIP(): string { - return $this->attributes['ip'] ?? ''; + return $this->ip ?? ''; } public function getViewer(): string { - return $this->attributes['viewer'] ?? ''; + return $this->viewer ?? ''; } public function getOS(): string { - return $this->attributes['os'] ?? ''; + return $this->os ?? ''; } public function getPrice(): int { - return $this->attributes['price'] ?? 0; + return $this->price ?? 0; } public function getManufacturAt(): string { - return $this->attributes['manufactur_at'] ?? ''; + return $this->manufactur_at ?? ''; } public function getFormatAt(): string { - return $this->attributes['format_at'] ?? ''; + return $this->format_at ?? ''; } } diff --git a/app/Entities/Equipment/ServerPartEntity.php b/app/Entities/Equipment/ServerPartEntity.php index b05fadb..bc17350 100644 --- a/app/Entities/Equipment/ServerPartEntity.php +++ b/app/Entities/Equipment/ServerPartEntity.php @@ -6,9 +6,21 @@ use App\Models\Equipment\ServerPartModel; class ServerPartEntity extends EquipmentEntity { - const PK = ServerPartModel::PK; + const PK = ServerPartModel::PK; const TITLE = ServerPartModel::TITLE; + + protected $casts = [ + 'clientinfo_uid' => '?integer', + 'part_uid' => '?integer', + 'serverinfo_uid' => 'integer', + 'serviceinfo_uid' => '?integer', + ]; + protected $attributes = [ + 'clientinfo_uid' => null, + 'part_uid' => null, + 'serverinfo_uid' => null, + 'serviceinfo_uid' => null, 'title' => '', 'type' => '', 'billing' => '', @@ -21,21 +33,21 @@ class ServerPartEntity extends EquipmentEntity { parent::__construct($data); } - public function getClientInfoUid(): int|null + public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid'] ?? null; + return $this->clientinfo_uid ?? null; } - public function getServiceInfoUid(): int|null + public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid'] ?? null; + return $this->serviceinfo_uid ?? null; } - public function getServerInfoUid(): int|null + public function getServerInfoUid(): int|null { - return $this->attributes['serverinfo_uid'] ?? null; + return $this->serverinfo_uid ?? null; } - public function getPartUid(): int|null + public function getPartUid(): int|null { - return $this->attributes['part_uid'] ?? null; + return $this->part_uid ?? null; } //기본기능용 public function getCustomTitle(): string @@ -48,26 +60,26 @@ class ServerPartEntity extends EquipmentEntity } public function getType(): string { - return $this->attributes['type'] ?? ""; + return $this->type ?? ""; } public function getBilling(): string { - return $this->attributes['billing'] ?? ""; + return $this->billing ?? ""; } public function getBillingAt(): string { - return $this->attributes['billing_at'] ?? ""; + return $this->billing_at ?? ""; } public function getCnt(): int { - return $this->attributes['cnt'] ?? 0; + return $this->cnt ?? 0; } public function getAmount(): int { - return $this->attributes['amount'] ?? 0; + return $this->amount ?? 0; } public function getExtra(): string { - return $this->attributes['extra'] ?? ''; + return $this->extra ?? ''; } } diff --git a/app/Entities/Part/CPUEntity.php b/app/Entities/Part/CPUEntity.php index a20b24d..ffc1867 100644 --- a/app/Entities/Part/CPUEntity.php +++ b/app/Entities/Part/CPUEntity.php @@ -6,7 +6,7 @@ use App\Models\Part\CPUModel; class CPUEntity extends PartType1Entity { - const PK = CPUModel::PK; + const PK = CPUModel::PK; const TITLE = CPUModel::TITLE; public function __construct(array|null $data = null) { diff --git a/app/Entities/Part/CSEntity.php b/app/Entities/Part/CSEntity.php index 08bf297..d2eb2a9 100644 --- a/app/Entities/Part/CSEntity.php +++ b/app/Entities/Part/CSEntity.php @@ -21,30 +21,30 @@ class CSEntity extends PartType2Entity parent::__construct($data); } //기본기능 - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid']; + return $this->clientinfo_uid; } - final public function getServiceInfoUid(): int|null + final public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid']; + return $this->serviceinfo_uid; } - final public function getServerInfoUid(): int|null + final public function getServerInfoUid(): int|null { - return $this->attributes['serverinfo_uid']; + return $this->serverinfo_uid; } public function getIP(): string { - return $this->attributes['ip'] ?? ''; + return $this->ip ?? ''; } //기본기능 public function getAccountID(): string { - return $this->attributes['accountid'] ?? ""; + return $this->accountid ?? ""; } public function getDomain(): string { - return $this->attributes['domain'] ?? ""; + return $this->domain ?? ""; } //abstract 선언처리용 } diff --git a/app/Entities/Part/DISKEntity.php b/app/Entities/Part/DISKEntity.php index 358782c..4b42f5e 100644 --- a/app/Entities/Part/DISKEntity.php +++ b/app/Entities/Part/DISKEntity.php @@ -6,7 +6,7 @@ use App\Models\Part\DISKModel; class DISKEntity extends PartType1Entity { - const PK = DISKModel::PK; + const PK = DISKModel::PK; const TITLE = DISKModel::TITLE; protected $attributes = [ 'title' => '', @@ -24,6 +24,6 @@ class DISKEntity extends PartType1Entity public function getFormat(): int { - return $this->attributes['format'] ?? 0; + return $this->format ?? 0; } } diff --git a/app/Entities/Part/IPEntity.php b/app/Entities/Part/IPEntity.php index 969a971..bce977b 100644 --- a/app/Entities/Part/IPEntity.php +++ b/app/Entities/Part/IPEntity.php @@ -21,33 +21,33 @@ class IPEntity extends PartType3Entity { parent::__construct($data); } - public function getLineInfoUID(): int|null + public function getLineInfoUID(): int|null { - return $this->attributes['lineinfo_uid'] ?? null; + return $this->lineinfo_uid ?? null; } - public function getOldClientInfoUID(): int|null + public function getOldClientInfoUID(): int|null { - return $this->attributes['old_clientinfo_uid'] ?? null; + return $this->old_clientinfo_uid ?? null; } - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid']; + return $this->clientinfo_uid; } - final public function getServiceInfoUid(): int|null + final public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid']; + return $this->serviceinfo_uid; } - final public function getServerInfoUid(): int|null + final public function getServerInfoUid(): int|null { - return $this->attributes['serverinfo_uid']; + return $this->serverinfo_uid; } //기본기능 public function getIP(): string { - return $this->attributes['ip'] ?? ""; + return $this->ip ?? ""; } public function getContent(): string { - return $this->attributes['content'] ?? ""; + return $this->content ?? ""; } } diff --git a/app/Entities/Part/PartEntity.php b/app/Entities/Part/PartEntity.php index 24ec3da..efec0ec 100644 --- a/app/Entities/Part/PartEntity.php +++ b/app/Entities/Part/PartEntity.php @@ -15,10 +15,10 @@ abstract class PartEntity extends CommonEntity //기본기능용 public function getCustomTitle(mixed $title = null): string { - return sprintf("%s %s원", $title ? $title : $this->getTitle(), number_format($this->getPrice())); + return sprintf("%s %s원", $title ? $title : $this->getTitle(), number_format($this->getPrice())); } final public function getPrice(): int { - return $this->attributes['price'] ?? 0; + return $this->price ?? 0; } } diff --git a/app/Entities/Part/PartType1Entity.php b/app/Entities/Part/PartType1Entity.php index 64331fa..32c5ac6 100644 --- a/app/Entities/Part/PartType1Entity.php +++ b/app/Entities/Part/PartType1Entity.php @@ -20,11 +20,11 @@ class PartType1Entity extends PartEntity //기본기능 final public function getStock(): int { - return $this->attributes['stock'] ?? 0; + return $this->stock ?? 0; } final public function getUsed(): int { - return $this->attributes['used'] ?? 0; + return $this->used ?? 0; } final public function getAvailable(): int { diff --git a/app/Entities/Part/RAMEntity.php b/app/Entities/Part/RAMEntity.php index 1090f71..643c4ef 100644 --- a/app/Entities/Part/RAMEntity.php +++ b/app/Entities/Part/RAMEntity.php @@ -6,7 +6,7 @@ use App\Models\Part\RAMModel; class RAMEntity extends PartType1Entity { - const PK = RAMModel::PK; + const PK = RAMModel::PK; const TITLE = RAMModel::TITLE; protected $attributes = [ 'title' => '', diff --git a/app/Entities/Part/SOFTWAREEntity.php b/app/Entities/Part/SOFTWAREEntity.php index f32ff4e..d2f432d 100644 --- a/app/Entities/Part/SOFTWAREEntity.php +++ b/app/Entities/Part/SOFTWAREEntity.php @@ -6,6 +6,6 @@ use App\Models\Part\SOFTWAREModel; class SOFTWAREEntity extends PartType1Entity { - const PK = SOFTWAREModel::PK; + const PK = SOFTWAREModel::PK; const TITLE = SOFTWAREModel::TITLE; } diff --git a/app/Entities/Part/SWITCHEntity.php b/app/Entities/Part/SWITCHEntity.php index 8c9aa11..f7a32ef 100644 --- a/app/Entities/Part/SWITCHEntity.php +++ b/app/Entities/Part/SWITCHEntity.php @@ -6,7 +6,7 @@ use App\Models\Part\SWITCHModel; class SWITCHEntity extends PartType3Entity { - const PK = SWITCHModel::PK; + const PK = SWITCHModel::PK; const TITLE = SWITCHModel::TITLE; protected $attributes = [ 'code' => 0, @@ -15,23 +15,22 @@ class SWITCHEntity extends PartType3Entity ]; public function __construct(array|null $data = null) { - $this->attributes['code'] = ''; parent::__construct($data); } - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid']; + return $this->clientinfo_uid ?? null; } - final public function getServiceInfoUid(): int|null + final public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid']; + return $this->serviceinfo_uid ?? null; } - final public function getServerInfoUid(): int|null + final public function getServerInfoUid(): int|null { - return $this->attributes['serverinfo_uid']; + return $this->serverinfo_uid ?? null; } public function getCode(): string { - return $this->attributes['code'] ?? ""; + return $this->code ?? ""; } } diff --git a/app/Entities/PaymentEntity.php b/app/Entities/PaymentEntity.php index dd06ee3..d7f1206 100644 --- a/app/Entities/PaymentEntity.php +++ b/app/Entities/PaymentEntity.php @@ -25,15 +25,15 @@ class PaymentEntity extends CommonEntity } final public function getUserUid(): int|null { - return $this->attributes['user_uid'] ?? null; + return $this->user_uid ?? null; } - final public function getClientInfoUid(): int|null + final public function getClientInfoUid(): int|null { - return $this->attributes['clientinfo_uid'] ?? null; + return $this->clientinfo_uid ?? null; } - final public function getServiceInfoUid(): int|null + final public function getServiceInfoUid(): int|null { - return $this->attributes['serviceinfo_uid'] ?? null; + return $this->serviceinfo_uid ?? null; } //기본기능 public function getCustomTitle(): string @@ -42,27 +42,27 @@ class PaymentEntity extends CommonEntity } public function getBilling(): string { - return $this->attributes['billing'] ?? ""; + return $this->billing ?? ""; } public function getAmount(): int { - return $this->attributes['amount'] ?? 0; + return $this->amount ?? 0; } public function getBillingAt(): string { - return $this->attributes['billing_at'] ?? ""; + return $this->billing_at ?? ""; } public function getBillingMonth(): int { - return $this->attributes['billing_month'] ?? 0; + return $this->billing_month ?? 0; } public function getPay(): string { - return $this->attributes['pay'] ?? ""; + return $this->pay ?? ""; } public function getContent(): string { - return $this->attributes['content'] ?? ""; + return $this->content ?? ""; } public function getCountDueAt(): string { @@ -72,10 +72,10 @@ class PaymentEntity extends CommonEntity $due = new DateTime($this->getBillingAt()); if ($due < $now) { $interval = $due->diff($now); - $result = "{$interval->days}일지남"; + $result = "{$interval->days}일지남"; } else if ($due > $now) { $interval = $now->diff($due); - $day = $interval->days + 1; + $day = $interval->days + 1; $result = "{$day}일전"; } else { $result = "당일"; diff --git a/app/Entities/UserEntity.php b/app/Entities/UserEntity.php index c3969a8..1db7d24 100644 --- a/app/Entities/UserEntity.php +++ b/app/Entities/UserEntity.php @@ -30,11 +30,11 @@ class UserEntity extends CommonEntity } public function getID(): string { - return (string) $this->attributes['id']; + return (string) $this->id; } public function getPassword(): string { - return $this->attributes['passwd']; + return $this->passwd; } /** * 사용자의 역할을 배열 형태로 반환합니다. @@ -43,7 +43,7 @@ class UserEntity extends CommonEntity */ public function getRole(): array { - $role = $this->attributes['role'] ?? null; + $role = $this->role ?? null; // 1. 이미 배열인 경우 (방어적 코딩) if (is_array($role)) { return array_filter($role); @@ -70,7 +70,7 @@ class UserEntity extends CommonEntity { // 입력된 비밀번호가 null이 아니고 비어있지 않을 때만 해시 처리 if (!empty($password)) { - $this->attributes['passwd'] = password_hash($password, PASSWORD_BCRYPT); + $this->passwd = password_hash($password, PASSWORD_BCRYPT); } } @@ -99,6 +99,6 @@ class UserEntity extends CommonEntity $cleanedRoles = array_map(fn($item) => trim((string) ($item ?? ''), " \t\n\r\0\x0B\""), $roleArray); $roleArray = array_filter($cleanedRoles); // 최종적으로 DB에 삽입될 단일 CSV 문자열로 변환하여 저장합니다. - $this->attributes['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray); + $this->role = implode(DEFAULTS["DELIMITER_ROLE"], $roleArray); } } diff --git a/app/Entities/UserSNSEntity.php b/app/Entities/UserSNSEntity.php index 96ecb48..01d4201 100644 --- a/app/Entities/UserSNSEntity.php +++ b/app/Entities/UserSNSEntity.php @@ -21,18 +21,18 @@ class UserSNSEntity extends CommonEntity //Common Function public function getID(): string { - return $this->attributes['id']; + return $this->id; } public function getSite(): string { - return $this->attributes['site']; + return $this->site; } public function getEmail(): string { - return $this->attributes['email']; + return $this->email; } public function getParent(): int|string { - return $this->attributes['user_uid']; + return $this->user_uid; } } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 0235b3f..1886f51 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -126,11 +126,14 @@ abstract class CommonService * 단일 엔티티를 조회합니다. */ abstract protected function getEntity_process(CommonEntity $entity): CommonEntity; - final public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity + final public function getEntity($where = null, ?string $message = null): ?CommonEntity { try { - $entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where); - if (!$entity) { + $entity = null; + if ($where !== null) { + $entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where); + } + if ($entity === null) { return null; } // 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사 @@ -234,8 +237,8 @@ abstract class CommonService { // INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록) $initialPK = $entity->getPK(); - $result = $this->model->save($entity); log_message('debug', __FUNCTION__ . ":" . var_export($entity, true)); + $result = $this->model->save($entity); log_message('debug', __FUNCTION__ . ":" . $this->model->getLastQuery()); // 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK) $entity->{$this->getPKField()} = $this->handle_save_result($result, $initialPK); diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 69f664d..20d627e 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -46,7 +46,28 @@ class ServerPartService extends EquipmentService { return $entity; } - private function getFormDatasForServerPart(array $formDatas): array + private function getBillingAtByServiceEntity(ServiceEntity $serviceEntity, string $billing): string + { + //청구방식에 따른 결제일 설정 + $billing_at = null; + if ($billing === PAYMENT['BILLING']['MONTH']) { + $billing_at = $serviceEntity->getBillingAt(); + } else if ($billing === PAYMENT['BILLING']['ONETIME']) { + $billing_at = date("Y-m-d"); + } else { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$billing}에 해당하는 청구방식을 찾을수 없습니다."); + } + return $billing_at; + } + private function setPartTitleByPartEntity(array $formDatas): string + { + $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']); + if (!$partEntity instanceof PartEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['part_uid']}에 해당하는 파트정보을 찾을수 없습니다."); + } + return $partEntity->getTitle(); + } + private function getFormDatasForServerPart(array $formDatas, ServerEntity $serverEntity): array { if (empty($formDatas['serverinfo_uid'])) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서버번호가 지정되지 않았습니다."); @@ -61,44 +82,33 @@ class ServerPartService extends EquipmentService if (empty($formDatas['part_uid'])) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 파트번호가 지정되지 않았습니다."); } - //서버정보 가져오기 - $serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']); - if (!$serverEntity instanceof ServerEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serverinfo_uid']}에 해당하는 서버정보을 찾을수 없습니다."); - } + //해당 파트정보의 Title을 파트정보의 Title로 설정 + $formDatas['title'] = $this->setPartTitleByPartEntity($formDatas); + //청구일 설정 //서비스정보 가져오기 $serviceEntity = null; if ($serverEntity->getServiceInfoUid()) { $serviceEntity = service('customer_serviceservice')->getEntity($serverEntity->getServiceInfoUid()); } - //각 파트정보 가져오기 - $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']); - if (!$serviceEntity instanceof ServiceEntity) { + $formDatas['billing_at'] = null; + if ($serviceEntity instanceof ServiceEntity) { + $formDatas['billing_at'] = $this->getBillingAtByServiceEntity($serviceEntity, $formDatas['billing']); } //해당 파트정보에 고객번호,서비스번호 설정 $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUid(); $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUid(); - //해당 파트정보의 Title을 서버파트정보의 Titlte 설정 - $formDatas['title'] = $partEntity->getTitle(); - //청구방식에 따른 결제일 설정 - $formDatas['billing_at'] = null; - if ($formDatas['billing'] === PAYMENT['BILLING']['MONTH']) { - if (!$serviceEntity instanceof ServiceEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 매월결제 상품은 서비스정보가 지정된 후 설정하실 수 있습니다."); - } - $formDatas['billing_at'] = $serviceEntity->getBillingAt(); - } elseif ($formDatas['billing'] === PAYMENT['BILLING']['ONETIME']) { - if (!$serviceEntity instanceof ServiceEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 매월결제 상품은 서비스정보가 지정된 후 설정하실 수 있습니다."); - } - $formDatas['billing_at'] = date("Y-m-d"); - } - return array($serverEntity, $serviceEntity, $partEntity, $formDatas); + return $formDatas; } protected function create_process(array $formDatas): CommonEntity { + //서버정보 가져오기 + $serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']); + if (!$serverEntity instanceof ServerEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serverinfo_uid']}에 해당하는 서버정보을 찾을수 없습니다."); + } + //생성을 위한 추가 FormDatas설정 + $formDatas = $this->getFormDatasForServerPart($formDatas, $serverEntity); //서버파트 생성 - list($serverEntity, $serviceEntity, $partEntity, $formDatas) = $this->getFormDatasForServerPart($formDatas); $entity = parent::create_process($formDatas); if (!$entity instanceof ServerPartEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerPartEntity만 가능"); @@ -106,7 +116,11 @@ class ServerPartService extends EquipmentService //해당 파트정보를 서버파트정보에 추가 $this->getPartService($entity->getType())->attachToServerPart($entity); //서비스가 정의 되어 있으면 - if ($serviceEntity instanceof ServiceEntity) { + if ($entity->getServiceInfoUid()) { + $serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid()); + if (!$serviceEntity instanceof ServiceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUid()}에 해당하는 서비스정보을 찾을수 없습니다."); + } //Billing형식이 Month이면 서비스 금액설정 호출 if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { service('customer_serviceservice')->updateAmount($serviceEntity); @@ -120,7 +134,13 @@ class ServerPartService extends EquipmentService } protected function modify_process($entity, array $formDatas): CommonEntity { - list($serverEntity, $serviceEntity, $partEntity, $formDatas) = $this->getFormDatasForServerPart($formDatas); + //서버정보 가져오기 + $serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']); + if (!$serverEntity instanceof ServerEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serverinfo_uid']}에 해당하는 서버정보을 찾을수 없습니다."); + } + //수정을 위한 추가 FormDatas설정 + $formDatas = $this->getFormDatasForServerPart($formDatas, $serverEntity); //서버파트 수정 $oldEntity = clone $entity; $entity = parent::modify_process($entity, $formDatas); @@ -130,7 +150,11 @@ class ServerPartService extends EquipmentService //해당 파트정보가 변경 $this->getPartService($entity->getType())->modifyServerPart($oldEntity, $entity); //서비스가 정의 되어 있으면 - if ($serviceEntity instanceof ServiceEntity) { + if ($entity->getServiceInfoUid()) { + $serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid()); + if (!$serviceEntity instanceof ServiceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUid()}에 해당하는 서비스정보을 찾을수 없습니다."); + } //Billing형식이 Month이면 서비스 금액설정 호출 if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { service('customer_serviceservice')->updateAmount($serviceEntity); diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 0ca5421..4a2cd3d 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -127,8 +127,13 @@ class ServerService extends EquipmentService throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); } //서버추가시 서버파트 자동추가용 - service('part_ipservice')->attachToServer($entity); - service('part_switchservice')->attachToServer($entity); + // dd($entity); + if ($entity->getIP()) { + service('part_ipservice')->attachToServer($entity); + } + if ($entity->getSwitchInfoUid()) { + service('part_switchservice')->attachToServer($entity); + } service('equipment_chassisservice')->attachToServer($entity); service('equipment_serverpartservice')->attachToServer($entity); return $entity; @@ -218,8 +223,12 @@ class ServerService extends EquipmentService throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서버정보을 찾을수 없습니다."); } //서버파트정보 해제 - service('part_ipservice')->detachFromServer($entity); - service('part_switchservice')->detachFromServer($entity); + if ($entity->getIP()) { + service('part_ipservice')->detachFromServer($entity); + } + if ($entity->getSwitchInfoUid()) { + service('part_switchservice')->detachFromServer($entity); + } service('equipment_serverpartservice')->detachFromServer($entity); //서버정보 초기화 $formDatas['serviceinfo_uid'] = null; diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php index b17186d..a8cc87a 100644 --- a/app/Services/Part/SWITCHService.php +++ b/app/Services/Part/SWITCHService.php @@ -56,7 +56,7 @@ class SWITCHService extends PartType3Service //IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정 $entity = $this->getEntity($serverEntity->getSwitchInfoUid()); if (!$entity instanceof SWITCHEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$serverEntity->getSwitchInfoUid()}에 해당하는 IP정보를 찾을수없습니다."); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$serverEntity->getSwitchInfoUid()}에 해당하는 스위치정보를 찾을수없습니다."); } return $entity; }