56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Entities\Customer\CouponEntity;
|
|
use App\Models\Customer\CouponModel;
|
|
use App\Entities\Customer\ClientEntity;
|
|
|
|
class CouponService extends CustomerService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new CouponModel());
|
|
$this->addClassName('Coupon');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"clientinfo_code",
|
|
"status",
|
|
"title",
|
|
"amount",
|
|
];
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return ["clientinfo_code", 'status'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
//기본 기능부분
|
|
|
|
//고객예치금처리
|
|
private function setBalance(array $formDatas): void
|
|
{
|
|
//coupon_balance 체크
|
|
$entity = $this->getClientService()->getEntity($formDatas['clientinfo_code']);
|
|
if (!$entity) {
|
|
throw new \Exception("{$formDatas['clientinfo_code']}에 대한 고객정보를 찾을수 없습니다.");
|
|
}
|
|
$amount = intval($formDatas['amount']);
|
|
if ($formDatas['status'] === CouponEntity::DEFAULT_STATUS) { //입금, 쿠폰추가
|
|
$entity = $this->getClientService()->deposit($entity, 'coupon_balance', $amount);
|
|
} else { // 출금, 쿠폰사용
|
|
$entity = $this->getClientService()->withdrawal($entity, 'coupon_balance', $amount);
|
|
}
|
|
}
|
|
public function create(array $formDatas): CouponEntity
|
|
{
|
|
$this->setBalance($formDatas);
|
|
return parent::create($formDatas);
|
|
}
|
|
}
|