185 lines
8.3 KiB
PHP
185 lines
8.3 KiB
PHP
<?php
|
|
|
|
namespace lib\Controllers\DBMS\Client;
|
|
|
|
use lib\Services\HistoryService;
|
|
use lib\Services\MemberService;
|
|
use lib\Services\OnetimeService;
|
|
use lib\Utils\Pagination;
|
|
|
|
class PointController extends ClientController
|
|
{
|
|
private ?OnetimeService $_onetimeService = null;
|
|
private ?HistoryService $_historyService = null;
|
|
private ?MemberService $_memberService = null;
|
|
public function __construct(array $params = [])
|
|
{
|
|
parent::__construct($params);
|
|
$this->getView()->setPath('point');
|
|
} //
|
|
public function getMemberService(): MemberService
|
|
{
|
|
if ($this->_memberService === null) {
|
|
$this->_memberService = new MemberService();
|
|
}
|
|
return $this->_memberService;
|
|
}
|
|
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 -> IdcPointListMK.jsp 신규추가가
|
|
//CLI 접속방법 : php index.php site/client/point/index
|
|
//WEB 접속방법 : http://localhost/site/client/point/index
|
|
public function index()
|
|
{
|
|
//쿠폰내역
|
|
$this->curPage = intval($params['curPage'] ?? $this->request->get('curPage') ?? 1);
|
|
$this->perPage = intval($params['perPage'] ?? $this->request->get('perPage') ?? VIEW_LIST_PERPAGE);
|
|
[$this->total, $this->services] = $this->getServiceService()->getEntitiesForCoupon($this->curPage, $this->perPage);
|
|
$this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
|
|
$total_coupon = 0;
|
|
foreach ($this->services as $service) {
|
|
$total_coupon += $service->getCoupon();
|
|
}
|
|
$this->total_coupon = $total_coupon;
|
|
return $this->render(__FUNCTION__);
|
|
}
|
|
|
|
//IdcCouponUseMK.jsp -> domain_coupon_use.php
|
|
//CLI 접속방법 : php index.php site/client/counpon/client/client_code/코드
|
|
//WEB 접속방법 : http://localhost/site/client/coupon/client/client_code/코드
|
|
public function client()
|
|
{
|
|
//사용자정보
|
|
$client_code = $this->request->get('client_code');
|
|
if (!$client_code) {
|
|
throw new \Exception("client_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$client = $this->getClientService()->getEntityByCode($client_code);
|
|
if (!$client) {
|
|
throw new \Exception("[$client_code]에 해당하는 사용자정보가 존재하지 않습니다.");
|
|
}
|
|
$this->client = $client;
|
|
//전체 관리자정보(등록자)
|
|
$member_code = $this->request->get('mkid');
|
|
if (!$member_code) {
|
|
throw new \Exception("member_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$member = $this->getMemberService()->getEntityByCode($member_code);
|
|
if (!$member) {
|
|
throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
|
|
}
|
|
$this->member = $member;
|
|
//쿠폰내역
|
|
$this->curPage = intval($this->request->get('curPage', 1));
|
|
$this->perPage = intval($this->request->get('perPage', VIEW_LIST_PERPAGE));
|
|
[$this->total, $this->services] = $this->getServiceService()->getEntitiesForCoupon($this->curPage, $this->perPage, $client_code);
|
|
$this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
|
|
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()
|
|
{
|
|
$service_code = $this->request->get('service_code');
|
|
if (!$service_code) {
|
|
throw new \Exception("client_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$service = $this->getServiceService()->getEntityByCode($service_code);
|
|
if (!$service) {
|
|
throw new \Exception("[$service_code]에 해당하는 서비스정보가 존재하지 않습니다.");
|
|
}
|
|
$this->service = $service;
|
|
//사용자정보
|
|
$client = $this->getClientService()->getEntityByCode($service->getClientCode());
|
|
if (!$client) {
|
|
throw new \Exception("[{$service->getClientCode()}]에 해당하는 사용자정보가 존재하지 않습니다.");
|
|
}
|
|
$this->client = $client;
|
|
//전체 관리자정보(등록자)
|
|
$member_code = $this->request->get('mkid');
|
|
if (!$member_code) {
|
|
throw new \Exception("member_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$member = $this->getMemberService()->getEntityByCode($member_code);
|
|
if (!$member) {
|
|
throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
|
|
}
|
|
$this->member = $member;
|
|
$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()
|
|
{
|
|
$service_code = $this->request->get('service_code');
|
|
if (!$service_code) {
|
|
throw new \Exception("service_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$service = $this->getServiceService()->getEntityByCode($service_code);
|
|
if (!$service) {
|
|
throw new \Exception("[$service_code]에 해당하는 서비스정보가 존재하지 않습니다.");
|
|
}
|
|
$this->service = $service;
|
|
//사용자정보
|
|
$client = $this->getClientService()->getEntityByCode($service->getClientCode());
|
|
if (!$client) {
|
|
throw new \Exception("[{$service->getClientCode()}]에 해당하는 사용자정보가 존재하지 않습니다.");
|
|
}
|
|
$this->client = $client;
|
|
//전체 관리자정보(등록자)
|
|
$member_code = $this->request->get('mkid');
|
|
if (!$member_code) {
|
|
throw new \Exception("member_code 값이 정의되지 않았습니다.");
|
|
}
|
|
$member = $this->getMemberService()->getEntityByCode($member_code);
|
|
if (!$member) {
|
|
throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
|
|
}
|
|
//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') ?? 'point';
|
|
//onetime_request_date 사용일
|
|
$onetime_request_date = $this->request->get('onetime_request_date') ?? date("Y-m-d");
|
|
try {
|
|
$this->getServiceService()->beginTransaction();
|
|
//서비스쿠폰 갯수 수정
|
|
$this->getServiceService()->useCouponForDomain($service, $coupon);
|
|
//쿠폰 사용내역 onetime에 등록
|
|
$this->getOnetimeService()->useCouponForDomain($service, $client, $member, $onetime_case, $coupon, $note, $onetime_request_date);
|
|
//쿠폰 사용내역 history에 등록
|
|
$this->getHistoryService()->useCouponForDomain($service, $client, $onetime_case, $coupon, $note, $onetime_request_date);;
|
|
$this->getServiceService()->commit();
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $service->getClientCode());
|
|
} catch (\Exception $e) {
|
|
$this->getServiceService()->rollback();
|
|
return $this->redirect->back()->withInput()->with('error', ['message' => '쿠폰 사용에 실패하였습니다.:' . $e->getMessage()]);
|
|
}
|
|
}
|
|
} //Class
|