shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-02 18:44:28 +09:00
parent fd24fc032b
commit 51095d5c20
7 changed files with 26 additions and 19 deletions

View File

@ -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) {
});

View File

@ -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');
});
});;
});
/*
* --------------------------------------------------------------------

View File

@ -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() ?: "");

View File

@ -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

View File

@ -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)

View File

@ -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());
}
}

View File

@ -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);
}
}