dbmsv4 init...3
This commit is contained in:
parent
a0724e5d0f
commit
be378d99ef
@ -123,21 +123,19 @@ abstract class CommonForm
|
||||
}
|
||||
$dynamicRules = [];
|
||||
$dynamicLabels = []; // 레이블 배열 추가
|
||||
if (!count($this->getFormRules())) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 지정된 Form RULE이 없습니다.");
|
||||
}
|
||||
foreach ($this->getFormRules() as $field => $rule) {
|
||||
list($field, $rule) = $this->getValidationRule($field, $rule);
|
||||
$dynamicRules[$field] = $rule; // 규칙만 저장
|
||||
$dynamicLabels[$field] = $this->getFormFields()[$field];
|
||||
}
|
||||
log_message('debug', 'Validate Fields: ' . var_export($this->getFormFields(), true));
|
||||
log_message('debug', 'Validate Rules: ' . var_export($dynamicRules, true));
|
||||
log_message('debug', 'Validate Data: ' . var_export($formDatas, true));
|
||||
if (!count($dynamicRules)) {
|
||||
log_message('debug', 'Validate Rules: ' . var_export($this->getFormRules(), true));
|
||||
log_message('debug', 'Validate Dynamic Rules: ' . var_export($dynamicRules, true));
|
||||
log_message('debug', 'Validate Data: ' . var_export($formDatas, true));
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 지정된 Form RULE이 없습니다.");
|
||||
}
|
||||
// setRules의 세 번째 인자로 레이블 전달
|
||||
$this->_validation->setRules($dynamicRules, [], $dynamicLabels);
|
||||
|
||||
// run()에는 데이터만 전달 (setRules에서 이미 설정됨)
|
||||
$result = $this->_validation->run($formDatas);
|
||||
if ($result === false) {
|
||||
$message = static::class . '->' . __FUNCTION__ . "에서 데이터 검증 오류발생: " . var_export($this->_validation->getErrors(), true);
|
||||
|
||||
@ -190,8 +190,8 @@ abstract class CommonService
|
||||
}
|
||||
$entity = $this->save_process($entity);
|
||||
//입력/출력데이터 확인용
|
||||
log_message('debug', var_export($formDatas, true));
|
||||
log_message('debug', var_export($entity->toArray(), true));
|
||||
// log_message('debug', var_export($formDatas, true));
|
||||
// log_message('debug', var_export($entity->toArray(), true));
|
||||
return $entity;
|
||||
}
|
||||
final public function create(array $formDatas): object
|
||||
@ -225,13 +225,13 @@ abstract class CommonService
|
||||
$fields = array_keys($formDatas);
|
||||
$this->getFormService()->setFormFields($fields);
|
||||
$this->getFormService()->setFormRules('modify', $fields);
|
||||
if (static::class === PaymentService::class) {
|
||||
var_dump($this->getFormService()->getFormRules());
|
||||
echo "<HR>";
|
||||
var_dump($formDatas);
|
||||
dd($entity->toArray());
|
||||
echo "<HR>";
|
||||
}
|
||||
// if (static::class === PaymentService::class) {
|
||||
// var_dump($this->getFormService()->getFormRules());
|
||||
// echo "<HR>";
|
||||
// var_dump($formDatas);
|
||||
// dd($entity->toArray());
|
||||
// echo "<HR>";
|
||||
// }
|
||||
// 데이터 검증
|
||||
if (!$this->getFormService()->validate($formDatas)) {
|
||||
throw new ValidationException(
|
||||
@ -251,8 +251,8 @@ abstract class CommonService
|
||||
}
|
||||
$entity = $this->save_process($entity);
|
||||
//입력/출력데이터 확인용
|
||||
log_message('debug', var_export($formDatas, true));
|
||||
log_message('debug', var_export($entity->toArray(), true));
|
||||
// log_message('debug', var_export($formDatas, true));
|
||||
// log_message('debug', var_export($entity->toArray(), true));
|
||||
return $entity;
|
||||
}
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ class AccountService extends WalletService
|
||||
$formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle();
|
||||
$formDatas['balance'] = $clientEntity->getAccountBalance() - $formDatas['amount'];
|
||||
if ($formDatas['balance'] < 0) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액이 0보다 값이 정의 되었습니다.");
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액({$formDatas['balance']})이 0보다 작은 값이 정의되었습니다.");
|
||||
}
|
||||
//고객 잔액 갱신
|
||||
service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]);
|
||||
|
||||
@ -5,7 +5,6 @@ namespace App\Services\Customer\Wallet;
|
||||
use App\DTOs\Customer\Wallet\CouponDTO;
|
||||
use App\Entities\Customer\ClientEntity;
|
||||
use App\Entities\Customer\Wallet\CouponEntity;
|
||||
use App\Entities\PaymentEntity;
|
||||
use App\Forms\Customer\Wallet\CouponForm;
|
||||
use App\Helpers\Customer\Wallet\CouponHelper;
|
||||
use App\Models\Customer\Wallet\CouponModel;
|
||||
@ -139,22 +138,27 @@ class CouponService extends WalletService
|
||||
return parent::deposit_process($clientEntity, $formDatas);
|
||||
}
|
||||
//결제 관련 쿠폰 사용 처리
|
||||
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array
|
||||
protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array
|
||||
{
|
||||
$amount = $paymentEntity->getAmount();
|
||||
$balance = $clientEntity->getCouponBalance();
|
||||
if ($balance < $amount) {
|
||||
if (!array_key_exists('amount', $formDatas)) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 출금액이 정의되지 않았습니다.");
|
||||
}
|
||||
if ($clientEntity->getCouponBalance() < $formDatas['amount']) {
|
||||
throw new RuntimeException(sprintf(
|
||||
"%s 에서 오류발생: 사용쿠폰 수량(%s) , %s 고객의 잔여쿠폰 수량(%s)이 부족합니다.",
|
||||
"%s 에서 오류발생: 사용쿠폰 수량(%s) , %s 잔여쿠폰 수량(%s)이 부족합니다.",
|
||||
static::class . '->' . __FUNCTION__,
|
||||
number_format($amount),
|
||||
number_format($formDatas['amount']),
|
||||
$clientEntity->getTitle(),
|
||||
number_format($balance)
|
||||
number_format($clientEntity->getCouponBalance())
|
||||
));
|
||||
}
|
||||
//최종처리
|
||||
$formDatas['cnt'] = $amount;
|
||||
$formDatas['balance'] = $balance - $amount;
|
||||
return $formDatas;
|
||||
$formDatas['balance'] = $clientEntity->getCouponBalance() - $formDatas['amount'];
|
||||
if ($formDatas['balance'] < 0) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔여쿠폰수량({$formDatas['balance']})이 0보다 작은 값이 정의되었습니다.");
|
||||
}
|
||||
//고객 잔여쿠폰 갱신
|
||||
service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]);
|
||||
return parent::withdrawal_process($clientEntity, $formDatas);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ namespace App\Services\Customer\Wallet;
|
||||
use App\DTOs\Customer\Wallet\PointDTO;
|
||||
use App\Entities\Customer\ClientEntity;
|
||||
use App\Entities\Customer\Wallet\PointEntity;
|
||||
use App\Entities\PaymentEntity;
|
||||
use App\Forms\Customer\Wallet\PointForm;
|
||||
use App\Helpers\Customer\Wallet\PointHelper;
|
||||
use App\Models\Customer\Wallet\PointModel;
|
||||
@ -13,6 +12,7 @@ use RuntimeException;
|
||||
|
||||
class PointService extends WalletService
|
||||
{
|
||||
const CLIENTINFO_BALANCE_FIELD = 'point_balance';
|
||||
private $_form = null;
|
||||
private $_helper = null;
|
||||
public function __construct(PointModel $model)
|
||||
@ -122,23 +122,28 @@ class PointService extends WalletService
|
||||
//FormFilter 조건절 처리
|
||||
//검색어조건절처리
|
||||
|
||||
//결제 관련 출금 처리
|
||||
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array
|
||||
//결제 관련 포인트 사용 처리
|
||||
protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array
|
||||
{
|
||||
$amount = $paymentEntity->getAmount();
|
||||
$balance = $clientEntity->getPointBalance();
|
||||
if ($balance < $amount) {
|
||||
if (!array_key_exists('amount', $formDatas)) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 사용포인트가 정의되지 않았습니다.");
|
||||
}
|
||||
if ($clientEntity->getPointBalance() < $formDatas['amount']) {
|
||||
throw new RuntimeException(sprintf(
|
||||
"%s 에서 오류발생: 사용포인트(%s) , %s 고객의 포인트(%s)가 부족합니다.",
|
||||
"%s 에서 오류발생: 사용포인트(%s) , %s 잔여포인트(%s)가 부족합니다.",
|
||||
static::class . '->' . __FUNCTION__,
|
||||
number_format($amount),
|
||||
number_format($formDatas['amount']),
|
||||
$clientEntity->getTitle(),
|
||||
number_format($balance)
|
||||
number_format($clientEntity->getPointBalance())
|
||||
));
|
||||
}
|
||||
//최종처리
|
||||
$formDatas['amount'] = $amount;
|
||||
$formDatas['balance'] = $balance - $amount;
|
||||
return $formDatas;
|
||||
$formDatas['balance'] = $clientEntity->getPointBalance() - $formDatas['amount'];
|
||||
if ($formDatas['balance'] < 0) {
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔여포인트({$formDatas['balance']})가 0보다 작은 값이 정의되었습니다.");
|
||||
}
|
||||
//고객 잔여포인트 갱신
|
||||
service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]);
|
||||
return parent::withdrawal_process($clientEntity, $formDatas);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ abstract class WalletService extends CustomerService
|
||||
$formDatas['issue_at'] = array_key_exists('issue_at', $formDatas) ? $formDatas['issue_at'] : date('Y-m-d');
|
||||
return $formDatas;
|
||||
}
|
||||
//결제관련 출금 처리
|
||||
//결제관련 출금 처리(결제를 통해서만 호출되므로 action_init_process로 fields,rules 초기화 필요)
|
||||
final public function withdrawalByPayment(PaymentEntity $paymentEntity): void
|
||||
{
|
||||
//고객 정보
|
||||
@ -72,7 +72,8 @@ abstract class WalletService extends CustomerService
|
||||
'amount' => $paymentEntity->getAmount(),
|
||||
'status' => STATUS['WITHDRAWAL'],
|
||||
];
|
||||
$this->withdrawal_process($clientEntity, $formDatas);
|
||||
//초기화
|
||||
$this->action_init_process('create');
|
||||
$this->create_process($formDatas);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user