From ebc9e478db8615a2778830724957e4b6c627dd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0git=20config=20git=20config=20-?= =?UTF-8?q?-helpgit=20config=20--global=20user=2Ename=20=EC=B5=9C=EC=A4=80?= =?UTF-8?q?=ED=9D=A0?= Date: Sat, 12 Aug 2023 20:55:23 +0900 Subject: [PATCH] shoppingmallv2 init... --- app/Config/Constants.php | 8 +- app/Config/Routes.php | 18 +-- app/Config/Routes_Shoppinmall.php | 19 +-- app/Controllers/Admin/BoardController.php | 5 +- app/Controllers/Admin/CategoryController.php | 5 +- app/Controllers/Admin/OrderController.php | 5 +- app/Controllers/Admin/ProductController.php | 5 +- app/Controllers/Admin/SitepageController.php | 5 +- app/Controllers/Admin/UserController.php | 5 +- app/Controllers/Admin/UserSNSController.php | 5 +- app/Controllers/BaseController.php | 3 - .../Ecommerce/EcommerceController.php | 41 ------ .../Ecommerce/Payment/PaymentController.php | 76 ----------- app/Controllers/Front/BoardController.php | 5 +- .../Order}/CardController.php | 13 +- .../Order}/CartController.php | 53 ++++--- .../Order}/DepositController.php | 13 +- .../Front/Order/OrderController.php | 129 ++++++++++++++++++ app/Controllers/Front/OrderController.php | 76 ----------- app/Controllers/Front/ProductController.php | 5 +- app/Controllers/Front/SitepageController.php | 5 +- app/Controllers/Front/UserController.php | 5 +- app/Helpers/Order_helper.php | 4 +- .../payment => front/order}/card/update.php | 0 .../order}/deposit/update.php | 0 app/Views/front/order/index.php | 2 +- 26 files changed, 244 insertions(+), 266 deletions(-) delete mode 100644 app/Controllers/Ecommerce/EcommerceController.php delete mode 100644 app/Controllers/Ecommerce/Payment/PaymentController.php rename app/Controllers/{Ecommerce/Payment => Front/Order}/CardController.php (90%) rename app/Controllers/{Ecommerce => Front/Order}/CartController.php (78%) rename app/Controllers/{Ecommerce/Payment => Front/Order}/DepositController.php (86%) create mode 100644 app/Controllers/Front/Order/OrderController.php delete mode 100644 app/Controllers/Front/OrderController.php rename app/Views/{ecommerce/payment => front/order}/card/update.php (100%) rename app/Views/{ecommerce/payment => front/order}/deposit/update.php (100%) diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 8a30781..8b0ff38 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -152,10 +152,10 @@ define('URLS', [ 'LOGIN' => '/front/user/login', 'SIGNUP' => '/front/user/signup', 'LOGOUT' => '/front/user/logout', - 'addCart' => '/ecommerce/addCart', - 'cancelCart' => '/ecommerce/cancelCart', - 'paymentCard' => '/ecommerce/payment/card', - 'paymentDeposit' => '/ecommerce/payment/deposit', + 'addCart' => '/front/order/addCart', + 'cancelCart' => '/front/order/cancelCart', + 'cardPayment' => '/front/order/cardPayment', + 'depositPayment' => '/front/order/depositPayment', ]); //SESSION 관련 define('SESSION_NAMES', [ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0d51d5f..f11ca07 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -37,16 +37,6 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} $routes->get('/', 'Home::index'); $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); -$routes->group('ecommerce', ['namespace' => 'App\Controllers\Ecommerce'], function ($routes) { - $routes->post('addCart', 'CartController::insert'); - $routes->get('cancelCart', 'CartController::delete'); - $routes->group('payment', ['namespace' => 'App\Controllers\Ecommerce\Payment', 'filter' => 'authFilter:user'], function ($routes) { - $routes->get('card/(:uuid)', 'CardController::update_form/$1'); - $routes->post('card/(:uuid)', 'CardController::update/$1'); - $routes->get('deposit/(:uuid)', 'DepositController::update_form/$1'); - $routes->post('deposit/(:uuid)', 'DepositController::update/$1'); - }); -}); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], static function ($routes) { $routes->get('/', 'Home::index'); @@ -170,9 +160,15 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->get('excel', 'ProductController::excel/$1'); $routes->get('view/(:uuid)', 'ProductController::view/$1'); }); - $routes->group('order', static function ($routes) { + $routes->group('order', ['namespace' => 'App\Controllers\Front\Order'], static function ($routes) { $routes->get('', 'OrderController::index'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); + $routes->post('addCart', 'CartController::insert'); + $routes->get('cancelCart/(:uuid)', 'CartController::delete/$1'); + $routes->get('cardPayment/(:uuid)', 'CardController::update_form/$1', ['filter' => 'authFilter:user']); + $routes->post('cardPayment/(:uuid)', 'CardController::update/$1', ['filter' => 'authFilter:user']); + $routes->get('depositPayment/(:uuid)', 'DepositController::update_form/$1', ['filter' => 'authFilter:user']); + $routes->post('depositPayment/(:uuid)', 'DepositController::update/$1', ['filter' => 'authFilter:user']); }); $routes->group('payment', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:user'], static function ($routes) { $routes->get('', 'PaymentController::index'); diff --git a/app/Config/Routes_Shoppinmall.php b/app/Config/Routes_Shoppinmall.php index 6446f9a..81c7e79 100644 --- a/app/Config/Routes_Shoppinmall.php +++ b/app/Config/Routes_Shoppinmall.php @@ -37,14 +37,6 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} $routes->get('/', 'Home::index'); $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); -$routes->group('ecommerce', ['namespace' => 'App\Controllers'], function ($routes) { - $routes->post('addCart', 'EcommerceController::addCart'); - $routes->get('cancelCart', 'EcommerceController::cancelCart'); - $routes->get('paymentCard/(:uuid)', 'EcommerceController::cardPayment_form/$1', ['filter' => 'authFilter:user']); - $routes->post('paymentCard/(:uuid)', 'EcommerceController::cardPayment/$1', ['filter' => 'authFilter:user']); - $routes->get('depositPayment/(:uuid)', 'EcommerceController::depositPayment_form/$1', ['filter' => 'authFilter:user']); - $routes->post('depositPayment/(:uuid)', 'EcommerceController::depositPayment/$1', ['filter' => 'authFilter:user']); -}); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], static function ($routes) { $routes->get('/', 'Home::index'); @@ -131,6 +123,9 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2'); $routes->post('batchjob', 'OrderController::batchjob`'); }); + $routes->group('payment', static function ($routes) { + $routes->get('', 'PaymentController::index'); + }); }); $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) { $routes->group('user', static function ($routes) { @@ -165,9 +160,15 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->get('excel', 'ProductController::excel/$1'); $routes->get('view/(:uuid)', 'ProductController::view/$1'); }); - $routes->group('order', static function ($routes) { + $routes->group('order', ['namespace' => 'App\Controllers\Front\Order'], static function ($routes) { $routes->get('', 'OrderController::index'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); + $routes->post('addCart', 'CartController::insert'); + $routes->get('cancelCart', 'CartController::delete'); + $routes->get('cardPayment/(:uuid)', 'CardController::update_form/$1', ['filter' => 'authFilter:user']); + $routes->post('cardPayment/(:uuid)', 'CardController::update/$1', ['filter' => 'authFilter:user']); + $routes->get('depositPayment/(:uuid)', 'DepositController::update_form/$1', ['filter' => 'authFilter:user']); + $routes->post('depositPayment/(:uuid)', 'DepositController::update/$1', ['filter' => 'authFilter:user']); }); $routes->group('payment', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:user'], static function ($routes) { $routes->get('', 'PaymentController::index'); diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 84bac6c..43c0535 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -13,10 +13,13 @@ class BoardController extends AdminController use UpDownloadTrait; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new BoardModel(); $this->_viewDatas['className'] = 'Board'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']);; + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Admin/CategoryController.php b/app/Controllers/Admin/CategoryController.php index faa9a1c..664b7ae 100644 --- a/app/Controllers/Admin/CategoryController.php +++ b/app/Controllers/Admin/CategoryController.php @@ -14,10 +14,13 @@ class CategoryController extends AdminController use UpDownloadTrait; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new CategoryModel(); $this->_viewDatas['className'] = 'Category'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Admin/OrderController.php b/app/Controllers/Admin/OrderController.php index bdcac91..d923b57 100644 --- a/app/Controllers/Admin/OrderController.php +++ b/app/Controllers/Admin/OrderController.php @@ -11,10 +11,13 @@ class OrderController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new OrderModel(); $this->_viewDatas['className'] = 'Order'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } final public function getFields(string $action = ""): array diff --git a/app/Controllers/Admin/ProductController.php b/app/Controllers/Admin/ProductController.php index 1af4b93..96065cf 100644 --- a/app/Controllers/Admin/ProductController.php +++ b/app/Controllers/Admin/ProductController.php @@ -13,10 +13,13 @@ class ProductController extends AdminController use UpDownloadTrait; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new ProductModel(); $this->_viewDatas['className'] = 'Product'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Admin/SitepageController.php b/app/Controllers/Admin/SitepageController.php index f3a9875..8e4d287 100644 --- a/app/Controllers/Admin/SitepageController.php +++ b/app/Controllers/Admin/SitepageController.php @@ -11,10 +11,13 @@ class SitepageController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new SitepageModel(); $this->_viewDatas['className'] = 'Sitepage'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index dd08961..f966272 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -11,10 +11,13 @@ class UserController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new UserModel(); $this->_viewDatas['className'] = 'User'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array { diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index f17f90e..a3e89e7 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -11,10 +11,13 @@ class UserSNSController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new UserSNSModel(); $this->_viewDatas['className'] = 'UserSNS'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array { diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index c8174cc..f4d2354 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -60,9 +60,6 @@ abstract class BaseController extends Controller $this->_session = \Config\Services::session(); $this->_viewDatas['layout'] = LAYOUTS['empty']; $this->_viewDatas['session'] = $this->_session; - $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); - $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; - helper($this->_viewDatas['className']); //사용자 기본 Role 지정 $this->_viewDatas[SESSION_NAMES['ISLOGIN']] = false; diff --git a/app/Controllers/Ecommerce/EcommerceController.php b/app/Controllers/Ecommerce/EcommerceController.php deleted file mode 100644 index e03768e..0000000 --- a/app/Controllers/Ecommerce/EcommerceController.php +++ /dev/null @@ -1,41 +0,0 @@ -_session = \Config\Services::session(); - $this->_viewPath = 'ecommerce/'; - $this->_viewDatas['control'] = 'front'; - $this->_viewDatas['layout'] = LAYOUTS['front']; - } - final protected function getUserModel() - { - return $this->_userModel = $this->_userModel ?: new UserModel(); - } - final protected function getOrderModel() - { - return $this->_orderModel = $this->_orderModel ?: new OrderModel(); - } - final protected function getProductModel() - { - return $this->_productModel = $this->_productModel ?: new ProductModel(); - } -} diff --git a/app/Controllers/Ecommerce/Payment/PaymentController.php b/app/Controllers/Ecommerce/Payment/PaymentController.php deleted file mode 100644 index f20335e..0000000 --- a/app/Controllers/Ecommerce/Payment/PaymentController.php +++ /dev/null @@ -1,76 +0,0 @@ -_viewPath .= 'payment/'; - - //Default 회원정보 Category - $this->_category = DEFAULTS['ORDER_CATEGORY']; - $this->_category ?: throw new \Exception("분류를 지정하지 않으셨습니다."); - $this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]); - $this->_viewDatas['parent_category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_viewDatas['category']->getHierarchy_ParentUID()]); - } - - final protected function getCategoryModel() - { - return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel(); - } - - //Update관련 - protected function update_form_process($entity) - { - $entity = parent::update_form_process($entity); - $this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]); - return $entity; - } - final public function update_form($uid) - { - try { - $this->_viewDatas = $this->init(__FUNCTION__); - $entity = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]); - $this->_viewDatas['entity'] = $this->update_form_process($entity); - helper(['form']); - $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - return view($this->_viewPath . '/update', ['viewDatas' => $this->_viewDatas]); - } catch (\Exception $e) { - log_message("error", $e->getMessage()); - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage()); - } - } - - //결제처리 - public function update($uid) - { - $msg = ""; - try { - $this->_viewDatas = $this->init(__FUNCTION__); - $entity = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]); - $this->update_validate($entity); - $entity = $this->update_process($entity); - $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다."; - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - } catch (\Exception $e) { - $msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\n" . $e->getMessage(); - log_message("error", $e->getMessage()); - $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - return redirect()->back()->withInput(); - } finally { - $this->_session->setFlashdata("return_message", $msg); - } - } -} diff --git a/app/Controllers/Front/BoardController.php b/app/Controllers/Front/BoardController.php index fa282c6..e27c3ce 100644 --- a/app/Controllers/Front/BoardController.php +++ b/app/Controllers/Front/BoardController.php @@ -11,10 +11,13 @@ class BoardController extends FrontController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new BoardModel(); $this->_viewDatas['className'] = 'Board'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array { diff --git a/app/Controllers/Ecommerce/Payment/CardController.php b/app/Controllers/Front/Order/CardController.php similarity index 90% rename from app/Controllers/Ecommerce/Payment/CardController.php rename to app/Controllers/Front/Order/CardController.php index d072e71..8db52bf 100644 --- a/app/Controllers/Ecommerce/Payment/CardController.php +++ b/app/Controllers/Front/Order/CardController.php @@ -1,21 +1,22 @@ _model = new OrderModel(); - $this->_viewDatas['className'] = 'Card'; parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['className'] = 'Card'; + $this->_viewPath .= '/' . strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Ecommerce/CartController.php b/app/Controllers/Front/Order/CartController.php similarity index 78% rename from app/Controllers/Ecommerce/CartController.php rename to app/Controllers/Front/Order/CartController.php index 06af23b..ddf7822 100644 --- a/app/Controllers/Ecommerce/CartController.php +++ b/app/Controllers/Front/Order/CartController.php @@ -1,26 +1,39 @@ _viewDatas['className'] = 'Cart'; parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['className'] = 'Cart'; + $this->_viewPath .= '/' . strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } + final protected function getProductModel() + { + return $this->_productModel = $this->_productModel ?: new ProductModel(); + } + + public function getFields(string $action = ""): array { - $fields = ["product_uid", "quantity", "price"]; switch ($action) { + case 'update': + return ["product_uid", "quantity", "price"]; + break; default: - return $fields; + return []; break; } } @@ -30,7 +43,7 @@ class CartController extends EcommerceController case "product_uid": case "quantity": case "price": - $rules = $this->getOrderModel()->getFieldRule($field, $rules, $action); + $rules = $this->_model->getFieldRule($field, $rules, $action); break; default: $rules = parent::getFieldRule($field, $rules, $action); @@ -54,7 +67,7 @@ class CartController extends EcommerceController try { $this->_viewDatas = $this->init(__FUNCTION__); //Transaction 시작 - $this->getOrderModel()->transStart(); + $this->_model->transStart(); //장바구니정보 검증 $this->insert_validate(); //상품정보 가져오기 @@ -71,16 +84,16 @@ class CartController extends EcommerceController // echo var_export($this->_viewDatas['fieldDatas']); // exit; //상품명을 복사해서 구매한 상품명에 넣기 - $this->_viewDatas['fieldDatas'][$this->getOrderModel()->getTitleField()] = $product->getTitle(); + $this->_viewDatas['fieldDatas'][$this->_model->getTitleField()] = $product->getTitle(); //주문추가 - $entity = $this->getOrderModel()->addCart($this->_viewDatas['fieldDatas']); + $entity = $this->_model->addCart($this->_viewDatas['fieldDatas']); //상품재고감소 $product = $this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']); //주문정보 세션에 넣기 $order_uids = $this->_session->get(SESSION_NAMES['CART']) ?: array(); $this->_session->set(SESSION_NAMES['CART'], [...$order_uids, $entity->getPrimaryKey()]); //Transaction Commit - $this->getOrderModel()->transComplete(); + $this->_model->transComplete(); $msg = sprintf( "%s\n 상품명:%s\n 상품갯수:%s개, 구매금액:%s원\n 장바구니에 담았습니다.", $this->_viewDatas['title'], @@ -91,7 +104,7 @@ class CartController extends EcommerceController return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { //Transaction Rollback - $this->getOrderModel()->transRollback(); + $this->_model->transRollback(); log_message("error", $e->getMessage()); $msg = sprintf( "%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s", @@ -110,14 +123,14 @@ class CartController extends EcommerceController $msg = ""; try { //주문정보 가져오기 - $entity = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); //Transaction 시작 - $this->getOrderModel()->transStart(); + $this->_model->transStart(); //주문취소 - if (!$this->getOrderModel()->cancelCart($entity)) { - log_message("error", __FUNCTION__ . "에서 호출:" . $this->getOrderModel()->getLastQuery()); - log_message("error", implode("\n", $this->getOrderModel()->errors())); - throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getOrderModel()->errors(), true)); + if (!$this->_model->cancelCart($entity)) { + log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); + log_message("error", implode("\n", $this->_model->errors())); + throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors(), true)); } //상품정보 가져오기 $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->product_uid]); @@ -133,12 +146,12 @@ class CartController extends EcommerceController } $this->_session->set(SESSION_NAMES['CART'], $temps); //Transaction Commit - $this->getOrderModel()->transComplete(); + $this->_model->transComplete(); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()} {$entity->quantity}개의 주문을 취소하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { //Transaction Rollback - $this->getOrderModel()->transRollback(); + $this->_model->transRollback(); $msg = sprintf( "%s에서 다음 오류로 인해 주문취소를 실패하였습니다.\n%s", $this->_viewDatas['title'], diff --git a/app/Controllers/Ecommerce/Payment/DepositController.php b/app/Controllers/Front/Order/DepositController.php similarity index 86% rename from app/Controllers/Ecommerce/Payment/DepositController.php rename to app/Controllers/Front/Order/DepositController.php index e20ad64..c9da474 100644 --- a/app/Controllers/Ecommerce/Payment/DepositController.php +++ b/app/Controllers/Front/Order/DepositController.php @@ -1,20 +1,21 @@ _model = new OrderModel(); - $this->_viewDatas['className'] = 'Deposit'; parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['className'] = 'Deposit'; + $this->_viewPath .= '/' . strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array diff --git a/app/Controllers/Front/Order/OrderController.php b/app/Controllers/Front/Order/OrderController.php new file mode 100644 index 0000000..f378f2f --- /dev/null +++ b/app/Controllers/Front/Order/OrderController.php @@ -0,0 +1,129 @@ +_model = new OrderModel(); + $this->_viewDatas['className'] = 'Order'; + $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); + + //Default 회원정보 Category + $this->_category = DEFAULTS['ORDER_CATEGORY']; + $this->isRole('index'); + } + + final protected function getUserModel() + { + return $this->_userModel = $this->_userModel ?: new UserModel(); + } + + public function getFields(string $action = ""): array + { + $fields = ["product_uid", "cost", "sale", "quantity", "price", "status"]; + switch ($action) { + case "index": + case "excel": + case "view": + return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"]; + break; + default: + return $fields; + break; + } + } + public function getFieldFilters(): array + { + return ['product_uid', "status"]; + } + public function getFieldBatchFilters(): array + { + return ["status"]; + } + + //Update관련 (결제처리용) + protected function update_form_process($entity) + { + $entity = parent::update_form_process($entity); + $this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]); + return $entity; + } + final public function update_form($uid) + { + try { + $this->_viewDatas = $this->init(__FUNCTION__); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->_viewDatas['entity'] = $this->update_form_process($entity); + helper(['form']); + $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); + return view($this->_viewPath . '/update', ['viewDatas' => $this->_viewDatas]); + } catch (\Exception $e) { + log_message("error", $e->getMessage()); + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage()); + } + } + public function update($uid) + { + $msg = ""; + try { + $this->_viewDatas = $this->init(__FUNCTION__); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->update_validate($entity); + $entity = $this->update_process($entity); + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다."; + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + } catch (\Exception $e) { + $msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\n" . $e->getMessage(); + log_message("error", $e->getMessage()); + $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); + return redirect()->back()->withInput(); + } finally { + $this->_session->setFlashdata("return_message", $msg); + } + } + + //View관련 + protected function view_process($entity) + { + //권한체크 + $this->isRole('view', $entity); + return parent::view_process($entity); + } + + //Index관련 + protected function index_process() + { + //권한체크 + $this->isRole('index'); + return parent::index_process(); + } + protected function index_setCondition() + { + //세션에 Cart정보(order_uids)가 있으면 + $uids = $this->_session->get(SESSION_NAMES['CART']) ?: array('NONE'); + //또는 Login했으면 사용자정보(user_uid)에 맞는 Order정보 가져오기 + if ($this->_session->get(SESSION_NAMES['ISLOGIN'])) { + $this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]); + if (count($uids)) { + $this->_model->orWhereIn('uid', $uids); + } + } elseif (count($uids)) { + $this->_model->whereIn('uid', $uids); + } + parent::index_setCondition(); + } +} diff --git a/app/Controllers/Front/OrderController.php b/app/Controllers/Front/OrderController.php deleted file mode 100644 index 24b2a64..0000000 --- a/app/Controllers/Front/OrderController.php +++ /dev/null @@ -1,76 +0,0 @@ -_model = new OrderModel(); - $this->_viewDatas['className'] = 'Order'; - parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_viewDatas['className']); - //Default 회원정보 Category - $this->_category = DEFAULTS['ORDER_CATEGORY']; - $this->isRole('index'); - } - - final public function getFields(string $action = ""): array - { - $fields = ["product_uid", "cost", "sale", "quantity", "price", "status"]; - switch ($action) { - case "index": - case "excel": - case "view": - return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"]; - break; - default: - return $fields; - break; - } - } - final public function getFieldFilters(): array - { - return ['product_uid', "status"]; - } - final public function getFieldBatchFilters(): array - { - return ["status"]; - } - - //View관련 - protected function view_process($entity) - { - //권한체크 - $this->isRole('view', $entity); - return parent::view_process($entity); - } - - //Index관련 - protected function index_process() - { - //권한체크 - $this->isRole('index'); - return parent::index_process(); - } - protected function index_setCondition() - { - //세션에 Cart정보(order_uids)가 있으면 - $uids = $this->_session->get(SESSION_NAMES['CART']) ?: array('NONE'); - //또는 Login했으면 사용자정보(user_uid)에 맞는 Order정보 가져오기 - if ($this->_session->get(SESSION_NAMES['ISLOGIN'])) { - $this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]); - if (count($uids)) { - $this->_model->orWhereIn('uid', $uids); - } - } elseif (count($uids)) { - $this->_model->whereIn('uid', $uids); - } - parent::index_setCondition(); - } -} diff --git a/app/Controllers/Front/ProductController.php b/app/Controllers/Front/ProductController.php index 7c8ab9c..8818d8c 100644 --- a/app/Controllers/Front/ProductController.php +++ b/app/Controllers/Front/ProductController.php @@ -11,10 +11,13 @@ class ProductController extends FrontController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new ProductModel(); $this->_viewDatas['className'] = 'Product'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array { diff --git a/app/Controllers/Front/SitepageController.php b/app/Controllers/Front/SitepageController.php index 5e3bdee..9dbdd95 100644 --- a/app/Controllers/Front/SitepageController.php +++ b/app/Controllers/Front/SitepageController.php @@ -11,10 +11,13 @@ class SitepageController extends FrontController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new SitepageModel(); $this->_viewDatas['className'] = 'Sitepage'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); } public function getFields(string $action = ""): array { diff --git a/app/Controllers/Front/UserController.php b/app/Controllers/Front/UserController.php index 76647f4..a20b964 100644 --- a/app/Controllers/Front/UserController.php +++ b/app/Controllers/Front/UserController.php @@ -13,10 +13,13 @@ class UserController extends FrontController private $_adapters = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + parent::initController($request, $response, $logger); $this->_model = new UserModel(); $this->_viewDatas['className'] = 'User'; - parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_viewDatas['className']); + $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); + $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; + helper($this->_viewDatas['className']); $this->initAdapters(); //Default 회원정보 Category diff --git a/app/Helpers/Order_helper.php b/app/Helpers/Order_helper.php index cbd7628..e46e9df 100644 --- a/app/Helpers/Order_helper.php +++ b/app/Helpers/Order_helper.php @@ -138,12 +138,12 @@ function getFieldIndex_Row_OrderHelper($field, $entity, array $viewDatas): strin return sprintf( "
%s
%s
", anchor( - URLS['paymentCard'] . '/' . $entity->getPrimaryKey(), + URLS['cardPayment'] . '/' . $entity->getPrimaryKey(), "카 드 결 제", ["class" => "btn btn-sm btn-primary btn-circle", "style" => "color:white", "target" => "_self"] ), anchor( - URLS['paymentDeposit'] . '/' . $entity->getPrimaryKey(), + URLS['depositPayment'] . '/' . $entity->getPrimaryKey(), "무통장입금", ["class" => "btn btn-sm btn-info btn-circle", "style" => "color:white", "target" => "_self"] ) diff --git a/app/Views/ecommerce/payment/card/update.php b/app/Views/front/order/card/update.php similarity index 100% rename from app/Views/ecommerce/payment/card/update.php rename to app/Views/front/order/card/update.php diff --git a/app/Views/ecommerce/payment/deposit/update.php b/app/Views/front/order/deposit/update.php similarity index 100% rename from app/Views/ecommerce/payment/deposit/update.php rename to app/Views/front/order/deposit/update.php diff --git a/app/Views/front/order/index.php b/app/Views/front/order/index.php index d66cffb..af73dfd 100644 --- a/app/Views/front/order/index.php +++ b/app/Views/front/order/index.php @@ -26,7 +26,7 @@ status == DEFAULTS['STATUS']) : ?> - getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> + getPrimaryKey(), ICONS['DELETE'] . '주문취소', ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>