104 lines
4.6 KiB
PHP
104 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace lib\Controllers\DBMS\Client;
|
|
|
|
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()
|
|
{
|
|
parent::__construct();
|
|
$this->getView()->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, mkid, service_code를 설정합니다.
|
|
list($client_code, $member_code, $service_code) = $this->setDefaultRequestData();
|
|
//사용자별 쿠폰내역
|
|
if ($client_code) {
|
|
$this->getServiceService()->getModel()->where('client_code', $client_code);
|
|
}
|
|
$this->curPage = intval($this->request->get('curPage', 1));
|
|
$this->perPage = intval($this->request->get('perPage', VIEW_LIST_PERPAGE));
|
|
[$this->total, $this->entities] = $this->getServiceService()->getList($this->curPage, $this->perPage);
|
|
$this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
|
|
$total_coupon = 0;
|
|
foreach ($this->entities as $entity) {
|
|
$total_coupon += $entity->getCoupon();
|
|
}
|
|
$this->total_coupon = $total_coupon;
|
|
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 insert_form()
|
|
{
|
|
//기본적으로 필요한 client_code, mkid, service_code를 설정합니다.
|
|
list($client_code, $member_code, $service_code) = $this->setDefaultRequestData();
|
|
$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 insert()
|
|
{
|
|
//기본적으로 필요한 client_code, mkid, service_code를 설정합니다.
|
|
list($client_code, $member_code, $service_code) = $this->setDefaultRequestData();
|
|
//onetime_sub 도메인 구매 수량
|
|
$coupon = $this->request->get('coupon');
|
|
if (! $coupon || $coupon < 1) {
|
|
throw new \Exception("도메인 구매 수량 값이 정의되지 않았거나, 도메인 구매 수량은 1개 이상이어야 합니다.");
|
|
}
|
|
//onetime_note 도메인 구매 수량
|
|
$note = $this->request->get('note');
|
|
if (!$note) {
|
|
throw new \Exception("도메인 리스트 값이 정의되지 않았습니다.");
|
|
}
|
|
//onetime_case 사용용도
|
|
$onetime_case = $this->request->get('onetime_case', 'domain');
|
|
//onetime_request_date 사용일
|
|
$onetime_request_date = $this->request->get('onetime_request_date') ?? date("Y-m-d");
|
|
try {
|
|
$this->getServiceService()->beginTransaction();
|
|
//서비스쿠폰 갯수 수정
|
|
$this->getServiceService()->useCouponByService($this->service, $coupon);
|
|
//쿠폰 사용내역 onetime에 등록
|
|
$this->getOnetimeService()->useCouponByService($this->service, $this->client, $this->member, $onetime_case, $coupon, $note, $onetime_request_date);
|
|
//쿠폰 사용내역 history에 등록
|
|
$this->getHistoryService()->useCouponByService($this->service, $this->client, $onetime_case, $coupon, $note, $onetime_request_date);;
|
|
$this->getServiceService()->commit();
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $this->service->getClientCode());
|
|
} catch (\Exception $e) {
|
|
$this->getServiceService()->rollback();
|
|
return $this->redirect->back()->withInput()->with('error', ['message' => '쿠폰 사용에 실패하였습니다.:' . $e->getMessage()]);
|
|
}
|
|
}
|
|
} //Class
|