diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index 5353318..5e2e1ee 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -60,7 +60,7 @@ class ClientController extends CustomerController if (!$history) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다."); } - $entity = $this->service->modify($uid, ['history' => $history]); + $entity = $this->service->history($uid, $history); $this->addViewDatas('entity', $entity); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); } catch (\Throwable $e) { diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 2c422ad..0e86783 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -51,7 +51,7 @@ class ServiceController extends CustomerController if (!$history) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다."); } - $entity = $this->service->modify($uid, ['history' => $history]); + $entity = $this->service->history($uid, $history); $this->addViewDatas('entity', $entity); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); } catch (\Throwable $e) { diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 90f750c..38c9c36 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -2,13 +2,14 @@ namespace App\Services\Customer; -use App\DTOs\Customer\ClientDTO; -use App\Entities\Customer\ClientEntity; -use App\Entities\PaymentEntity; -use App\Forms\Customer\ClientForm; -use App\Helpers\Customer\ClientHelper; -use App\Models\Customer\ClientModel; use RuntimeException; +use App\Entities\CommonEntity; +use App\Entities\PaymentEntity; +use App\DTOs\Customer\ClientDTO; +use App\Forms\Customer\ClientForm; +use App\Models\Customer\ClientModel; +use App\Helpers\Customer\ClientHelper; +use App\Entities\Customer\ClientEntity; class ClientService extends CustomerService { @@ -69,4 +70,21 @@ class ClientService extends CustomerService 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__); + } } diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 06b62e4..de69575 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -2,14 +2,15 @@ namespace App\Services\Customer; -use App\DTOs\Customer\ServiceDTO; -use App\Entities\Customer\ServiceEntity; -use App\Forms\Customer\ServiceForm; -use App\Helpers\Customer\ServiceHelper; -use App\Models\Customer\ServiceModel; -use DateTimeImmutable; use DateTimeZone; use RuntimeException; +use DateTimeImmutable; +use App\Entities\CommonEntity; +use App\DTOs\Customer\ServiceDTO; +use App\Forms\Customer\ServiceForm; +use App\Models\Customer\ServiceModel; +use App\Helpers\Customer\ServiceHelper; +use App\Entities\Customer\ServiceEntity; class ServiceService extends CustomerService { @@ -189,4 +190,22 @@ class ServiceService extends CustomerService return $this->recalcAmountAndSyncPaymentByOld($oldEntity, $entity); } + + 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__); + } }