diff --git a/app/Controllers/Admin/OrderController.php b/app/Controllers/Admin/OrderController.php
index d923b57..1b0deba 100644
--- a/app/Controllers/Admin/OrderController.php
+++ b/app/Controllers/Admin/OrderController.php
@@ -24,7 +24,7 @@ class OrderController extends AdminController
{
switch ($action) {
case 'update':
- return ['product_uid', "cost", "sale", "quantity", "status"];
+ return ['product_uid', "paymentday", "cost", "sale", "quantity", "status"];
break;
case "index":
case "excel":
@@ -40,7 +40,7 @@ class OrderController extends AdminController
}
final public function getFieldFilters(): array
{
- return ["user_uid", 'product_uid', "status"];
+ return ["user_uid", 'product_uid', "status"];
}
final public function getFieldBatchFilters(): array
{
diff --git a/app/Controllers/Front/Order/CartController.php b/app/Controllers/Front/Order/CartController.php
index 6c5f273..39168ef 100644
--- a/app/Controllers/Front/Order/CartController.php
+++ b/app/Controllers/Front/Order/CartController.php
@@ -2,14 +2,14 @@
namespace App\Controllers\Front\Order;
+use App\Entities\OrderEntity;
+use App\Entities\ProductEntity;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
-use App\Models\ProductModel;
class CartController extends OrderController
{
- private $_productModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@@ -20,17 +20,11 @@ class CartController extends OrderController
helper($this->_viewDatas['className']);
}
- final protected function getProductModel()
- {
- return $this->_productModel = $this->_productModel ?: new ProductModel();
- }
-
-
public function getFields(string $action = ""): array
{
switch ($action) {
case 'insert':
- return ["product_uid", "quantity", "price"];
+ return $this->_product->type == DEFAULTS['STATUS'] ? ["product_uid", "quantity", "price", 'paymentday'] : ["product_uid", "quantity", "price"];
break;
default:
return [];
@@ -47,6 +41,9 @@ class CartController extends OrderController
case 'price':
$rules[$field] = "required|numeric";
break;
+ case 'paymentday':
+ $rules[$field] = $this->_product->type == DEFAULTS['STATUS'] ? "required|numeric" : "if_exist|numeric";
+ break;
default:
$rules = parent::getFieldRule($field, $rules, $action);
break;
@@ -62,53 +59,39 @@ class CartController extends OrderController
return parent::getFieldBatchFilters();
}
- protected function insert_process()
- {
- //addCart용 데이터 재처리 작업
- $orderFormDatas = [];
- $orderFormDatas[$this->_model->getTitleField()] = $this->_viewDatas['fieldDatas'][$this->_model->getTitleField()];
- $orderFormDatas['product_uid'] = $this->_viewDatas['fieldDatas']['product_uid'];
- $orderFormDatas['cost'] = $this->_viewDatas['fieldDatas']['price'];
- $orderFormDatas['sale'] = 0;
- $orderFormDatas['quantity'] = $this->_viewDatas['fieldDatas']['quantity'];
- $orderFormDatas['price'] = $orderFormDatas['cost'] * $orderFormDatas['quantity'];
- $this->_viewDatas['fieldDatas'] = $orderFormDatas;
- // echo var_export($this->_viewDatas['fieldDatas']);
- // exit;
- return parent::insert_process();
- }
-
- //주문(uid->product_uid)
+ //insert관련
public function insert()
{
$msg = "";
try {
+ //상품정보가져오기
+ $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $this->_viewDatas['fieldDatas']['product_uid']]);
$this->_viewDatas = $this->init(__FUNCTION__);
//장바구니정보 검증
$this->insert_validate();
- //상품정보 가져오기
- $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $this->_viewDatas['fieldDatas']['product_uid']]);
//재고수 비교
if ($product->stock < $this->_viewDatas['fieldDatas']['quantity']) {
- throw new \Exception("구매수량이 너무 많습니다.\n구매수량:{$this->_viewDatas['fieldDatas']['quantity']}개, 남은 재고수량:{$product->stock}개");
+ throw new \Exception("구매수량이 너무 많습니다.\n구매수량:{$this->_viewDatas['fieldDatas']['quantity']}개, 남은 재고수량:{$entity->stock}개");
}
//구매 금액 비교
$price = $product->price * $this->_viewDatas['fieldDatas']['quantity'];
if ($price != $this->_viewDatas['fieldDatas']['price']) {
throw new \Exception("실 상품금액{$price} 와 구매금액{$this->_viewDatas['fieldDatas']['price']}이 서로 다릅니다.");
}
- //상품명을 복사해서 구매한 상품명에 넣기
- $this->_viewDatas['fieldDatas'][$this->_model->getTitleField()] = $product->getTitle();
-
+ //결제방식이 월이용권이면 결제일 확인
+ $paymentDay = null;
+ if ($product->category_uid == DEFAULTS['STATUS']) {
+ $paymentDay = $this->request->getVar('paymentday') ?: throw new \Exception("월이용권 상품의 경우는 매월 결제일을 지정해주셔야합니다.");
+ }
//Transaction 시작
$this->_model->transStart();
//주문추가
- $entity = $this->insert_process();
+ $order = $this->_model->addCart($product, $this->_viewDatas['fieldDatas']['quantity'], $paymentDay);
//상품재고감소
- $product = $this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']);
+ $entity = $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()]);
+ $this->_session->set(SESSION_NAMES['CART'], [...$order_uids, $order->getPrimaryKey()]);
//Transaction Commit
$this->_model->transComplete();
$msg = sprintf(
@@ -142,15 +125,15 @@ class CartController extends OrderController
$msg = "";
try {
//주문정보 가져오기
- $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $uid]);
//상품정보 가져오기
- $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->product_uid]);
+ $entity = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->product_uid]);
//Transaction 시작
- $this->_model->transStart();
+ $this->getProductModel()->transStart();
//주문취소
- $entity = $this->_model->modify($entity, ['status' => 'unuse']);
+ $entity = $this->getProductModel()->modify($entity, ['status' => 'unuse']);
//상품반환
- $product = $this->getProductModel()->cancelCart($product, $entity->quantity);
+ $entity = $this->getProductModel()->cancelCart($entity, $entity->quantity);
//주문정보 세션에서 빼기
$order_uids = $this->_session->get(SESSION_NAMES['CART']) ?: array();
$temps = array();
@@ -161,12 +144,12 @@ class CartController extends OrderController
}
$this->_session->set(SESSION_NAMES['CART'], $temps);
//Transaction Commit
- $this->_model->transComplete();
+ $this->getProductModel()->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->_model->transRollback();
+ $this->getProductModel()->transRollback();
$msg = sprintf(
"%s에서 다음 오류로 인해 주문취소를 실패하였습니다.\n%s",
$this->_viewDatas['title'],
diff --git a/app/Controllers/Front/Order/OrderController.php b/app/Controllers/Front/Order/OrderController.php
index ee75ea2..04aa484 100644
--- a/app/Controllers/Front/Order/OrderController.php
+++ b/app/Controllers/Front/Order/OrderController.php
@@ -2,16 +2,19 @@
namespace App\Controllers\Front\Order;
+use App\Controllers\Front\FrontController;
use App\Models\OrderModel;
+use App\Models\ProductModel;
+use App\Models\UserModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
-use App\Controllers\Front\FrontController;
-use App\Models\UserModel;
class OrderController extends FrontController
{
private $_userModel = null;
+ private $_productModel = null;
+ protected $_product = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@@ -31,10 +34,13 @@ class OrderController extends FrontController
{
return $this->_userModel = $this->_userModel ?: new UserModel();
}
+ final protected function getProductModel()
+ {
+ return $this->_productModel = $this->_productModel ?: new ProductModel();
+ }
public function getFields(string $action = ""): array
{
- $fields = ["product_uid", "cost", "sale", "quantity", "price", "status"];
switch ($action) {
case "index":
case "excel":
@@ -44,60 +50,19 @@ class OrderController extends FrontController
return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"];
break;
default:
- return $fields;
+ return [];
break;
}
}
public function getFieldFilters(): array
{
- return ['product_uid', "status"];
+ return ['product_uid', "type", "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)
{
diff --git a/app/Controllers/Front/Order/CardController.php b/app/Controllers/Front/Order/Payment/CardController.php
similarity index 97%
rename from app/Controllers/Front/Order/CardController.php
rename to app/Controllers/Front/Order/Payment/CardController.php
index 8db52bf..8d0df6e 100644
--- a/app/Controllers/Front/Order/CardController.php
+++ b/app/Controllers/Front/Order/Payment/CardController.php
@@ -1,13 +1,13 @@
_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]);
+ return $entity;
+ }
+ final public function update_form($uid)
+ {
+ try {
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $this->_product = $this->getProductModel()->getEntity([$this->_model->getPrimaryKey() => $entity->product_uid]);
+ $this->_viewDatas = $this->init(__FUNCTION__);
+ $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());
+ }
+ }
+ final public function update($uid)
+ {
+ $msg = "";
+ try {
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $this->_product = $this->getProductModel()->getEntity([$this->_model->getPrimaryKey() => $entity->product_uid]);
+ $this->_viewDatas = $this->init(__FUNCTION__);
+ $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/Database/shoppingmall.sql b/app/Database/shoppingmall.sql
index 5142cf0..2804daf 100644
--- a/app/Database/shoppingmall.sql
+++ b/app/Database/shoppingmall.sql
@@ -147,6 +147,7 @@ CREATE TABLE shoppingmall.tw_order (
price int(10) UNSIGNED NOT NULL COMMENT '결제액',
response text NULL COMMENT '결제처리결과',
quantity varchar(255) NOT NULL COMMENT '수량',
+ paymentday int(2) UNSIGNED NULL COMMENT '결제일',
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 결제하기, unuse: 주문취소, deposit:무통장입금, paid:결제완료 등등',
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(),
diff --git a/app/Helpers/Order_helper.php b/app/Helpers/Order_helper.php
index 0f3cdb6..4c0bc96 100644
--- a/app/Helpers/Order_helper.php
+++ b/app/Helpers/Order_helper.php
@@ -69,10 +69,19 @@ function getFieldView_OrderHelper($field, $entity, array $viewDatas)
$value = $entity->$field ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'cost':
- case 'price':
case 'sale':
return number_format(!$value ? 0 : $value) . "원";
break;
+ case 'price':
+ $price = number_format(!$value ? 0 : $value) . "원";
+ $paymentday = $entity->paymentday;
+ return sprintf(
+ "%s:%s
%s",
+ lang("{$viewDatas['className']}.label.paymentday"),
+ $paymentday,
+ $price
+ );
+ break;
case 'stock':
case 'view_cnt':
return number_format(!$value ? 0 : $value);
diff --git a/app/Language/ko/Order.php b/app/Language/ko/Order.php
index a290c5f..9308452 100644
--- a/app/Language/ko/Order.php
+++ b/app/Language/ko/Order.php
@@ -12,10 +12,15 @@ return [
'quantity' => "수량",
'price' => "결제금액",
'response' => "결제처리결과",
+ "paymentday" => "월결제일",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
+ "TYPE" => [
+ "use" => "월이용권",
+ "unuse" => "판매",
+ ],
"STATUS" => [
"use" => "장바구니",
"unuse" => "주문취소",
diff --git a/app/Language/ko/Product.php b/app/Language/ko/Product.php
index db8d0aa..dde3ea9 100644
--- a/app/Language/ko/Product.php
+++ b/app/Language/ko/Product.php
@@ -17,6 +17,10 @@ return [
'updated_at' => "수정일",
'created_at' => "생성일"
],
+ "TYPE" => [
+ "use" => "월이용권",
+ "unuse" => "판매",
+ ],
"STATUS" => [
"use" => "판매중",
"unuse" => "판매일시중지",
diff --git a/app/Models/OrderModel.php b/app/Models/OrderModel.php
index 2ea0827..b4c3941 100644
--- a/app/Models/OrderModel.php
+++ b/app/Models/OrderModel.php
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Entities\OrderEntity;
+use App\Entities\ProductEntity;
class OrderModel extends BaseModel
{
@@ -14,7 +15,11 @@ class OrderModel extends BaseModel
public function __construct()
{
parent::__construct('Order');
- $this->allowedFields = [...$this->allowedFields, 'product_uid', "user_uid", "name", "cost", "sale", "quantity", "price", "response", "status"];
+ $this->allowedFields = [
+ ...$this->allowedFields, 'product_uid', "user_uid",
+ "name", "cost", "sale", "quantity", "price", "response",
+ "paymentday", "status"
+ ];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
final public function getTitleField(): string
@@ -36,6 +41,7 @@ class OrderModel extends BaseModel
$rules[$field] = "required|numeric";
break;
case 'sale':
+ case 'paymentday':
$rules[$field] = "if_exist|numeric";
break;
default:
@@ -84,4 +90,31 @@ class OrderModel extends BaseModel
$this->orLike($this->getTitleField(), $word, "both");
}
}
+
+ //장바구니에 넣기()
+ final public function addCart(ProductEntity $entity, int $quantity, $paymentDay = null): OrderEntity
+ {
+ $formDatas = [];
+ $formDatas['product_uid'] = $entity->getPrimaryKey();
+ //상품명을 복사해서 구매한 상품명에 넣기
+ $formDatas[$this->_model->getTitleField()] = $entity->getTitle();
+ $formDatas['cost'] = $entity->price;
+ $formDatas['sale'] = 0;
+ $formDatas['quantity'] = $quantity;
+ $formDatas['price'] = $formDatas['cost'] * $formDatas['quantity'];
+ if (!is_null($paymentDay)) {
+ $formDatas['paymentday'] = $paymentDay;
+ }
+ return $this->create($formDatas);
+ }
+ //장바구니에 빼기
+ public function cancelCart(OrderEntity $entity)
+ {
+ $formDatas = array();
+ //장바구니인경우에만
+ if ($entity->status == DEFAULTS['STATUS']) {
+ $formDatas['status'] = 'unuse';
+ }
+ return $this->modify($entity, $formDatas);
+ }
}
diff --git a/app/Views/front/product/addCart.php b/app/Views/front/product/addCart.php
deleted file mode 100644
index 2249cba..0000000
--- a/app/Views/front/product/addCart.php
+++ /dev/null
@@ -1,21 +0,0 @@
-= form_open(URLS['addCart'], ['method' => 'post']) ?>
-= form_hidden("product_uid", $viewDatas['entity']->getPrimaryKey()) ?>
-
- "구매수량 선택"];
-for ($i = 1; $i <= $viewDatas['entity']->stock; $i++) {
- $quantityOptions[$i] = $i . "개";
-}
-?>
-구매 수량 : = form_dropdown('quantity', $quantityOptions, 1, ['onChange' => "cal_price(this.options[this.selectedIndex].value)"]); ?>
-구매 금액 : = number_format($viewDatas['entity']->price * 1) ?>원
-= form_submit('', '최소:1 ~ 최대:' . $viewDatas['entity']->stock, array("class" => "btn btn-outline btn-primary")); ?>
-= form_close(); ?>
-
\ No newline at end of file
diff --git a/app/Views/front/product/view.php b/app/Views/front/product/view.php
index 2f55360..a9ddca4 100644
--- a/app/Views/front/product/view.php
+++ b/app/Views/front/product/view.php
@@ -18,7 +18,27 @@