shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-09 17:35:32 +09:00
parent 8340e07db0
commit cc4366d6ab
14 changed files with 112 additions and 24 deletions

View File

@ -208,6 +208,7 @@ define('ICONS', [
'EXCEL' => '<img src="/images/common/excel.png"/>', 'EXCEL' => '<img src="/images/common/excel.png"/>',
'HOME' => '<i class="bi bi-house-door-fill"></i>', 'HOME' => '<i class="bi bi-house-door-fill"></i>',
'PLAY' => '<i class="bi bi-play-fill"></i>', 'PLAY' => '<i class="bi bi-play-fill"></i>',
'CART' => '<i class="bi bi-cart4"></i>',
'IMAGE_FILE' => '<i class="bi bi-file-earmark-image"></i>', 'IMAGE_FILE' => '<i class="bi bi-file-earmark-image"></i>',
]); ]);
define('CLASS_ICONS', [ define('CLASS_ICONS', [
@ -217,8 +218,7 @@ define('CLASS_ICONS', [
'SITEPAGE' => '<i class="bi bi-body-text"></i>', 'SITEPAGE' => '<i class="bi bi-body-text"></i>',
'CATEGORY' => '<i class="bi bi-boxes"></i>', 'CATEGORY' => '<i class="bi bi-boxes"></i>',
'PRODUCT' => '<i class="bi bi-box2"></i>', 'PRODUCT' => '<i class="bi bi-box2"></i>',
'CART' => '<i class="bi bi-cart4"></i>', 'ORDER' => '<i class="bi bi-cart4"></i>',
'ORDER' => '<i class="bi bi-clipboard-check"></i>',
'PAYMENT' => '<i class="bi bi-cash-coin"></i>', 'PAYMENT' => '<i class="bi bi-cash-coin"></i>',
]); ]);
define('AUDIOS', [ define('AUDIOS', [

View File

@ -120,6 +120,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('order', static function ($routes) { $routes->group('order', static function ($routes) {
$routes->get('', 'OrderController::index'); $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('view/(:uuid)', 'OrderController::view/$1');
$routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2'); $routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2');

View File

@ -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->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('/', '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('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
}); });
$routes->group('ecommerce', ['namespace' => 'App\Controllers'], 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->group('order', static function ($routes) {
$routes->get('', 'OrderController::index'); $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('view/(:uuid)', 'OrderController::view/$1');
$routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2'); $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('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
$routes->group('user', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:user'], static function ($routes) { $routes->group('user', static function ($routes) {
$routes->get('update/(:uuid)', 'UserController::update_form/$1'); $routes->get('', 'UserController::index', ['filter' => 'authFilter:user']);
$routes->post('update/(:uuid)', 'UserController::update/R1'); $routes->get('insert', 'UserController::insert_form');
$routes->get('view/(:uuid)', 'UserController::view/$1'); $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->group('board', static function ($routes) {
$routes->get('', 'BoardController::index'); $routes->get('', 'BoardController::index');

View File

@ -18,15 +18,17 @@ class OrderController extends AdminController
final public function getFields(string $action = ""): array final public function getFields(string $action = ""): array
{ {
$fields = ["user_uid", 'product_uid', "quantity", "price", "status"];
switch ($action) { switch ($action) {
case 'update':
return ['product_uid', "cost", "sale", "quantity", "price", "status"];
break;
case "index": case "index":
case "excel": case "excel":
case "view": 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; break;
default: default:
return $fields; return throw new \Exception("{$action} 해당기능은 없습니다.");
break; break;
} }
} }

View File

@ -21,12 +21,12 @@ class OrderController extends FrontController
final public function getFields(string $action = ""): array final public function getFields(string $action = ""): array
{ {
$fields = ["product_uid", "quantity", "price", "status"]; $fields = ["product_uid", "cost", "sale", "quantity", "price", "status"];
switch ($action) { switch ($action) {
case "index": case "index":
case "excel": case "excel":
case "view": case "view":
return ['name', "quantity", "price", "status", "updated_at", "created_at"]; return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"];
break; break;
default: default:
return $fields; return $fields;

View File

@ -122,8 +122,8 @@ CREATE TABLE shoppingmall.tw_product (
name varchar(255) NOT NULL COMMENT '상품명', name varchar(255) NOT NULL COMMENT '상품명',
photo varchar(255) NULL COMMENT '이미지', photo varchar(255) NULL COMMENT '이미지',
cost int(10) UNSIGNED NOT 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 '할인가', sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가',
price int(10) UNSIGNED NOT NULL COMMENT '판매가',
stock int(5) UNSIGNED DEFAULT 1 NULL COMMENT '재고수량', stock int(5) UNSIGNED DEFAULT 1 NULL COMMENT '재고수량',
view_cnt int(4) UNSIGNED DEFAULT 1 NOT NULL DEFAULT 0 COMMENT '조회수', view_cnt int(4) UNSIGNED DEFAULT 1 NOT NULL DEFAULT 0 COMMENT '조회수',
content text NOT NULL COMMENT '상품정보', content text NOT NULL COMMENT '상품정보',
@ -142,8 +142,10 @@ CREATE TABLE shoppingmall.tw_order (
product_uid varchar(36) NULL COMMENT '상품 정보', product_uid varchar(36) NULL COMMENT '상품 정보',
user_uid varchar(36) NULL COMMENT '사용자 정보', user_uid varchar(36) NULL COMMENT '사용자 정보',
name varchar(255) NOT 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 '수량', quantity varchar(255) NOT NULL COMMENT '수량',
price int(10) UNSIGNED NOT NULL COMMENT '구매가',
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 주문대기, unuse: 사용않함 등등', status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 주문대기, unuse: 사용않함 등등',
updated_at timestamp NULL DEFAULT NULL, updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(), created_at timestamp NOT NULL DEFAULT current_timestamp(),

View File

@ -143,7 +143,27 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $viewDatas): strin
//Admin용 //Admin용
function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $viewDatas): string function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $viewDatas): string
{ {
$value = $entity->$field ?: DEFAULTS['EMPTY'];
switch ($field) { 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(
"<div style=\"text-align:left; padding-left:%spx\">%s %s</div>",
$entity->getHierarchy_Depth() * DEFAULTS['HIERARCHY_GRPDEPTH'],
$reply,
$view
);
break;
default: default:
if (in_array($field, $viewDatas['fieldFilters'])) { if (in_array($field, $viewDatas['fieldFilters'])) {
$attributes["onChange"] = sprintf( $attributes["onChange"] = sprintf(

View File

@ -128,7 +128,7 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $viewDatas): str
case 'title': case 'title':
case 'name': case 'name':
return anchor( return anchor(
current_url() . '/view/' . $entity->getPrimaryKey(), current_url() . '/view/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['category']->getPrimaryKey(),
$value ? str_split($value, 66)[0] . "..." : "", $value ? str_split($value, 66)[0] . "..." : "",
["target" => "_self"] ["target" => "_self"]
); );
@ -141,7 +141,16 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $viewDatas): str
//Admin용 //Admin용
function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $viewDatas): string function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $viewDatas): string
{ {
$value = $entity->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case 'title':
case 'name':
return anchor(
current_url() . '/view/' . $entity->getPrimaryKey(),
$value ? str_split($value, 66)[0] . "..." : "",
["target" => "_self"]
);
break;
default: default:
if (in_array($field, $viewDatas['fieldFilters'])) { if (in_array($field, $viewDatas['fieldFilters'])) {
$attributes["onChange"] = sprintf( $attributes["onChange"] = sprintf(

View File

@ -7,8 +7,10 @@ return [
'sess_id' => "세션ID", 'sess_id' => "세션ID",
'user_uid' => "사용자정보", 'user_uid' => "사용자정보",
'name' => "상품명", 'name' => "상품명",
'cost' => "구매원가",
'sale' => "할인가",
'quantity' => "수량", 'quantity' => "수량",
'price' => "구매가", 'price' => "결제금액",
'status' => "상태", 'status' => "상태",
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일" 'created_at' => "작성일"

View File

@ -14,7 +14,7 @@ class OrderModel extends BaseModel
public function __construct() public function __construct()
{ {
parent::__construct('Order'); 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),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
} }
final public function getTitleField(): string final public function getTitleField(): string
@ -30,10 +30,14 @@ class OrderModel extends BaseModel
case $this->getTitleField(): case $this->getTitleField():
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
break; break;
case 'cost':
case 'quantity': case 'quantity':
case 'price': case 'price':
$rules[$field] = "required|numeric"; $rules[$field] = "required|numeric";
break; break;
case 'sale':
$rules[$field] = "if_exist|numeric";
break;
default: default:
$rules = parent::getFieldRule($field, $rules, $action); $rules = parent::getFieldRule($field, $rules, $action);
break; break;
@ -84,7 +88,14 @@ class OrderModel extends BaseModel
//장바구니에 넣기 //장바구니에 넣기
public function addCart(array $formDatas): OrderEntity 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) public function cancelCart(OrderEntity $entity)

View File

@ -45,10 +45,12 @@ class ProductModel extends BaseModel
break; break;
case 'cost': case 'cost':
case 'price': case 'price':
case 'sale':
case 'stock': case 'stock':
$rules[$field] = "required|numeric"; $rules[$field] = "required|numeric";
break; break;
case 'sale':
$rules[$field] = "if_exist|numeric";
break;
case "content": case "content":
$rules[$field] = "required|string"; $rules[$field] = "required|string";
break; break;

View File

@ -0,0 +1,21 @@
<?= $this->extend('layouts/admin') ?>
<?= $this->section('content') ?>
<div class="content">
<?= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
<table class="form table table-bordered table-hover table-striped">
<?php foreach ($viewDatas['fields'] as $field) : ?>
<tr>
<td class="label"><?= getFieldLabel_OrderHelper($field, $viewDatas) ?></td>
<td class="column">
<?= getFieldForm_OrderHelper($field, old($field, $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']), $viewDatas) ?>
<?= validation_show_error($field); ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td valign="bottom" colspan="2"><?= form_submit('', '수정', array("class" => "btn btn-outline btn-primary")); ?></td>
</tr>
</table>
<?= form_close(); ?>
</div>
<?= $this->endSection() ?>

View File

@ -10,6 +10,9 @@
</li> </li>
</ul> </ul>
<ul class="nav justify-content-end"> <ul class="nav justify-content-end">
<li class="cart nav-item">
<?= anchor('/front/order', ICONS['CART'], ["target" => "_self"]); ?>
</li>
<li class="nav-item"> <li class="nav-item">
<?= $this->include($viewDatas['layout']['path'] . '/top_navigator/member_link'); ?> <?= $this->include($viewDatas['layout']['path'] . '/top_navigator/member_link'); ?>
</li> </li>

View File

@ -4,12 +4,22 @@
background-color:#eeeeee background-color:#eeeeee
} }
#top_navigator div.navigator_center span{ #top_navigator ul.justify-content-center div.navigator_center span{
padding-left:5px; padding-left:5px;
padding-right:5px; padding-right:5px;
} }
#top_navigator div.navigator_center span strong{ #top_navigator ul.justify-content-center div.navigator_center span strong{
color:#26417D; color:#26417D;
font-weight: bold; font-weight: bold;
} }
#top_navigator ul.justify-content-center div.navigator_center span strong{
color:#26417D;
font-weight: bold;
}
#top_navigator ul.justify-content-end li.cart a{
font-size:18px;
font-weight: 500;
color:black;
}