126 lines
3.3 KiB
PHP
126 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Entities\Customer;
|
|
|
|
use App\Models\Customer\ClientModel;
|
|
|
|
class ClientEntity extends CustomerEntity
|
|
{
|
|
const PK = ClientModel::PK;
|
|
const TITLE = ClientModel::TITLE;
|
|
|
|
/**
|
|
* 생성자
|
|
*/
|
|
public function __construct(array|null $data = null)
|
|
{
|
|
parent::__construct($data);
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Override Getter들 (모두 property 스타일 사용)
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
public function getCustomTitle(mixed $title = null): string
|
|
{
|
|
return sprintf("%s/%s", $this->getSite(), $title ? $title : $this->getTitle());
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function getSite(): string
|
|
{
|
|
return $this->site;
|
|
}
|
|
|
|
public function getAccountBalance(): int
|
|
{
|
|
return (int) ($this->account_balance ?? 0);
|
|
}
|
|
|
|
public function getCouponBalance(): int
|
|
{
|
|
return (int) ($this->coupon_balance ?? 0);
|
|
}
|
|
|
|
public function getPointBalance(): int
|
|
{
|
|
return (int) ($this->point_balance ?? 0);
|
|
}
|
|
|
|
public function getHistory(): ?string
|
|
{
|
|
return $this->history;
|
|
}
|
|
|
|
/**
|
|
* role을 배열로 반환
|
|
*/
|
|
public function getRole(): array
|
|
{
|
|
$role = $this->attributes['role'] ?? null;
|
|
|
|
if (is_array($role)) {
|
|
return array_values(array_filter($role, fn($v) => (string) $v !== ''));
|
|
}
|
|
|
|
if (is_string($role) && $role !== '') {
|
|
$decoded = json_decode($role, true);
|
|
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
|
$clean = array_map(
|
|
fn($item) => trim((string) ($item ?? ''), " \t\n\r\0\x0B\""),
|
|
$decoded
|
|
);
|
|
return array_values(array_filter($clean, fn($v) => $v !== ''));
|
|
}
|
|
|
|
$parts = explode(DEFAULTS["DELIMITER_COMMA"], $role);
|
|
$clean = array_map(
|
|
fn($item) => trim((string) ($item ?? ''), " \t\n\r\0\x0B\""),
|
|
$parts
|
|
);
|
|
return array_values(array_filter($clean, fn($v) => $v !== ''));
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* ✅ role은 DB 저장용 CSV 문자열로 반환
|
|
*/
|
|
public function setRole($role): string
|
|
{
|
|
$roleArray = [];
|
|
|
|
if (is_string($role)) {
|
|
$clean = trim($role, " \t\n\r\0\x0B\"");
|
|
if ($clean !== '') {
|
|
$decoded = json_decode($clean, true);
|
|
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
|
$roleArray = $decoded;
|
|
} else {
|
|
$roleArray = explode(DEFAULTS["DELIMITER_COMMA"], $clean);
|
|
}
|
|
}
|
|
} elseif (is_array($role)) {
|
|
$roleArray = $role;
|
|
} else {
|
|
$roleArray = [];
|
|
}
|
|
|
|
$cleaned = array_map(
|
|
fn($item) => trim((string) ($item ?? ''), " \t\n\r\0\x0B\""),
|
|
$roleArray
|
|
);
|
|
|
|
$roleArray = array_values(array_filter($cleaned, fn($v) => $v !== ''));
|
|
|
|
return implode(DEFAULTS["DELIMITER_COMMA"], $roleArray);
|
|
}
|
|
}
|