diff --git a/app/Controllers/Admin/OrderController.php b/app/Controllers/Admin/OrderController.php index 10fd59a..7c7e9e6 100644 --- a/app/Controllers/Admin/OrderController.php +++ b/app/Controllers/Admin/OrderController.php @@ -21,12 +21,12 @@ class OrderController extends AdminController final public function getFields(string $action = ""): array { - $fields = ['product_uid', "quantity", "price", "status"]; + $fields = ["user_uid", 'product_uid', "quantity", "price", "status"]; switch ($action) { case "index": case "excel": case "view": - return ['product_uid', "user_uid", "quantity", "price", "status", "updated_at", "created_at"]; + return ["user_uid", 'product_uid', "name", "quantity", "price", "status", "updated_at", "created_at"]; break; default: return $fields; @@ -35,7 +35,7 @@ class OrderController extends AdminController } final public function getFieldFilters(): array { - return ['product_uid', "user_uid", "status"]; + return ["user_uid", 'product_uid', "status"]; } final public function getFieldBatchFilters(): array { diff --git a/app/Controllers/Front/OrderController.php b/app/Controllers/Front/OrderController.php index 886d1c8..3323c01 100644 --- a/app/Controllers/Front/OrderController.php +++ b/app/Controllers/Front/OrderController.php @@ -23,12 +23,12 @@ class OrderController extends FrontController final public function getFields(string $action = ""): array { - $fields = ['product_uid', "quantity", "price", "status"]; + $fields = ["product_uid", "quantity", "price", "status"]; switch ($action) { case "index": case "excel": case "view": - return ['product_uid', "quantity", "price", "status", "updated_at", "created_at"]; + return ['name', "quantity", "price", "status", "updated_at", "created_at"]; break; default: return $fields; @@ -44,6 +44,7 @@ class OrderController extends FrontController return ["status"]; } + //Insert관련 (주문) //세션에 장바구니에 담긴 Order UID를 추가해준다. private function setCart(OrderEntity $entity) { @@ -62,9 +63,11 @@ class OrderController extends FrontController } //상품재고 줄이기,Order(장바구니)에넣기,Order(장바구니)번호 세션넣기 $this->_productModel->decreaseStock($product, $this->_viewDatas['fieldDatas']['quantity']); + //상품명을 복사해서 구매한 상품명에 넣기 + $this->_viewDatas['fieldDatas'][$this->_model->getTitleField()] = $product->getTitle(); //장바구니에 넣기 $entity = parent::insert_process(); - //Cart세션정의 + //장바구니 세션정의 $this->setCart($entity); return $entity; } @@ -100,6 +103,34 @@ class OrderController extends FrontController } } + //Delete 관련 (주문취소) + protected function delete_process($entity) + { + if (!$this->_model->delete($entity->getPrimaryKey())) { + 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)); + } + return $entity; + } + public function delete($uid) + { + $msg = ""; + try { + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->delete_process($entity); + $msg = "{$this->_viewDatas['title']}에서 해당 상품 {$entity->quantity}개를 완료하였습니다."; + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); + } catch (\Exception $e) { + $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); + log_message("error", $e->getMessage()); + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); + } finally { + $this->_session->setFlashdata("return_message", $msg); + } + } + + //Index관련 protected function index_setCondition() { parent::index_setCondition(); diff --git a/app/Database/shoppingmall.sql b/app/Database/shoppingmall.sql index 87c6641..852d9a9 100644 --- a/app/Database/shoppingmall.sql +++ b/app/Database/shoppingmall.sql @@ -46,6 +46,7 @@ CREATE TABLE shoppingmall.tw_order ( uid varchar(36) NOT NULL, product_uid varchar(36) NULL COMMENT '상품 정보', user_uid varchar(36) NULL COMMENT '사용자 정보', + name 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: 사용않함 등등', diff --git a/app/Entities/OrderEntity.php b/app/Entities/OrderEntity.php index 9b419e9..57a855b 100644 --- a/app/Entities/OrderEntity.php +++ b/app/Entities/OrderEntity.php @@ -16,7 +16,7 @@ class OrderEntity extends BaseEntity } final public function getTitle(): string { - return $this->attributes['product_uid']; + return $this->attributes['name']; } final public function getStatus(): string { diff --git a/app/Helpers/BoardConfig_helper.php b/app/Helpers/BoardConfig_helper.php index 28980d1..38f7c02 100644 --- a/app/Helpers/BoardConfig_helper.php +++ b/app/Helpers/BoardConfig_helper.php @@ -108,11 +108,20 @@ function getFieldIndex_Row_BoardConfigHelper($field, $entity, array $fieldFilter { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_BoardConfigHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/Board_helper.php b/app/Helpers/Board_helper.php index f788d01..a8fe607 100644 --- a/app/Helpers/Board_helper.php +++ b/app/Helpers/Board_helper.php @@ -125,11 +125,20 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $fieldFilters, $fi { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_BoardHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_BoardHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/Category_helper.php b/app/Helpers/Category_helper.php index 685d53e..b8b90a1 100644 --- a/app/Helpers/Category_helper.php +++ b/app/Helpers/Category_helper.php @@ -117,11 +117,20 @@ function getFieldIndex_Row_CategoryHelper($field, $entity, array $fieldFilters, { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_CategoryHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_CategoryHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_CategoryHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_CategoryHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_CategoryHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/Order_helper.php b/app/Helpers/Order_helper.php index 081a155..c35e853 100644 --- a/app/Helpers/Order_helper.php +++ b/app/Helpers/Order_helper.php @@ -92,4 +92,17 @@ function getFieldIndex_Row_OrderHelper($field, $entity, array $fieldFilters, $fi return getFieldView_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_OrderHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_OrderHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_OrderHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/Product_helper.php b/app/Helpers/Product_helper.php index bb3e42e..a55d0d6 100644 --- a/app/Helpers/Product_helper.php +++ b/app/Helpers/Product_helper.php @@ -129,11 +129,20 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $fieldFilters, $ { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_ProductHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_ProductHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_ProductHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_ProductHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/UserSNS_helper.php b/app/Helpers/UserSNS_helper.php index e60418d..801e8aa 100644 --- a/app/Helpers/UserSNS_helper.php +++ b/app/Helpers/UserSNS_helper.php @@ -98,11 +98,20 @@ function getFieldIndex_Row_UserSNSHelper($field, $entity, array $fieldFilters, $ { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_UserSNSHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/User_helper.php b/app/Helpers/User_helper.php index 81944f0..17ff344 100644 --- a/app/Helpers/User_helper.php +++ b/app/Helpers/User_helper.php @@ -104,11 +104,20 @@ function getFieldIndex_Row_UserHelper($field, $entity, array $fieldFilters, $fie { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_UserHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_UserHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_UserHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Language/ko/Order.php b/app/Language/ko/Order.php index a53db35..d52d590 100644 --- a/app/Language/ko/Order.php +++ b/app/Language/ko/Order.php @@ -6,11 +6,12 @@ return [ 'product_uid' => "상품정보", 'sess_id' => "세션ID", 'user_uid' => "사용자정보", + 'name' => "상품명", 'quantity' => "수량", 'price' => "구매가", 'status' => "상태", 'updated_at' => "수정일", 'created_at' => "작성일" ], - "STATUS" => ["use" => "장바구니", "unuse" => "주문취소", "confirm" => "주문완료",] + "STATUS" => ["use" => "결제", "unuse" => "주문취소", "confirm" => "주문완료",] ]; diff --git a/app/Models/OrderModel.php b/app/Models/OrderModel.php index 7e29cfa..af7c8a0 100644 --- a/app/Models/OrderModel.php +++ b/app/Models/OrderModel.php @@ -14,19 +14,21 @@ class OrderModel extends BaseModel public function __construct(array $fields = array()) { parent::__construct('Order'); - $this->allowedFields = ["uid", "user_uid", ...$this->allowedFields, ...$fields]; + $this->allowedFields = ["uid", "user_uid", "name", ...$this->allowedFields, ...$fields]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } final public function getTitleField(): string { - return 'product_uid'; + return 'name'; } protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { - case $this->getTitleField(): + case 'product_uid': $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; break; + case $this->getTitleField(): + $rules[$field] = "required|trim|string"; break; case 'quantity': case 'price': diff --git a/app/Views/admin/board/index.php b/app/Views/admin/board/index.php index ddb8991..0e4ec9b 100644 --- a/app/Views/admin/board/index.php +++ b/app/Views/admin/board/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/admin/boardconfig/index.php b/app/Views/admin/boardconfig/index.php index 2b57d5e..3e28890 100644 --- a/app/Views/admin/boardconfig/index.php +++ b/app/Views/admin/boardconfig/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/admin/category/index.php b/app/Views/admin/category/index.php index fb89143..9f35470 100644 --- a/app/Views/admin/category/index.php +++ b/app/Views/admin/category/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/admin/order/index.php b/app/Views/admin/order/index.php index 28fce26..b2bb00d 100644 --- a/app/Views/admin/order/index.php +++ b/app/Views/admin/order/index.php @@ -24,7 +24,7 @@ - + getStatus() == DEFAULTS['STATUS'] ? anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) : "" ?> diff --git a/app/Views/admin/product/index.php b/app/Views/admin/product/index.php index ed92a7a..f4cc3d1 100644 --- a/app/Views/admin/product/index.php +++ b/app/Views/admin/product/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/admin/user/index.php b/app/Views/admin/user/index.php index 5c010e4..57e6a6a 100644 --- a/app/Views/admin/user/index.php +++ b/app/Views/admin/user/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/admin/usersns/index.php b/app/Views/admin/usersns/index.php index c8b232b..b4a08b9 100644 --- a/app/Views/admin/usersns/index.php +++ b/app/Views/admin/usersns/index.php @@ -24,7 +24,7 @@ getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> - + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/front/order/index.php b/app/Views/front/order/index.php index 8f710a0..59ca100 100644 --- a/app/Views/front/order/index.php +++ b/app/Views/front/order/index.php @@ -13,6 +13,7 @@ 번호 + 작업 @@ -23,6 +24,11 @@ + + getStatus() == DEFAULTS['STATUS']) : ?> + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> + +