112 lines
5.4 KiB
PHP
112 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace lib\Controllers\Client;
|
|
|
|
use lib\Entities\ClientEntity;
|
|
use lib\Services\HistoryService;
|
|
use lib\Services\OnetimeService;
|
|
use lib\Utils\Pagination;
|
|
|
|
class CouponController extends ClientController
|
|
{
|
|
private ?OnetimeService $_onetimeService = null;
|
|
private ?HistoryService $_historyService = null;
|
|
public function __construct(array $params = [])
|
|
{
|
|
parent::__construct($params);
|
|
$this->setPath('coupon');
|
|
} //
|
|
public function getOnetimeService(): OnetimeService
|
|
{
|
|
if ($this->_onetimeService === null) {
|
|
$this->_onetimeService = new OnetimeService();
|
|
}
|
|
return $this->_onetimeService;
|
|
}
|
|
public function getHistoryService(): HistoryService
|
|
{
|
|
if ($this->_historyService === null) {
|
|
$this->_historyService = new HistoryService();
|
|
}
|
|
return $this->_historyService;
|
|
}
|
|
|
|
//IdcCouponListMK.jsp -> domain_coupon.php
|
|
//CLI 접속방법 : php index.php site/client/counpon/index
|
|
//WEB 접속방법 : http://localhost/site/client/coupon/index
|
|
public function index()
|
|
{
|
|
//기본적으로 필요한 client_code, member_code, service_code를 설정합니다.
|
|
list($this->client, $this->member, $this->service) = $this->setDefaultRequestData();
|
|
//사용자 코드가 있으면
|
|
if ($this->client instanceof ClientEntity) {
|
|
$this->getServiceService()->getModel()->where('client_code', $this->client->getClientCode());
|
|
}
|
|
//업체명_일회성만 나오게하기 위해서
|
|
$this->getServiceService()->getModel()->like('server_code', "%\-일회성");
|
|
[$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getServiceService()->getList(
|
|
$this->request->get('curPage'),
|
|
$this->request->get('perPage')
|
|
);
|
|
//전체 사용자정보
|
|
$this->clients = $this->getClientService()->getEntities();
|
|
return $this->render(__FUNCTION__);
|
|
}
|
|
|
|
//IdcCouponBuyMK.jsp -> domain_coupon_buy.php
|
|
//CLI 접속방법 : php index.php site/client/counpon/insert_form
|
|
//WEB 접속방법 : http://localhost/site/client/coupon/insert_form
|
|
public function update_form()
|
|
{
|
|
//기본적으로 필요한 client_code, member_code, service_code를 설정합니다.
|
|
list($this->client, $this->member, $this->service) = $this->setDefaultRequestData(null, true, true);
|
|
//기본적으로 필요한 client_code, mkid, service_code를 설정합니다.
|
|
$this->today = date("Y-m-d");
|
|
return $this->render(__FUNCTION__);
|
|
}
|
|
|
|
//IdcCouponBuyMK.jsp -> domain_coupon_buy.php
|
|
//CLI 접속방법 : php index.php site/client/counpon/insert_form
|
|
//WEB 접속방법 : http://localhost/site/client/coupon/insert_form
|
|
public function use()
|
|
{
|
|
try {
|
|
//기본적으로 필요한 client_code, member_code, service_code를 설정합니다.
|
|
list($this->client, $this->member, $this->service) = $this->setDefaultRequestData(null, true, true);
|
|
//onetime_case 사용용도
|
|
$onetime_case = $this->request->get('type');
|
|
if (! $onetime_case) {
|
|
throw new \Exception("쿠폰 사용용도를 선택하세요");
|
|
}
|
|
//onetime_note 사용내역
|
|
$title = $this->request->get('title');
|
|
if (! $title) {
|
|
throw new \Exception("쿠폰 사용제목을 입력하세요");
|
|
}
|
|
//onetime_sub 사용수량
|
|
$coupon_select = $this->request->get('select_coupon');
|
|
if (! $coupon_select) {
|
|
throw new \Exception("쿠폰 수량 값이 정의되지 않았거나, 도메인 구매 수량은 1개 이상이어야 합니다.");
|
|
}
|
|
//onetime_note 비고
|
|
$note = $this->request->get('coupon_note');
|
|
//onetime_request_date 사용일
|
|
$onetime_request_date = $this->request->get('onetime_request_date') ?? date("Y-m-d");
|
|
$this->getServiceService()->beginTransaction();
|
|
//서비스쿠폰 갯수 수정
|
|
$this->getServiceService()->useCouponByService($this->service, $coupon_select);
|
|
//쿠폰 사용내역 onetime에 등록
|
|
$this->getOnetimeService()->useCouponByService($this->service, $this->client, $this->member, $onetime_case, $title, $coupon_select, $note, $onetime_request_date);
|
|
//쿠폰 사용내역 history에 등록
|
|
$this->getHistoryService()->useCouponByService($this->service, $this->client, $onetime_case, $coupon_select, $note, $onetime_request_date);;
|
|
$this->getServiceService()->commit();
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $this->service->getClientCode())->send();
|
|
} catch (\PDOException $e) {
|
|
$this->getServiceService()->rollback();
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponListMK.cup?client_code=" . $this->service->getClientCode())->withInput()->with('error', '쿠폰 사용에 실패하였습니다.:' . $e->getMessage())->send();
|
|
} catch (\Exception $e) {
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponListMK.cup?client_code=" . $this->service->getClientCode())->withInput()->with('error', '쿠폰 사용에 실패하였습니다.:' . $e->getMessage())->send();
|
|
}
|
|
}
|
|
} //Class
|