shoppingmallv2 init...
This commit is contained in:
parent
0a968d2815
commit
847c4f9271
@ -175,7 +175,7 @@ define('URLS', [
|
||||
'Order' => '/front/order',
|
||||
'addCart' => '/front/order/addCart',
|
||||
'cancelCart' => '/front/order/cancelCart',
|
||||
'Billing' => '/front/billing',
|
||||
'Billing' => '/front/billing/insert',
|
||||
'cardPayment' => '/front/billing/payment/card',
|
||||
'depositPayment' => '/front/billing/payment/deposit',
|
||||
]);
|
||||
|
||||
@ -585,7 +585,7 @@ abstract class BaseController extends Controller
|
||||
$this->_viewDatas['pagination'] = $this->index_getPagination();
|
||||
//모델 처리
|
||||
$this->_viewDatas['entitys'] = $this->index_getEntitys();
|
||||
// echo $this->_model->getLastQuery();
|
||||
echo $this->_model->getLastQuery();
|
||||
// exit;
|
||||
// log_message("debug", __METHOD__ . "에서 findAll 호출:" . $this->_model->getLastQuery());
|
||||
//setting return_url to session flashdata
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
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;
|
||||
@ -69,6 +67,19 @@ class CartController extends OrderController
|
||||
$this->insert_validate();
|
||||
//상품정보가져오기
|
||||
$product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $this->_viewDatas['fieldDatas']['product_uid']]);
|
||||
//상품갯수확인
|
||||
if (!$this->_viewDatas['fieldDatas']['quantity']) {
|
||||
throw new \Exception("상품갯수가 지정되지 않았습니다.");
|
||||
}
|
||||
//구매금액확인
|
||||
if (!$this->_viewDatas['fieldDatas']['price']) {
|
||||
throw new \Exception("구매금액이 지정되지 않았습니다.");
|
||||
}
|
||||
//결제방식이 월이용권이면 결제일 확인
|
||||
$paymentDay = null;
|
||||
if (in_array($product->category_uid, RENTAL_PRODUCT_CATEGORYS)) {
|
||||
$paymentDay = $this->request->getVar('paymentday') ?: throw new \Exception("월이용권 상품의 경우는 매월 결제일을 지정해주셔야합니다.");
|
||||
}
|
||||
//재고수 비교
|
||||
if ($product->stock < $this->_viewDatas['fieldDatas']['quantity']) {
|
||||
throw new \Exception("구매수량이 너무 많습니다.\n구매수량:{$this->_viewDatas['fieldDatas']['quantity']}개, 남은 재고수량:{$product->stock}개");
|
||||
@ -78,20 +89,15 @@ class CartController extends OrderController
|
||||
if ($price != $this->_viewDatas['fieldDatas']['price']) {
|
||||
throw new \Exception("실 상품금액{$price} 와 구매금액{$this->_viewDatas['fieldDatas']['price']}이 서로 다릅니다.");
|
||||
}
|
||||
//결제방식이 월이용권이면 결제일 확인
|
||||
$paymentDay = null;
|
||||
if (in_array($product->category_uid, RENTAL_PRODUCT_CATEGORYS)) {
|
||||
$paymentDay = $this->request->getVar('paymentday') ?: throw new \Exception("월이용권 상품의 경우는 매월 결제일을 지정해주셔야합니다.");
|
||||
}
|
||||
//Transaction 시작
|
||||
$this->_model->transStart();
|
||||
//주문추가
|
||||
$order = $this->_model->addCart($product, $this->_viewDatas['fieldDatas']['quantity'], $paymentDay);
|
||||
$entity = $this->_model->addCart($product, $this->_viewDatas['fieldDatas']['quantity'], $paymentDay);
|
||||
//상품재고감소
|
||||
$entity = $this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']);
|
||||
$product = $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, $order->getPrimaryKey()]);
|
||||
$this->_session->set(SESSION_NAMES['CART'], [...$order_uids, $entity->getPrimaryKey()]);
|
||||
//Transaction Commit
|
||||
$this->_model->transComplete();
|
||||
$msg = sprintf(
|
||||
@ -125,15 +131,15 @@ class CartController extends OrderController
|
||||
$msg = "";
|
||||
try {
|
||||
//주문정보 가져오기
|
||||
$entity = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $uid]);
|
||||
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
||||
//상품정보 가져오기
|
||||
$entity = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->product_uid]);
|
||||
$product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->product_uid]);
|
||||
//Transaction 시작
|
||||
$this->getProductModel()->transStart();
|
||||
$this->_model->transStart();
|
||||
//주문취소
|
||||
$entity = $this->getProductModel()->modify($entity, ['status' => 'unuse']);
|
||||
$entity = $this->delete_process($entity);
|
||||
//상품반환
|
||||
$entity = $this->getProductModel()->cancelCart($entity, $entity->quantity);
|
||||
$product = $this->getProductModel()->cancelCart($product, $entity->quantity);
|
||||
//주문정보 세션에서 빼기
|
||||
$order_uids = $this->_session->get(SESSION_NAMES['CART']) ?: array();
|
||||
$temps = array();
|
||||
@ -144,12 +150,12 @@ class CartController extends OrderController
|
||||
}
|
||||
$this->_session->set(SESSION_NAMES['CART'], $temps);
|
||||
//Transaction Commit
|
||||
$this->getProductModel()->transComplete();
|
||||
$this->_model->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->getProductModel()->transRollback();
|
||||
$this->_model->transRollback();
|
||||
$msg = sprintf(
|
||||
"%s에서 다음 오류로 인해 주문취소를 실패하였습니다.\n%s",
|
||||
$this->_viewDatas['title'],
|
||||
|
||||
@ -37,7 +37,7 @@ class OrderController extends FrontController
|
||||
switch ($action) {
|
||||
case "index":
|
||||
case "excel":
|
||||
return ['name', "cost", "sale", "quantity", "price", "status", "created_at"];
|
||||
return ['name', "cost", "sale", "quantity", "price"];
|
||||
break;
|
||||
case "view":
|
||||
return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"];
|
||||
|
||||
@ -141,17 +141,6 @@ function getFieldIndex_Row_OrderHelper($field, $entity, array $viewDatas): strin
|
||||
);
|
||||
return sprintf("%s<BR>%s", $uid, $title);
|
||||
break;
|
||||
case 'status':
|
||||
//장바구니인경우
|
||||
if ($value == DEFAULTS['STATUS']) {
|
||||
return anchor(
|
||||
URLS['Billing'] . '/' . $entity->getPrimaryKey(),
|
||||
CLASS_ICONS['BILLING'] . '결제하기',
|
||||
["class" => "btn btn-sm btn-primary btn-circle", "style" => "color:white", "target" => "_self"]
|
||||
);
|
||||
} else {
|
||||
return getFieldView_OrderHelper($field, $entity, $viewDatas);
|
||||
}
|
||||
default:
|
||||
return getFieldView_OrderHelper($field, $entity, $viewDatas);
|
||||
break;
|
||||
|
||||
@ -11,7 +11,6 @@ class OrderModel extends BaseModel
|
||||
protected $table = "tw_order";
|
||||
protected $useAutoIncrement = false;
|
||||
protected $returnType = OrderEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Order');
|
||||
@ -92,19 +91,21 @@ class OrderModel extends BaseModel
|
||||
}
|
||||
|
||||
//장바구니에 넣기()
|
||||
final public function addCart(ProductEntity $entity, int $quantity, $paymentDay = null): OrderEntity
|
||||
final public function addCart(ProductEntity $product, int $quantity, $paymentDay = null): OrderEntity
|
||||
{
|
||||
$formDatas = [];
|
||||
$formDatas['product_uid'] = $entity->getPrimaryKey();
|
||||
$formDatas['product_uid'] = $product->getPrimaryKey();
|
||||
//상품명을 복사해서 구매한 상품명에 넣기
|
||||
$formDatas[$this->getTitleField()] = $entity->getTitle();
|
||||
$formDatas['cost'] = $entity->price;
|
||||
$formDatas[$this->getTitleField()] = $product->getTitle();
|
||||
$formDatas['cost'] = $product->price;
|
||||
$formDatas['sale'] = 0;
|
||||
$formDatas['quantity'] = $quantity;
|
||||
$formDatas['price'] = $formDatas['cost'] * $formDatas['quantity'];
|
||||
if (!is_null($paymentDay)) {
|
||||
$formDatas['paymentday'] = $paymentDay;
|
||||
}
|
||||
// echo var_export($formDatas, true);
|
||||
// exit;
|
||||
return $this->create($formDatas);
|
||||
}
|
||||
//장바구니에 빼기
|
||||
|
||||
@ -1,40 +1,73 @@
|
||||
<?= $this->extend('layouts/front') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<link href="/css/front/content.css" media="screen" rel="stylesheet" type="text/css" />
|
||||
<link href="/css/front/order.css" media="screen" rel="stylesheet" type="text/css" />
|
||||
<div id="content">
|
||||
<div><?= html_entity_decode($viewDatas['category']->head) ?></div>
|
||||
<div class="top">
|
||||
<?= $this->include('templates/front/index_head') ?>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<div class="top"><?= $this->include('templates/front/index_head') ?></div>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<?php foreach ($viewDatas['fields'] as $field) : ?><?= getFieldIndex_Column_OrderHelper($field, $viewDatas) ?><?php endforeach ?>
|
||||
<th>@</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $cnt = 0 ?>
|
||||
<?php $total_price = 0 ?>
|
||||
<?php $total_sale = 0 ?>
|
||||
<?php foreach ($viewDatas['entitys'] as $entity) : ?>
|
||||
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
|
||||
<td nowrap>
|
||||
<?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?>
|
||||
</td>
|
||||
<?php foreach ($viewDatas['fields'] as $field) : ?>
|
||||
<td><?= getFieldIndex_Row_OrderHelper($field, $entity, $viewDatas) ?></td>
|
||||
<?php endforeach ?>
|
||||
<td>
|
||||
<?php if ($entity->status == DEFAULTS['STATUS']) : ?>
|
||||
<?= anchor(URLS['cancelCart'] . '/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $total_price += $entity->price ?>
|
||||
<?php $total_sale += $entity->sale ?>
|
||||
<?php $cnt++ ?>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="order" class="col-2">
|
||||
<?= form_open_multipart(URLS['Billing'], $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
|
||||
<div class="orderbox">
|
||||
<div class="title">결제정보</div>
|
||||
<div class="item">
|
||||
<span class="label">상품수</span>
|
||||
<span class="value"><?= count($viewDatas['entitys']) ?>개</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span class="label">상품금액</span>
|
||||
<span class="value"><?= number_format($total_price) ?>원</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span class="label">할인금액</span>
|
||||
<span class="value"><?= number_format($total_sale) ?>원</span>
|
||||
</div>
|
||||
<div class="total">
|
||||
<span class="label">총결제금액</span>
|
||||
<span class="value"><?= number_format($total_price - $total_sale) ?>원</span>
|
||||
</div>
|
||||
<div class="submit"><?= form_submit('', '결제하기', array("class" => "btn btn-outline btn-primary")); ?></div>
|
||||
</div>
|
||||
<?= form_close(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom"><?= $viewDatas['pagination'] ?></div>
|
||||
<div><?= html_entity_decode($viewDatas['category']->tail) ?></div>
|
||||
</div>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<?php foreach ($viewDatas['fields'] as $field) : ?><?= getFieldIndex_Column_OrderHelper($field, $viewDatas) ?><?php endforeach ?>
|
||||
<th>@</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $cnt = 0 ?>
|
||||
<?php foreach ($viewDatas['entitys'] as $entity) : ?>
|
||||
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
|
||||
<td nowrap>
|
||||
<?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?>
|
||||
</td>
|
||||
<?php foreach ($viewDatas['fields'] as $field) : ?>
|
||||
<td><?= getFieldIndex_Row_OrderHelper($field, $entity, $viewDatas) ?></td>
|
||||
<?php endforeach ?>
|
||||
<td>
|
||||
<?php if ($entity->status == DEFAULTS['STATUS']) : ?>
|
||||
<?= anchor(URLS['cancelCart'] . '/' . $entity->getPrimaryKey(), ICONS['DELETE'] . '주문취소', ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $cnt++ ?>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="bottom"><?= $viewDatas['pagination'] ?></div>
|
||||
<div><?= html_entity_decode($viewDatas['category']->tail) ?></div>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
48
public/css/front/order.css
Normal file
48
public/css/front/order.css
Normal file
@ -0,0 +1,48 @@
|
||||
/* ------------------------------------------------------------
|
||||
* Name : admin.css
|
||||
* Desc : Admin StyleSheet
|
||||
* Created : 2016/9/11 Tri-aBility by Junheum,Choi
|
||||
* Updated :
|
||||
------------------------------------------------------------ */
|
||||
div#order {
|
||||
position:relative;
|
||||
}
|
||||
div#order div.orderbox {
|
||||
position:fixed;
|
||||
width:200px;
|
||||
height:220px;
|
||||
padding:10px;
|
||||
border:1px solid gray;
|
||||
}
|
||||
div#order div.orderbox div.title{
|
||||
font-size:18px;
|
||||
font-weight: 500;
|
||||
padding-bottom:10px;
|
||||
border-bottom:2px solid gray;
|
||||
}
|
||||
|
||||
div#order div.orderbox div.item{
|
||||
padding-bottom:5px;
|
||||
}
|
||||
div#order div.orderbox div.item span.label{
|
||||
color: gray;
|
||||
}
|
||||
div#order div.orderbox div.item span.value{
|
||||
float:right;
|
||||
}
|
||||
div#order div.orderbox div.total{
|
||||
padding-top:10px;
|
||||
border-top:2px solid gray;
|
||||
}
|
||||
div#order div.orderbox div.total span.label{
|
||||
color: gray;
|
||||
}
|
||||
div#order div.orderbox div.total span.value{
|
||||
float:right;
|
||||
font-size:18px;
|
||||
font-weight: 800;
|
||||
}
|
||||
div#order div.orderbox div.submit{
|
||||
text-align:center;
|
||||
padding-top:25px;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user