From cc4366d6ab547389438d20c3a5dc402915bfc91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Wed, 9 Aug 2023 17:35:32 +0900 Subject: [PATCH] shoppingmallv2 init... --- app/Config/Constants.php | 4 ++-- app/Config/Routes.php | 2 ++ app/Config/Routes_Shoppinmall.php | 20 ++++++++++++-------- app/Controllers/Admin/OrderController.php | 8 +++++--- app/Controllers/Front/OrderController.php | 4 ++-- app/Database/shoppingmall.sql | 6 ++++-- app/Helpers/Board_helper.php | 20 ++++++++++++++++++++ app/Helpers/Product_helper.php | 11 ++++++++++- app/Language/ko/Order.php | 4 +++- app/Models/OrderModel.php | 15 +++++++++++++-- app/Models/ProductModel.php | 4 +++- app/Views/admin/order/update.php | 21 +++++++++++++++++++++ app/Views/layouts/front/top_navigator.php | 3 +++ public/css/front/top_navigator.css | 14 ++++++++++++-- 14 files changed, 112 insertions(+), 24 deletions(-) create mode 100644 app/Views/admin/order/update.php diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 191129d..117d446 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -208,6 +208,7 @@ define('ICONS', [ 'EXCEL' => '', 'HOME' => '', 'PLAY' => '', + 'CART' => '', 'IMAGE_FILE' => '', ]); define('CLASS_ICONS', [ @@ -217,8 +218,7 @@ define('CLASS_ICONS', [ 'SITEPAGE' => '', 'CATEGORY' => '', 'PRODUCT' => '', - 'CART' => '', - 'ORDER' => '', + 'ORDER' => '', 'PAYMENT' => '', ]); define('AUDIOS', [ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4b67d2b..1c89602 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -120,6 +120,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au }); $routes->group('order', static function ($routes) { $routes->get('', 'OrderController::index'); + $routes->get('update/(:uuid)', 'OrderController::update_form/$1'); + $routes->post('update/(:uuid)', 'OrderController::update/$1'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); $routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2'); diff --git a/app/Config/Routes_Shoppinmall.php b/app/Config/Routes_Shoppinmall.php index da230c7..1c89602 100644 --- a/app/Config/Routes_Shoppinmall.php +++ b/app/Config/Routes_Shoppinmall.php @@ -35,10 +35,6 @@ $routes->setAutoRoute(false); $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'); $routes->get('/', 'Home::index'); -$routes->get('/login', 'AuthController::login'); -$routes->post('/signup', 'AuthController::signup/local'); -$routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); -$routes->get('/logout', 'AuthController::logout'); $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); $routes->group('ecommerce', ['namespace' => 'App\Controllers'], function ($routes) { @@ -124,6 +120,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au }); $routes->group('order', static function ($routes) { $routes->get('', 'OrderController::index'); + $routes->get('update/(:uuid)', 'OrderController::update_form/$1'); + $routes->post('update/(:uuid)', 'OrderController::update/$1'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); $routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2'); @@ -131,10 +129,16 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au }); }); $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) { - $routes->group('user', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:user'], static function ($routes) { - $routes->get('update/(:uuid)', 'UserController::update_form/$1'); - $routes->post('update/(:uuid)', 'UserController::update/R1'); - $routes->get('view/(:uuid)', 'UserController::view/$1'); + $routes->group('user', static function ($routes) { + $routes->get('', 'UserController::index', ['filter' => 'authFilter:user']); + $routes->get('insert', 'UserController::insert_form'); + $routes->post('insert', 'UserController::insert'); + $routes->get('update/(:uuid)', 'UserController::update_form/$1', ['filter' => 'authFilter:user']); + $routes->post('update/(:uuid)', 'UserController::update/$1', ['filter' => 'authFilter:user']); + $routes->get('login', 'UserController::login_form'); + $routes->post('login', 'UserController::login/local'); + $routes->get('signup/(:alpha)', 'UserController::login/$1'); + $routes->get('logout', 'UserController::logout', ['filter' => 'authFilter:user']); }); $routes->group('board', static function ($routes) { $routes->get('', 'BoardController::index'); diff --git a/app/Controllers/Admin/OrderController.php b/app/Controllers/Admin/OrderController.php index de45127..305f48e 100644 --- a/app/Controllers/Admin/OrderController.php +++ b/app/Controllers/Admin/OrderController.php @@ -18,15 +18,17 @@ class OrderController extends AdminController final public function getFields(string $action = ""): array { - $fields = ["user_uid", 'product_uid', "quantity", "price", "status"]; switch ($action) { + case 'update': + return ['product_uid', "cost", "sale", "quantity", "price", "status"]; + break; case "index": case "excel": case "view": - return ["user_uid", 'product_uid', "name", "quantity", "price", "status", "updated_at", "created_at"]; + return ["user_uid", 'product_uid', "name", "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"]; break; default: - return $fields; + return throw new \Exception("{$action} 해당기능은 없습니다."); break; } } diff --git a/app/Controllers/Front/OrderController.php b/app/Controllers/Front/OrderController.php index 93c5222..b3edc4d 100644 --- a/app/Controllers/Front/OrderController.php +++ b/app/Controllers/Front/OrderController.php @@ -21,12 +21,12 @@ class OrderController extends FrontController final public function getFields(string $action = ""): array { - $fields = ["product_uid", "quantity", "price", "status"]; + $fields = ["product_uid", "cost", "sale", "quantity", "price", "status"]; switch ($action) { case "index": case "excel": case "view": - return ['name', "quantity", "price", "status", "updated_at", "created_at"]; + return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"]; break; default: return $fields; diff --git a/app/Database/shoppingmall.sql b/app/Database/shoppingmall.sql index b72766a..5555589 100644 --- a/app/Database/shoppingmall.sql +++ b/app/Database/shoppingmall.sql @@ -122,8 +122,8 @@ CREATE TABLE shoppingmall.tw_product ( name varchar(255) NOT NULL COMMENT '상품명', photo varchar(255) NULL COMMENT '이미지', cost int(10) UNSIGNED NOT NULL COMMENT '원가', - price int(10) UNSIGNED NOT NULL COMMENT '판매가', sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가', + price int(10) UNSIGNED NOT NULL COMMENT '판매가', stock int(5) UNSIGNED DEFAULT 1 NULL COMMENT '재고수량', view_cnt int(4) UNSIGNED DEFAULT 1 NOT NULL DEFAULT 0 COMMENT '조회수', content text NOT NULL COMMENT '상품정보', @@ -142,8 +142,10 @@ CREATE TABLE shoppingmall.tw_order ( product_uid varchar(36) NULL COMMENT '상품 정보', user_uid varchar(36) NULL COMMENT '사용자 정보', name varchar(255) NOT NULL COMMENT '상품명', + cost int(10) UNSIGNED NOT NULL COMMENT '구매원가', + sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가', + price int(10) UNSIGNED NOT NULL COMMENT '결제액', quantity varchar(255) NOT NULL COMMENT '수량', - price int(10) UNSIGNED NOT NULL COMMENT '구매가', status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 주문대기, unuse: 사용않함 등등', updated_at timestamp NULL DEFAULT NULL, created_at timestamp NOT NULL DEFAULT current_timestamp(), diff --git a/app/Helpers/Board_helper.php b/app/Helpers/Board_helper.php index 93bd55a..c7a0325 100644 --- a/app/Helpers/Board_helper.php +++ b/app/Helpers/Board_helper.php @@ -143,7 +143,27 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $viewDatas): strin //Admin용 function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $viewDatas): string { + $value = $entity->$field ?: DEFAULTS['EMPTY']; switch ($field) { + case 'title': + case 'name': + $reply = anchor( + current_url() . '/reply/' . $entity->getPrimaryKey(), + ICONS['REPLY'], + ["target" => "_self"] + ); + $view = anchor( + current_url() . '/view/' . $entity->getPrimaryKey(), + $value, + ["target" => "_self"] + ); + return sprintf( + "
%s %s
", + $entity->getHierarchy_Depth() * DEFAULTS['HIERARCHY_GRPDEPTH'], + $reply, + $view + ); + break; default: if (in_array($field, $viewDatas['fieldFilters'])) { $attributes["onChange"] = sprintf( diff --git a/app/Helpers/Product_helper.php b/app/Helpers/Product_helper.php index 83c47d9..aff6c6d 100644 --- a/app/Helpers/Product_helper.php +++ b/app/Helpers/Product_helper.php @@ -128,7 +128,7 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $viewDatas): str case 'title': case 'name': return anchor( - current_url() . '/view/' . $entity->getPrimaryKey(), + current_url() . '/view/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['category']->getPrimaryKey(), $value ? str_split($value, 66)[0] . "..." : "", ["target" => "_self"] ); @@ -141,7 +141,16 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $viewDatas): str //Admin용 function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $viewDatas): string { + $value = $entity->$field ?: DEFAULTS['EMPTY']; switch ($field) { + case 'title': + case 'name': + return anchor( + current_url() . '/view/' . $entity->getPrimaryKey(), + $value ? str_split($value, 66)[0] . "..." : "", + ["target" => "_self"] + ); + break; default: if (in_array($field, $viewDatas['fieldFilters'])) { $attributes["onChange"] = sprintf( diff --git a/app/Language/ko/Order.php b/app/Language/ko/Order.php index ba218d2..0489477 100644 --- a/app/Language/ko/Order.php +++ b/app/Language/ko/Order.php @@ -7,8 +7,10 @@ return [ 'sess_id' => "세션ID", 'user_uid' => "사용자정보", 'name' => "상품명", + 'cost' => "구매원가", + 'sale' => "할인가", 'quantity' => "수량", - 'price' => "구매가", + 'price' => "결제금액", 'status' => "상태", 'updated_at' => "수정일", 'created_at' => "작성일" diff --git a/app/Models/OrderModel.php b/app/Models/OrderModel.php index 9dff072..f989367 100644 --- a/app/Models/OrderModel.php +++ b/app/Models/OrderModel.php @@ -14,7 +14,7 @@ class OrderModel extends BaseModel public function __construct() { parent::__construct('Order'); - $this->allowedFields = [...$this->allowedFields, 'product_uid', "user_uid", "name", "quantity", "price", "status"]; + $this->allowedFields = [...$this->allowedFields, 'product_uid', "user_uid", "name", "cost", "sale", "quantity", "price", "status"]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } final public function getTitleField(): string @@ -30,10 +30,14 @@ class OrderModel extends BaseModel case $this->getTitleField(): $rules[$field] = "required|trim|string"; break; + case 'cost': case 'quantity': case 'price': $rules[$field] = "required|numeric"; break; + case 'sale': + $rules[$field] = "if_exist|numeric"; + break; default: $rules = parent::getFieldRule($field, $rules, $action); break; @@ -84,7 +88,14 @@ class OrderModel extends BaseModel //장바구니에 넣기 public function addCart(array $formDatas): OrderEntity { - return $this->create_process(new OrderEntity(), $formDatas); + $orderFormDatas = [ + $formDatas['product_uid'] = $formDatas['product_uid'], + $formDatas['cost'] = $formDatas['price'], + $formDatas['sale'] = 0, + $formDatas['quantity'] = $formDatas['quantity'], + $formDatas['price'] = ($formDatas['cost'] - $formDatas['sale']) * $formDatas['quantity'], + ]; + return $this->create_process(new OrderEntity(), $orderFormDatas); } //장바구니에 빼기 public function cancelCart(OrderEntity $entity) diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index 0000502..c830cfa 100644 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -45,10 +45,12 @@ class ProductModel extends BaseModel break; case 'cost': case 'price': - case 'sale': case 'stock': $rules[$field] = "required|numeric"; break; + case 'sale': + $rules[$field] = "if_exist|numeric"; + break; case "content": $rules[$field] = "required|string"; break; diff --git a/app/Views/admin/order/update.php b/app/Views/admin/order/update.php new file mode 100644 index 0000000..0381733 --- /dev/null +++ b/app/Views/admin/order/update.php @@ -0,0 +1,21 @@ +extend('layouts/admin') ?> +section('content') ?> +
+ + + + + + + + + + + +
+ $field ?: DEFAULTS['EMPTY']), $viewDatas) ?> + +
"btn btn-outline btn-primary")); ?>
+ +
+endSection() ?> \ No newline at end of file diff --git a/app/Views/layouts/front/top_navigator.php b/app/Views/layouts/front/top_navigator.php index 2fb350a..6e4daba 100644 --- a/app/Views/layouts/front/top_navigator.php +++ b/app/Views/layouts/front/top_navigator.php @@ -10,6 +10,9 @@