diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 988bbc0..0a39373 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -41,7 +41,7 @@ $routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); $routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { $routes->post('addCart', 'CartController::addCart'); - $routes->get('cancelCart', 'CartController::cancelCart'); + $routes->get('cancelCart/(:uuid)', 'CartController::cancelCart/$1'); });; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); diff --git a/app/Config/Routes_Shoppinmall.php b/app/Config/Routes_Shoppinmall.php index 2754026..0a39373 100644 --- a/app/Config/Routes_Shoppinmall.php +++ b/app/Config/Routes_Shoppinmall.php @@ -41,7 +41,7 @@ $routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); $routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { $routes->post('addCart', 'CartController::addCart'); - $routes->get('cancelCart', 'CartController::cancelCart'); + $routes->get('cancelCart/(:uuid)', 'CartController::cancelCart/$1'); });; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); @@ -155,7 +155,7 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->group('order', static function ($routes) { $routes->get('', 'OrderController::index'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); - }); + });; }); /* * -------------------------------------------------------------------- diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 82cd4d2..df390e0 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -499,6 +499,7 @@ abstract class BaseController extends Controller $this->_viewDatas['pagination'] = $this->index_getPagination(); //모델 처리 $this->_viewDatas['entitys'] = $this->index_getEntitys(); + // echo $this->_model->getLastQuery(); // log_message("debug", __METHOD__ . "에서 findAll 호출:" . $this->_model->getLastQuery()); //setting return_url to session flashdata $this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); diff --git a/app/Controllers/CartController.php b/app/Controllers/CartController.php index 47030b2..4ff4c27 100644 --- a/app/Controllers/CartController.php +++ b/app/Controllers/CartController.php @@ -97,8 +97,6 @@ class CartController extends Controller $this->_viewDatas['fieldDatas'][$this->getOrderModel()->getTitleField()] = $product->getTitle(); //주문추가 $entity = $this->getOrderModel()->addCart($this->_viewDatas['fieldDatas']); - echo var_export($entity, true); - exit; //상품재고감소 $this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']); //주문정보 세션에 넣기 @@ -107,10 +105,11 @@ class CartController extends Controller //Transaction Commit $this->getOrderModel()->transComplete(); $msg = sprintf( - "%s에서 %s %s개를 장바구니에 담았습니다.", + "%s\n 상품명:%s\n 상품갯수:%s개, 구매금액:%s원\n 장바구니에 담았습니다.", $this->_viewDatas['title'], $entity->getTitle(), $entity->getQuantity(), + number_format($entity->getPrice()) ); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { @@ -129,7 +128,7 @@ class CartController extends Controller } //주문취소 - public function canelCart($uid) + public function cancelCart($uid) { $msg = ""; try { @@ -138,27 +137,27 @@ class CartController extends Controller //Transaction 시작 $this->getOrderModel()->transStart(); //주문취소 - if (!$this->getOrderModel()->canelCart($entity)) { + 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)); } //상품정보 가져오기 - $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $this->_viewDatas['fieldDatas']['product_uid']]); + $product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->getProduct_uid()]); //상품반환 - $this->getProductModel()->canelCart($product, $entity->getQuantity()); + $this->getProductModel()->cancelCart($product, $entity->getQuantity()); //주문정보 세션에서 빼기 $order_uids = $this->_session->get(SESSION_NAMES['CART']) ?: array(); $temps = array(); foreach ($order_uids as $order_uid) { - if ($order_uid != $entity->uid) { + if ($order_uid != $entity->getPrimaryKey()) { array_push($temps, $order_uid); } } $this->_session->set(SESSION_NAMES['CART'], $temps); //Transaction Commit $this->getOrderModel()->transComplete(); - $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()} {$entity->quantity}개의 주문을 취소하였습니다."; + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()} {$entity->getQuantity()}개의 주문을 취소하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { //Transaction Rollback diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 26b48aa..90f1566 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -252,15 +252,17 @@ abstract class BaseModel extends Model public function setIndexWordFilter(string $word) { } - public function setIndexDateFilterTrit($start, $end) + public function setIndexDateFilter($start, $end) { $this->where("created_at >=", $start); $this->where("created_at <=", $end); } public function setIndexOrderBy(?string $field, ?string $order) { - if (!is_null($field) && !is_null($order)) { + if ($this->useAutoIncrement) { $this->orderBy($field ?: $this->primaryKey, $order ?: "DESC"); + } else { + $this->orderBy($field ?: "created_at", $order ?: "DESC"); } } final public function setCondition(array $filterFields, $word, $start, $end, $order_field, $order_value) diff --git a/app/Models/OrderModel.php b/app/Models/OrderModel.php index b26e89e..3be0822 100644 --- a/app/Models/OrderModel.php +++ b/app/Models/OrderModel.php @@ -85,8 +85,8 @@ class OrderModel extends BaseModel return $this->create_process(new OrderEntity(), $formDatas); } //장바구니에 빼기 - public function canelCart(OrderEntity $entity) + public function cancelCart(OrderEntity $entity) { - return $this->delete(new $entity->getPrimaryKey()); + return $this->delete($entity->getPrimaryKey()); } } diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index c28e3f8..ede4c18 100644 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -6,6 +6,7 @@ use App\Entities\ProductEntity; class ProductModel extends BaseModel { + const STATUS_OUTOFSTOCK = "outofstock"; private $_category_options = null; protected $table = "tw_product"; protected $useAutoIncrement = false; @@ -106,14 +107,18 @@ class ProductModel extends BaseModel final public function addCart(ProductEntity $entity, int $quantity): ProductEntity { if ($entity->getStock() == $quantity) { - $entity->status = "outofstock"; + $entity->status = self::STATUS_OUTOFSTOCK; } $entity->stock -= $quantity; return $this->save_process($entity); } //장바구니에 빼기 - public function canelCart(ProductEntity $entity) + public function cancelCart(ProductEntity $entity, int $quantity) { - return $this->delete(new $entity->getPrimaryKey()); + if ($entity->getStatus() == self::STATUS_OUTOFSTOCK) { + $entity->status = DEFAULTS['STATUS']; + } + $entity->stock += $quantity; + return $this->save_process($entity); } }