dbmsv4/app/Services/Customer/ClientService.php
2026-02-26 16:57:21 +09:00

97 lines
3.2 KiB
PHP

<?php
namespace App\Services\Customer;
use RuntimeException;
use App\Entities\CommonEntity;
use App\Forms\Customer\ClientForm;
use App\Models\Customer\ClientModel;
use App\Helpers\Customer\ClientHelper;
use App\Entities\Customer\ClientEntity;
class ClientService extends CustomerService
{
protected string $formClass = ClientForm::class;
protected string $helperClass = ClientHelper::class;
public function __construct(ClientModel $model)
{
parent::__construct($model);
$this->addClassPaths('Client');
}
public function getEntityClass(): string
{
return ClientEntity::class;
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ClientEntity
{
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
//OrderBy 처리
public function setOrderBy(mixed $field = null, mixed $value = null): void
{
$this->model->orderBy("site ASC,name ASC");
parent::setOrderBy($field, $value);
}
protected function fieldhook_process(string $field, $value, array $formDatas): array
{
switch ($field) {
case 'role':
$arr = is_array($value) ? $value : explode(',', (string) $value);
$arr = array_values(array_filter(array_map('trim', $arr)));
sort($arr);
$formDatas[$field] = implode(',', $arr);
break;
default:
$formDatas = parent::fieldhook_process($field, $value, $formDatas);
break;
}
return $formDatas;
}
// protected function modify_process_fieldhook(array $formDatas): array
// {
// // 1) DB 컬럼 아닌 값 제거
// unset($formDatas['confirmpassword']);
// // 2) role은 무조건 문자열로
// if (array_key_exists('role', $formDatas)) {
// $arr = is_array($formDatas['role'])
// ? $formDatas['role']
// : explode(',', (string) $formDatas['role']);
// $arr = array_values(array_filter(array_map('trim', $arr)));
// sort($arr);
// $formDatas['role'] = implode(',', $arr);
// }
// // 3) passwd는 빈 값이면 업데이트 제외 (원하면)
// if (array_key_exists('passwd', $formDatas) && $formDatas['passwd'] === '') {
// unset($formDatas['passwd']);
// }
// return $formDatas;
// }
public function history(string|int $uid, string $history): CommonEntity
{
return $this->dbTransaction(function () use ($uid, $history) {
$entity = $this->getEntity($uid);
if (!$entity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다.");
}
$formDatas['user_uid'] = (int) $this->getAuthContext()->getUID();
$formDatas['history'] = $history;
// 검증 통과 후 엔티티 반영
$entity->fill($formDatas);
if (!$entity->hasChanged()) {
return $entity;
}
return $this->save_process($entity);
}, __FUNCTION__);
}
}