daemon-idc/app/DTOs/Customer/ClientDTO.php
2026-02-09 18:38:26 +09:00

52 lines
1.4 KiB
PHP

<?php
namespace App\DTOs\Customer;
use App\DTOs\CommonDTO;
class ClientDTO extends CommonDTO
{
public ?int $uid = null;
public ?int $user_uid = null;
public ?string $id = null;
public ?string $passwd = null;
public string $site = '';
public string $name = '';
public string $phone = '';
public string $email = '';
public array $role = [];
public int $account_balance = 0;
public int $coupon_balance = 0;
public int $point_balance = 0;
public string $status = '';
public string $history = '';
public function __construct(array $datas = [])
{
// 1. role 변환 로직 (기존 유지)
if (isset($datas['role']) && is_string($datas['role'])) {
$datas['role'] = explode(DEFAULTS["DELIMITER_COMMA"], $datas['role']);
}
if (!isset($datas['role'])) {
$datas['role'] = [];
}
// 2. [추가] 잔액 관련 데이터가 null이거나 비어있다면 0으로 보정
// CommonDTO의 parent::__construct가 호출되기 전에 데이터를 정제합니다.
$balanceFields = ['account_balance', 'coupon_balance', 'point_balance'];
foreach ($balanceFields as $field) {
if (!isset($datas[$field]) || $datas[$field] === '' || $datas[$field] === null) {
$datas[$field] = 0;
}
}
parent::__construct($datas);
}
public function getRoleToString(): string
{
return implode(DEFAULTS["DELIMITER_COMMA"], $this->role);
}
}