addClassPaths('Client'); } protected function getDTOClass(): string { return ClientDTO::class; } public function createDTO(array $formDatas): ClientDTO { return new ClientDTO($formDatas); } public function getEntityClass(): string { return ClientEntity::class; } public function getFormService(): ClientForm { if ($this->_form === null) { $this->_form = new ClientForm(); $this->_form->setAttributes([ 'pk_field' => $this->model->getPKField(), 'title_field' => $this->model->getTitleField(), 'table' => $this->model->getTable(), 'useAutoIncrement' => $this->model->useAutoIncrement(), 'class_path' => $this->getClassPaths(false) ]); } return $this->_form; } public function getHelper(): ClientHelper { if ($this->_helper === null) { $this->_helper = new ClientHelper(); $this->_helper->setAttributes([ 'pk_field' => $this->model->getPKField(), 'title_field' => $this->model->getTitleField(), 'table' => $this->model->getTable(), 'useAutoIncrement' => $this->model->useAutoIncrement(), 'class_path' => $this->getClassPaths(false) ]); } return $this->_helper; } public function action_init_process(string $action, array $formDatas = []): void { $fields = [ 'site', 'name', 'email', 'phone', 'role', ]; $filters = [ 'site', 'role', 'status', ]; $indexFilter = $filters; $batchjobFilters = ['site', 'role', 'status']; switch ($action) { case 'create': case 'create_form': break; case 'modify': case 'modify_form': $fields = [...$fields, 'status']; break; case 'view': $fields = [...$fields, 'status', 'created_at']; break; case 'index': case 'download': $fields = [ 'site', 'name', 'email', 'phone', 'role', 'account_balance', 'coupon_balance', 'point_balance', 'status', 'created_at', 'updated_at', ]; break; } $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules($action, $fields); $this->getFormService()->setFormFilters($filters); $this->getFormService()->setFormOptions($action, $filters, $formDatas); $this->getFormService()->setIndexFilters($indexFilter); $this->getFormService()->setBatchjobFilters($batchjobFilters); } final public function updateBalance(int|ClientEntity $uid, string $title, string $key, int $value, string $status): ClientEntity { $entity = is_int($uid) ? $this->getEntity($uid) : $uid; if (!$entity instanceof ClientEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다."); } $calculatedValue = null; $balance = 0; $title = ""; switch ($key) { case PAYMENT['PAY']['ACCOUNT']: $balance = $entity->getAccountBalance(); break; case PAYMENT['PAY']['COUPON']: $balance = $entity->getCouponBalance(); $title = "쿠폰"; break; case PAYMENT['PAY']['POINT']: $balance = $entity->getPointBalance(); $title = "포인트"; break; } //입금,추가 처리 if ($status === STATUS['DEPOSIT']) { $calculatedValue = $balance - $value; } //출금,사용 처리 if ($status === STATUS['WITHDRAWAL']) { if ($balance < $value) { throw new RuntimeException(sprintf( "%s 에서 오류발생: 고객 %s[%s]이/가 사용한 %s 금액/수[%s] 보다 작습니다.", __METHOD__, $title, number_format($balance), $title, number_format($value) )); } $calculatedValue = $balance - $value; } if (!is_int($calculatedValue) || $calculatedValue < 0) { throw new RuntimeException(__METHOD__ . "에서 {$title}의 계산결과 값이 NULL이거나 0보다 작은 값입니다."); } //balance 수정 $formDatas = ["{$key}_balance" => $calculatedValue, 'status' => $status]; $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules('modify', $fields); return parent::modify_process($entity, $formDatas); } //기본 기능부분 protected function getEntity_process(mixed $entity): ClientEntity { return $entity; } protected function create_process(array $formDatas): ClientEntity { return parent::create_process($formDatas); } protected function modify_process($entity, array $formDatas): ClientEntity { return parent::modify_process($entity, $formDatas); } //List 검색용 //FormFilter 조건절 처리 //검색어조건절처리 public function setSearchWord(string $word): void { $this->model->orLike($this->model->getTable() . '.alias', $word, 'both'); parent::setSearchWord($word); } //OrderBy 처리 public function setOrderBy(mixed $field = null, mixed $value = null): void { $this->model->orderBy("site ASC,name ASC"); parent::setOrderBy($field, $value); } }