127 lines
5.4 KiB
PHP
127 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace lib\Controllers\DBMS\Client;
|
|
|
|
use lib\Services\HistoryService;
|
|
use lib\Services\OnetimeService;
|
|
use lib\Services\PointService;
|
|
use lib\Utils\Pagination;
|
|
|
|
class PointController extends ClientController
|
|
{
|
|
private ?PointService $_pointService = null;
|
|
private ?OnetimeService $_onetimeService = null;
|
|
private ?HistoryService $_historyService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->getView()->setPath('point');
|
|
} //
|
|
public function getPointService(): PointService
|
|
{
|
|
if ($this->_pointService === null) {
|
|
$this->_pointService = new PointService();
|
|
}
|
|
return $this->_pointService;
|
|
}
|
|
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;
|
|
}
|
|
|
|
//IdcPointListMK.jsp -> domain_point.php
|
|
//CLI 접속방법 : php index.php site/client/point/index
|
|
//WEB 접속방법 : http://localhost/site/client/point/index
|
|
public function index()
|
|
{
|
|
//전체 고객객정보
|
|
$this->clients = $this->getClientService()->getEntities();
|
|
//전체 관리자정보(등록자)
|
|
$this->members = $this->getMemberService()->getEntities();
|
|
//사용자별 포인트내역
|
|
$client_code = $this->request->get('client_code');
|
|
if ($client_code) {
|
|
$this->getPointService()->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->getPointService()->getList($this->curPage, $this->perPage);
|
|
$this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
|
|
return $this->render(__FUNCTION__);
|
|
}
|
|
|
|
//IdcPointBuyMK.jsp -> domain_point_buy.php
|
|
//CLI 접속방법 : php index.php site/client/point/insert_form
|
|
//WEB 접속방법 : http://localhost/site/client/point/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__);
|
|
}
|
|
|
|
//IdcPointBuyMK.jsp -> domain_point_buy.php
|
|
//CLI 접속방법 : php index.php site/client/point/insert_form
|
|
//WEB 접속방법 : http://localhost/site/client/point/insert_form
|
|
public function insert()
|
|
{
|
|
//기본적으로 필요한 client_code, mkid, service_code를 설정합니다.
|
|
list($client_code, $member_code, $service_code) = $this->setDefaultRequestData();
|
|
//포인트 형식
|
|
$type = $this->request->get('type');
|
|
if (!$type) {
|
|
throw new \Exception("포인트 형식이 정의되지 않았습니다.");
|
|
}
|
|
//포인트 제목
|
|
$title = $this->request->get('title');
|
|
if (!$title) {
|
|
throw new \Exception("포인트 제목이 정의되지 않았습니다.");
|
|
}
|
|
//포인트 값
|
|
$amount = intval($this->request->get('amount'));
|
|
if (! $amount || $amount < 1) {
|
|
throw new \Exception("포인트 값이 정의되지 않았거나, 포인트값은 1 이상이어야 합니다.");
|
|
}
|
|
//포인트 작업 내용
|
|
$note = $this->request->get('note');
|
|
// //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 {
|
|
$formDatas = [
|
|
'client_code' => $client_code,
|
|
'member_code' => $member_code,
|
|
'type' => $type,
|
|
'title' => $title,
|
|
'amount' => $amount,
|
|
'note' => $note
|
|
];
|
|
$this->getServiceService()->beginTransaction();
|
|
// //서비스포인트 갯수 수정
|
|
// $this->getServiceService()->usePointByService($service, $point);
|
|
// //포인트 사용내역 onetime에 등록
|
|
// $this->getOnetimeService()->usePointByService($service, $client, $member, $onetime_case, $point, $note, $onetime_request_date);
|
|
// //포인트 사용내역 history에 등록
|
|
// $this->getHistoryService()->usePointByService($service, $client, $onetime_case, $point, $note, $onetime_request_date);;
|
|
$this->getPointService()->getModel()->insert($formDatas);
|
|
$this->getServiceService()->commit();
|
|
return $this->redirect->to(DBMS_SITE_URL . "/IdcPointList.cup")->with('success', ['message' => '포인트 작업이 완료되었습니다.']);
|
|
} catch (\Exception $e) {
|
|
$this->getServiceService()->rollback();
|
|
return $this->redirect->back()->withInput()->with('error', ['message' => '포인트 사용에 실패하였습니다.:' . $e->getMessage()]);
|
|
}
|
|
}
|
|
} //Class
|