shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-14 13:15:33 +09:00
parent 9fae6d801c
commit 430767e7be
6 changed files with 78 additions and 55 deletions

View File

@ -155,8 +155,8 @@ define('URLS', [
'Order' => '/front/order',
'addCart' => '/front/order/addCart',
'cancelCart' => '/front/order/cancelCart',
'cardPayment' => '/front/order/cardPayment',
'depositPayment' => '/front/order/depositPayment',
'cardPayment' => '/front/order/payment/card',
'depositPayment' => '/front/order/payment/deposit',
]);
//SESSION 관련
define('SESSION_NAMES', [
@ -166,7 +166,8 @@ define('SESSION_NAMES', [
'CART' => 'cart'
]);
define('AUTH_FIELDS', ['ID' => 'id', 'TITLE' => 'title', 'ROLE' => 'role']);
//월이용권 상품의 Category번호
define('RENTAL_PRODUCT_CATEGORYS', [5, 8]);
//인증 관련
define('AUTH_ADAPTERS', [
'Local' => [

View File

@ -165,13 +165,12 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
$routes->get('view/(:uuid)', 'OrderController::view/$1');
$routes->post('addCart', 'CartController::insert');
$routes->get('cancelCart/(:uuid)', 'CartController::delete/$1');
$routes->get('cardPayment/(:uuid)', 'CardController::update_form/$1', ['filter' => 'authFilter:user']);
$routes->post('cardPayment/(:uuid)', 'CardController::update/$1', ['filter' => 'authFilter:user']);
$routes->get('depositPayment/(:uuid)', 'DepositController::update_form/$1', ['filter' => 'authFilter:user']);
$routes->post('depositPayment/(:uuid)', 'DepositController::update/$1', ['filter' => 'authFilter:user']);
});
$routes->group('payment', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:user'], static function ($routes) {
$routes->get('', 'PaymentController::index');
$routes->group('payment', ['namespace' => 'App\Controllers\Front\Order\Payment', 'filter' => 'authFilter:user'], static function ($routes) {
$routes->get('card/(:uuid)', 'CardController::update_form/$1');
$routes->post('card/(:uuid)', 'CardController::update/$1');
$routes->get('deposit/(:uuid)', 'DepositController::update_form/$1');
$routes->post('deposit/(:uuid)', 'DepositController::update/$1');
});
});
});
/*

View File

@ -24,7 +24,7 @@ class CartController extends OrderController
{
switch ($action) {
case 'insert':
return $this->_product->type == DEFAULTS['STATUS'] ? ["product_uid", "quantity", "price", 'paymentday'] : ["product_uid", "quantity", "price"];
return ["product_uid", "quantity", "price", 'paymentday'];
break;
default:
return [];
@ -39,10 +39,10 @@ class CartController extends OrderController
break;
case 'quantity':
case 'price':
$rules[$field] = "required|numeric";
$rules[$field] = "required|numeric";
break;
case 'paymentday':
$rules[$field] = $this->_product->type == DEFAULTS['STATUS'] ? "required|numeric" : "if_exist|numeric";
$rules[$field] = "if_exist|numeric";
break;
default:
$rules = parent::getFieldRule($field, $rules, $action);
@ -64,14 +64,14 @@ class CartController extends OrderController
{
$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']}개, 남은 재고수량:{$entity->stock}");
throw new \Exception("구매수량이 너무 많습니다.\n구매수량:{$this->_viewDatas['fieldDatas']['quantity']}개, 남은 재고수량:{$product->stock}");
}
//구매 금액 비교
$price = $product->price * $this->_viewDatas['fieldDatas']['quantity'];
@ -80,7 +80,7 @@ class CartController extends OrderController
}
//결제방식이 월이용권이면 결제일 확인
$paymentDay = null;
if ($product->category_uid == DEFAULTS['STATUS']) {
if (in_array($product->category_uid, RENTAL_PRODUCT_CATEGORYS)) {
$paymentDay = $this->request->getVar('paymentday') ?: throw new \Exception("월이용권 상품의 경우는 매월 결제일을 지정해주셔야합니다.");
}
//Transaction 시작

View File

@ -7,17 +7,13 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
abstract class PaymentController extends OrderController
class PaymentController extends OrderController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
abstract public function getFields(string $action = ""): array;
abstract public function getFieldFilters(): array;
abstract public function getFieldBatchFilters(): array;
//Update관련 (결제처리용)
protected function update_form_process($entity)
{

View File

@ -97,7 +97,7 @@ class OrderModel extends BaseModel
$formDatas = [];
$formDatas['product_uid'] = $entity->getPrimaryKey();
//상품명을 복사해서 구매한 상품명에 넣기
$formDatas[$this->_model->getTitleField()] = $entity->getTitle();
$formDatas[$this->getTitleField()] = $entity->getTitle();
$formDatas['cost'] = $entity->price;
$formDatas['sale'] = 0;
$formDatas['quantity'] = $quantity;

View File

@ -6,43 +6,70 @@
<table class="form table table-bordered table-striped">
<tbody>
<?php foreach ($viewDatas['fields'] as $field) : ?>
<tr></tr>
<td class="label"><?= getFieldLabel_ProductHelper($field, $viewDatas) ?></td>
<td class="column">
<?= getFieldView_ProductHelper($field, $viewDatas['entity'], $viewDatas) ?>
<?= validation_show_error($field); ?>
</td>
<tr>
<td class="label"><?= getFieldLabel_ProductHelper($field, $viewDatas) ?></td>
<td class="column">
<?= getFieldView_ProductHelper($field, $viewDatas['entity'], $viewDatas) ?>
<?= validation_show_error($field); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div style="text-align:center">
<?php if ($viewDatas['entity']->status == DEFAULTS['STATUS']) : ?>
<?= form_open(URLS['addCart'], ['method' => 'post']) ?>
<?= form_hidden("product_uid", $viewDatas['entity']->getPrimaryKey()) ?>
<input type="hidden" id="price" name="price" value="<?= ($viewDatas['entity']->price) * 1 ?>">
<?php
$quantityOptions = [DEFAULTS['EMPTY'] => "구매수량 선택"];
for ($i = 1; $i <= $viewDatas['entity']->stock; $i++) {
$quantityOptions[$i] = $i . "";
}
?>
구매 수량 : <?= form_dropdown('quantity', $quantityOptions, 1, ['onChange' => "cal_price(this.options[this.selectedIndex].value)"]); ?>
구매 금액 : <span id="order_price"><?= number_format($viewDatas['entity']->price * 1) ?></span>원
<?= form_submit('', '최소:1 ~ 최대:' . $viewDatas['entity']->stock, array("class" => "btn btn-outline btn-primary")); ?>
<?= form_close(); ?>
<script>
function cal_price(quantity) {
var price = 0;
price = <?= $viewDatas['entity']->price ?> * quantity;;
document.getElementById('price').value = price;
document.getElementById('order_price').textContent = new Intl.NumberFormat().format(price);
<?php if ($viewDatas['entity']->status == DEFAULTS['STATUS']) : ?>
<?= form_open(URLS['addCart'], ['method' => 'post']) ?>
<?= form_hidden("product_uid", $viewDatas['entity']->getPrimaryKey()) ?>
<input type="hidden" id="price" name="price" value="<?= ($viewDatas['entity']->price) * 1 ?>">
<?php
$quantityOptions = [DEFAULTS['EMPTY'] => "구매수량 선택"];
for ($i = 1; $i <= $viewDatas['entity']->stock; $i++) {
$quantityOptions[$i] = $i . "";
}
?>
<table class="form table table-bordered table-striped" style="width:400px;">
<tr>
<td class=" label" nowrap>구매금액</td>
<td class="column">
<span id="order_price"><?= number_format($viewDatas['entity']->price * 1) ?></span>원
</td>
<td rowspan="3">
<?= form_submit('', '구매하기', array("class" => "btn btn-outline btn-primary")); ?>
</td>
</tr>
<tr>
<td class="label" nowrap>구매수량</td>
<td class="column">
<?= form_dropdown('quantity', $quantityOptions, old('quantity', 1), ['onChange' => "cal_price(this.options[this.selectedIndex].value)"]); ?>
<?= validation_show_error('quantity'); ?>
</td>
</tr>
<?php if (in_array($viewDatas['category']->getPrimaryKey(), RENTAL_PRODUCT_CATEGORYS)) : ?>
<?php $paymentDayOptions = [DEFAULTS['EMPTY'] => "결제일 선택"];
for ($i = 1; $i <= 28; $i++) {
$paymentDayOptions[$i] = "매월 {$i}";
}
</script>
<?php else : ?>
이제품은 현재[<?= lang('Product.STATUS.' . $viewDatas['entity']->status) ?>]입니다.
<?php endif ?>
</div>
?>
<tr>
<td class="label" nowrap>결제일</td>
<td class="column">
<?= form_dropdown('paymentday', $paymentDayOptions, old('paymentday', 25)) ?>
<?= validation_show_error('paymentday'); ?>
</td>
</tr>
<?php endif ?>
</table>
<?= form_close(); ?>
<script>
function cal_price(quantity) {
var price = 0;
price = <?= $viewDatas['entity']->price ?> * quantity;;
document.getElementById('price').value = price;
document.getElementById('order_price').textContent = new Intl.NumberFormat().format(price);
}
</script>
<?php else : ?>
이제품은 현재[<?= lang('Product.STATUS.' . $viewDatas['entity']->status) ?>]입니다.
<?php endif ?>
<div><?= html_entity_decode($viewDatas['category']->tail) ?></div>
</div>
<?= $this->endSection() ?>