shoppingmallv2 init...
This commit is contained in:
parent
b0f7be463c
commit
adbf052a12
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Backend;
|
||||
|
||||
use App\Models\UserModel;
|
||||
use App\Entities\BaseEntity;
|
||||
use App\Models\UserModel;
|
||||
use CodeIgniter\HTTP\Files\UploadedFile;
|
||||
|
||||
abstract class BaseBackend
|
||||
@ -25,7 +25,7 @@ abstract class BaseBackend
|
||||
}
|
||||
|
||||
//User모델
|
||||
final protected function getUserModel(): UserModel
|
||||
final public function getUserModel(): UserModel
|
||||
{
|
||||
return is_null($this->_userModel) ? new UserModel() : $this->_userModel;
|
||||
}
|
||||
|
||||
16
app/Backend/CartgoryBackend.php
Normal file
16
app/Backend/CartgoryBackend.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Backend;
|
||||
|
||||
use App\Entities\CategoryEntity;
|
||||
use App\Models\CategoryModel;
|
||||
use App\Models\ProductModel;
|
||||
|
||||
class CategoryBackend extends BaseHierarchyBackend
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Category');
|
||||
$this->_model = new CategoryModel();
|
||||
}
|
||||
}
|
||||
78
app/Backend/OrderBackend.php
Normal file
78
app/Backend/OrderBackend.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Backend;
|
||||
|
||||
use App\Entities\OrderEntity;
|
||||
use App\Models\OrderModel;
|
||||
use App\Models\ProductModel;
|
||||
|
||||
class OrderBackend extends BaseBackend
|
||||
{
|
||||
private $_productModel = null;
|
||||
private $_product_uids = array();
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Order');
|
||||
$this->_model = new OrderModel();
|
||||
}
|
||||
|
||||
//Porduct모델
|
||||
final public function getProductModel(): ProductModel
|
||||
{
|
||||
return is_null($this->_productModel) ? new ProductModel() : $this->_productModel;
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
public function getFieldFormOption(string $field): array
|
||||
{
|
||||
switch ($field) {
|
||||
case 'product_uid':
|
||||
$options = $this->_product_uids = $this->_product_uids ?: $this->getProductModel()->getFieldFormOptions([]);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormOption($field);
|
||||
break;
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
//Insert관련 //장바구니에 담기 및 Product 재고 차감
|
||||
public function insert(array $fieldDatas): OrderEntity
|
||||
{
|
||||
//상품정보가져오기
|
||||
$product = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $fieldDatas['product_uid']]);
|
||||
if (!$fieldDatas['quantity']) {
|
||||
throw new \Exception("제품 구매수량을 확인해주세요");
|
||||
}
|
||||
if (!$fieldDatas['price']) {
|
||||
throw new \Exception("제품 구매금액을 확인해주세요");
|
||||
}
|
||||
if ($product->getStock() < $fieldDatas['quantity']) {
|
||||
throw new \Exception(sprintf(
|
||||
"%s의 재고수[%s]보다 많은 수량[%s]을 주문하셨습니다.\\n",
|
||||
$product->getTitle(),
|
||||
$product->getStock(),
|
||||
$fieldDatas['quantity']
|
||||
));
|
||||
}
|
||||
//구매금액 = (판매가-할인가)*구매수량과 맞는지 다시 확인.
|
||||
// $calculated_price = ($product->getPrice() - $product->getSale()) * $quantity;
|
||||
$calculated_price = ($product->getPrice() - $product->getSale()) * $fieldDatas['quantity'];
|
||||
if ($fieldDatas['price'] != $calculated_price) {
|
||||
throw new \Exception(
|
||||
sprintf(
|
||||
"%s상품의 구매금액[%s원]과 판매금액[%s원]이 맞지않습니다.",
|
||||
$product->getTitle(),
|
||||
number_format($fieldDatas['price']),
|
||||
number_format($calculated_price)
|
||||
)
|
||||
);
|
||||
}
|
||||
//상품모델에서 Order에 담은 갯수만큼 재고에서 뺀다.
|
||||
$this->getProductModel()->decreaseStock($product, $fieldDatas['quantity']);
|
||||
return parent::insert($fieldDatas);
|
||||
}
|
||||
}
|
||||
41
app/Backend/ProductBackend.php
Normal file
41
app/Backend/ProductBackend.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Backend;
|
||||
|
||||
use App\Entities\ProductEntity;
|
||||
use App\Models\CategoryModel;
|
||||
use App\Models\ProductModel;
|
||||
|
||||
class ProductBackend extends BaseBackend
|
||||
{
|
||||
private $_categoryModel = null;
|
||||
private $_category_uids = null;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Product');
|
||||
$this->_model = new ProductModel();
|
||||
}
|
||||
|
||||
//Category모델
|
||||
final protected function getCategoryModel(): CategoryModel
|
||||
{
|
||||
return is_null($this->_categoryModel) ? new CategoryModel() : $this->_categoryModel;
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
public function getFieldFormOption(string $field): array
|
||||
{
|
||||
switch ($field) {
|
||||
case 'category_uid':
|
||||
$options = $this->_category_uids = $this->_category_uids ?: $this->getCategoryModel()->getFieldFormOptions(['status' => 'use']);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormOption($field);
|
||||
break;
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@ -91,6 +91,42 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->post('batchjob', 'BoardController::batchjob');
|
||||
$routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2');
|
||||
});
|
||||
$routes->group('category', static function ($routes) {
|
||||
$routes->get('', 'CategoryController::index');
|
||||
$routes->get('excel', 'CategoryController::excel/$1');
|
||||
$routes->get('insert', 'CategoryController::insert_form');
|
||||
$routes->post('insert', 'CategoryController::insert');
|
||||
$routes->get('update/(:num)', 'CategoryController::update_form/$1');
|
||||
$routes->post('update/(:num)', 'CategoryController::update/$1');
|
||||
$routes->get('view/(:num)', 'CategoryController::view/$1');
|
||||
$routes->get('reply/(:num)', 'CategoryController::reply_form/$1');
|
||||
$routes->post('reply/(:num)', 'CategoryController::reply/$1');
|
||||
$routes->get('delete/(:num)', 'CategoryController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'CategoryController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'CategoryController::batchjob');
|
||||
});
|
||||
$routes->group('product', static function ($routes) {
|
||||
$routes->get('', 'ProductController::index');
|
||||
$routes->get('excel', 'ProductController::excel/$1');
|
||||
$routes->get('insert', 'ProductController::insert_form');
|
||||
$routes->post('insert', 'ProductController::insert');
|
||||
$routes->get('update/(:uuid)', 'ProductController::update_form/$1');
|
||||
$routes->post('update/(:uuid)', 'ProductController::update/$1');
|
||||
$routes->get('view/(:uuid)', 'ProductController::view/$1');
|
||||
$routes->get('reply/(:uuid)', 'ProductController::reply_form/$1');
|
||||
$routes->post('reply/(:uuid)', 'ProductController::reply/$1');
|
||||
$routes->get('delete/(:uuid)', 'ProductController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:uuid)/(:hash)', 'ProductController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'ProductController::batchjob');
|
||||
$routes->get('download/(:any)/(:uuid)', 'ProductController::download/$1/$2');
|
||||
});
|
||||
$routes->group('order', static function ($routes) {
|
||||
$routes->get('', 'OrderController::index');
|
||||
$routes->post('insert/(:uuid)', 'OrderController::insert/$1');
|
||||
$routes->get('view/(:uuid)', 'OrderController::view/$1');
|
||||
$routes->post('batchjob', 'OrderController::batchjob`');
|
||||
$routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
});
|
||||
});
|
||||
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
|
||||
$routes->get('/', 'Home::index');
|
||||
|
||||
@ -57,4 +57,25 @@ class Services extends BaseService
|
||||
}
|
||||
return new \App\Backend\BoardConfigBackend();
|
||||
}
|
||||
public static function category($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('category');
|
||||
}
|
||||
return new \App\Backend\CategoryBackend();
|
||||
}
|
||||
public static function prodcut($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('product');
|
||||
}
|
||||
return new \App\Backend\ProductBackend();
|
||||
}
|
||||
public static function order($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('order');
|
||||
}
|
||||
return new \App\Backend\OrderBackend();
|
||||
}
|
||||
}
|
||||
|
||||
81
app/Config/Services_Shoppingmall.php
Normal file
81
app/Config/Services_Shoppingmall.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* Services Configuration file.
|
||||
*
|
||||
* Services are simply other classes/libraries that the system uses
|
||||
* to do its job. This is used by CodeIgniter to allow the core of the
|
||||
* framework to be swapped out easily without affecting the usage within
|
||||
* the rest of your application.
|
||||
*
|
||||
* This file holds any application-specific services, or service overrides
|
||||
* that you might need. An example has been included with the general
|
||||
* method format you should use for your service methods. For more examples,
|
||||
* see the core Services file at system/Config/Services.php.
|
||||
*/
|
||||
class Services extends BaseService
|
||||
{
|
||||
/*
|
||||
* public static function example($getShared = true)
|
||||
* {
|
||||
* if ($getShared) {
|
||||
* return static::getSharedInstance('example');
|
||||
* }
|
||||
*
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
public static function user($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('user');
|
||||
}
|
||||
return new \App\Backend\UserBackend();
|
||||
}
|
||||
public static function usersns($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('usersns');
|
||||
}
|
||||
return new \App\Backend\UserSNSBackend();
|
||||
}
|
||||
public static function board($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('board');
|
||||
}
|
||||
return new \App\Backend\BoardBackend();
|
||||
}
|
||||
public static function boardconfig($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('boardconfig');
|
||||
}
|
||||
return new \App\Backend\BoardConfigBackend();
|
||||
}
|
||||
public static function category($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('category');
|
||||
}
|
||||
return new \App\Backend\CategoryBackend();
|
||||
}
|
||||
public static function prodcut($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('product');
|
||||
}
|
||||
return new \App\Backend\ProductBackend();
|
||||
}
|
||||
public static function order($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('order');
|
||||
}
|
||||
return new \App\Backend\OrderBackend();
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class AdminHierarchyController extends AdminController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
//Reply관련
|
||||
protected function reply_form_process($entity)
|
||||
{
|
||||
return $this->update_form_process($entity);
|
||||
}
|
||||
final public function reply_form($uid)
|
||||
{
|
||||
try {
|
||||
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
||||
$this->_viewDatas['fields'] = $this->_model->getFields('reply');
|
||||
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply');
|
||||
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
|
||||
$this->_viewDatas['entity'] = $this->reply_form_process($entity);
|
||||
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
||||
return view($this->_viewPath . '/update', $this->_viewDatas);
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage());
|
||||
}
|
||||
}
|
||||
protected function reply_validate($entity)
|
||||
{
|
||||
return $this->update_validate($entity);
|
||||
}
|
||||
protected function reply_process($entity)
|
||||
{
|
||||
return $this->_model->reply($entity, $this->_viewDatas['fieldDatas']);
|
||||
}
|
||||
public function reply($uid)
|
||||
{
|
||||
$msg = "";
|
||||
try {
|
||||
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
||||
$this->_viewDatas['fields'] = $this->_model->getFields('reply');
|
||||
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply');
|
||||
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
|
||||
$entity = $this->reply_validate($entity);
|
||||
$entity = $this->reply_process($entity);
|
||||
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다.";
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} catch (\Exception $e) {
|
||||
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
|
||||
log_message("error", $e->getMessage());
|
||||
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
|
||||
return redirect()->back()->withInput();
|
||||
} finally {
|
||||
$this->_session->setFlashdata("return_message", $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,21 +2,16 @@
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Models\CategoryModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CategoryController extends AdminHierarchyController
|
||||
class CategoryController extends AdminController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->_backend = service('category');
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className .= 'Category';
|
||||
$this->_model = new CategoryModel();
|
||||
helper($this->_className);
|
||||
$this->_viewPath .= strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_viewDatas['className'] = $this->_className;
|
||||
$this->_viewPath .= strtolower($this->_backend->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,85 +2,18 @@
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Entities\OrderEntity;
|
||||
use App\Models\OrderModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Models\ProductModel;
|
||||
|
||||
class OrderController extends AdminController
|
||||
{
|
||||
private $_productModel = null;
|
||||
private $_product_uids = array();
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->_backend = service('order');
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className .= 'Order';
|
||||
$this->_model = new OrderModel();
|
||||
helper($this->_className);
|
||||
$this->_viewPath .= strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_viewDatas['className'] = $this->_className;
|
||||
}
|
||||
//Porduct모델
|
||||
final protected function getProductModel(): ProductModel
|
||||
{
|
||||
return is_null($this->_productModel) ? new ProductModel() : $this->_productModel;
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
protected function getFieldFormOption(string $field): array
|
||||
{
|
||||
switch ($field) {
|
||||
case 'product_uid':
|
||||
$options = $this->_product_uids = $this->_product_uids ?: $this->getProductModel()->getFieldFormOptions([]);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormOption($field);
|
||||
break;
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
//구매상품검사
|
||||
protected function insert_process(): OrderEntity
|
||||
{
|
||||
//상품정보가져오기
|
||||
$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("제품 구매금액을 확인해주세요");
|
||||
}
|
||||
if ($product->getStock() < $this->_viewDatas['fieldDatas']['quantity']) {
|
||||
throw new \Exception(sprintf(
|
||||
"%s의 재고수[%s]보다 많은 수량[%s]을 주문하셨습니다.\\n",
|
||||
$product->getTitle(),
|
||||
$product->getStock(),
|
||||
$this->_viewDatas['fieldDatas']['quantity']
|
||||
));
|
||||
}
|
||||
//구매금액 = (판매가-할인가)*구매수량과 맞는지 다시 확인.
|
||||
// $calculated_price = ($product->getPrice() - $product->getSale()) * $quantity;
|
||||
$calculated_price = ($product->getPrice() - $product->getSale()) * $this->_viewDatas['fieldDatas']['quantity'];
|
||||
if ($this->_viewDatas['fieldDatas']['price'] != $calculated_price) {
|
||||
throw new \Exception(
|
||||
sprintf(
|
||||
"%s상품의 구매금액[%s원]과 판매금액[%s원]이 맞지않습니다.",
|
||||
$product->getTitle(),
|
||||
number_format($this->_viewDatas['fieldDatas']['price']),
|
||||
number_format($calculated_price)
|
||||
)
|
||||
);
|
||||
}
|
||||
//상품모델에서 Order에 담은 갯수만큼 재고에서 뺀다.
|
||||
$this->getProductModel()->decreaseStock($product, $this->_viewDatas['fieldDatas']['quantity']);
|
||||
return parent::insert_process();
|
||||
$this->_viewPath .= strtolower($this->_backend->getClassName());
|
||||
}
|
||||
|
||||
//장바구니에 담기
|
||||
@ -88,24 +21,22 @@ class OrderController extends AdminController
|
||||
{
|
||||
$msg = "";
|
||||
try {
|
||||
$this->_viewDatas['fields'] = $this->_model->getFields('insert');
|
||||
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'insert');
|
||||
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
|
||||
$this->insert_validate();
|
||||
$this->_viewDatas = $this->init(__FUNCTION__);
|
||||
//Transaction manully 시작
|
||||
$this->_model->transBegin();
|
||||
$this->_backend->transBegin();
|
||||
$this->insert_process();
|
||||
$entity = $this->_backend->insert($this->_viewDatas['fieldDatas']);
|
||||
//Transaction manully Commit
|
||||
$this->_model->transCommit();
|
||||
$this->_backend->transCommit();
|
||||
$msg = sprintf(
|
||||
"%s에서 상품 %s개를 장바구니에 담았습니다.",
|
||||
"%s에서 %s상품 %s개를 장바구니에 담았습니다.",
|
||||
$this->_viewDatas['title'],
|
||||
$entity->getTtile(),
|
||||
$this->_viewDatas['fieldDatas']['quantity']
|
||||
);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} catch (\Exception $e) {
|
||||
//Transaction manully Rollback
|
||||
$this->_model->transRollback();
|
||||
$this->_backend->transRollback();
|
||||
$msg = sprintf(
|
||||
"%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s",
|
||||
$this->_viewDatas['title'],
|
||||
@ -113,40 +44,17 @@ class OrderController extends AdminController
|
||||
);
|
||||
log_message("error", $e->getMessage());
|
||||
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} finally {
|
||||
$this->_session->setFlashdata("return_message", $msg);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//View관련
|
||||
protected function view_process($entity)
|
||||
{
|
||||
$this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $entity->getUser_uid()]);
|
||||
$this->_viewDatas['product'] = $this->getProductModel()->getEntity([$this->getProductModel()->getPrimaryKey() => $entity->getProduct_uid()]);
|
||||
return $entity;
|
||||
$this->_viewDatas['user'] = $this->_backend->getUserModel()->getEntity([$this->_backend->getUserModel()->getPrimaryKey() => $entity->getUser_uid()]);
|
||||
$this->_viewDatas['product'] = $this->_backend->getProductModel()->getEntity([$this->_backend->getProductModel()->getPrimaryKey() => $entity->getProduct_uid()]);
|
||||
return parent::view_process($entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,48 +2,18 @@
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Models\CategoryModel;
|
||||
use App\Models\ProductModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ProductController extends AdminController
|
||||
{
|
||||
private $_categoryModel = null;
|
||||
private $_category_uids = null;
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->_backend = service('product');
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className .= 'Product';
|
||||
$this->_model = new ProductModel();
|
||||
helper($this->_className);
|
||||
$this->_viewPath .= strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_viewDatas['className'] = $this->_className;
|
||||
}
|
||||
|
||||
//Category모델
|
||||
final protected function getCategoryModel(): CategoryModel
|
||||
{
|
||||
return is_null($this->_categoryModel) ? new CategoryModel() : $this->_categoryModel;
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
protected function getFieldFormOption(string $field): array
|
||||
{
|
||||
switch ($field) {
|
||||
case 'category_uid':
|
||||
$options = $this->_category_uids = $this->_category_uids ?: $this->getCategoryModel()->getFieldFormOptions(['status' => 'use']);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormOption($field);
|
||||
break;
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
||||
}
|
||||
return $options;
|
||||
$this->_viewPath .= strtolower($this->_backend->getClassName());
|
||||
}
|
||||
|
||||
//Field별 Form Datas 처리용
|
||||
|
||||
@ -15,20 +15,24 @@ class CategoryModel extends BaseHierarchyModel
|
||||
$this->allowedFields = [...$this->allowedFields, ...$this->getFields(),];
|
||||
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
|
||||
}
|
||||
public function getTitle(): string
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
public function getContentField(): string
|
||||
{
|
||||
return 'head';
|
||||
}
|
||||
public function getFields(string $action = ""): array
|
||||
{
|
||||
$fields = [$this->getTitle(), "status", "head", "tail",];
|
||||
$fields = [$this->getTitleField(), "status", "head", "tail",];
|
||||
switch ($action) {
|
||||
case "index":
|
||||
case "excel":
|
||||
return [$this->getTitle(), "status", "created_at"];
|
||||
return [$this->getTitleField(), "status", "created_at"];
|
||||
break;
|
||||
case "view":
|
||||
return [$this->getTitle(), "status", "created_at", "head", "tail",];
|
||||
return [$this->getTitleField(), "status", "created_at", "head", "tail",];
|
||||
break;
|
||||
default:
|
||||
return $fields;
|
||||
@ -46,7 +50,7 @@ class CategoryModel extends BaseHierarchyModel
|
||||
protected function getFieldRule(string $field, array $rules, string $action = ""): array
|
||||
{
|
||||
switch ($field) {
|
||||
case $this->getTitle():
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
break;
|
||||
case "head":
|
||||
@ -70,10 +74,10 @@ class CategoryModel extends BaseHierarchyModel
|
||||
$old_title = "";
|
||||
foreach ($this->where($conditions)->orderby("grpno DESC, grporder ASC")->findAll() as $entity) {
|
||||
if ($entity->getPrimaryKey() == $entity->getHierarchy_No()) {
|
||||
$options[$entity->getTitle()] = [];
|
||||
$old_title = $entity->getTitle();
|
||||
$options[$entity->getTitleField()] = [];
|
||||
$old_title = $entity->getTitleField();
|
||||
} else {
|
||||
$options[$old_title][$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
$options[$old_title][$entity->getPrimaryKey()] = $entity->getTitleField();
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
@ -96,7 +100,7 @@ class CategoryModel extends BaseHierarchyModel
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
parent::setIndexWordFilter($word);
|
||||
$this->orLike($this->getTitle(), $word, "both");
|
||||
$this->orLike($this->getTitleField(), $word, "both");
|
||||
$this->orLike("head", $word, "both"); //befor , after , both
|
||||
$this->orLike("tail", $word, "both"); //befor , after , both
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ class OrderModel extends BaseModel
|
||||
$this->allowedFields = ["uid", "user_uid", "sess_id", ...$this->allowedFields, ...$this->getFields(),];
|
||||
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
|
||||
}
|
||||
final public function getTitle(): string
|
||||
final public function getTitleField(): string
|
||||
{
|
||||
return 'product_uid';
|
||||
}
|
||||
|
||||
@ -16,17 +16,17 @@ class ProductModel extends BaseModel
|
||||
$this->allowedFields = ["uid", "user_uid", ...$this->allowedFields, ...$this->getFields(),];
|
||||
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
|
||||
}
|
||||
public function getTitle(): string
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
public function getFields(string $action = ""): array
|
||||
{
|
||||
$fields = ["category_uid", $this->getTitle(), "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "content",];
|
||||
$fields = ["category_uid", $this->getTitleField(), "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "content",];
|
||||
switch ($action) {
|
||||
case "index":
|
||||
case "excel":
|
||||
return ["category_uid", "user_uid", $this->getTitle(), "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "created_at"];
|
||||
return ["category_uid", "user_uid", $this->getTitleField(), "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "created_at"];
|
||||
break;
|
||||
case "view":
|
||||
return [...$fields, "created_at"];
|
||||
@ -53,7 +53,7 @@ class ProductModel extends BaseModel
|
||||
case "user_uid":
|
||||
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
||||
break;
|
||||
case $this->getTitle():
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
break;
|
||||
case 'photo':
|
||||
@ -94,12 +94,12 @@ class ProductModel extends BaseModel
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
parent::setIndexWordFilter($word);
|
||||
$this->orLike($this->getTitle(), $word, "both");
|
||||
$this->orLike($this->getTitleField(), $word, "both");
|
||||
$this->orLike("content", $word, "both"); //befor , after , both
|
||||
}
|
||||
|
||||
//추가Action
|
||||
//View관련 (게시판등의 조회수 증가함수)
|
||||
//장바구니에 넣은 갯수만큼 차감
|
||||
final public function decreaseStock(ProductEntity $entity, int $cnt)
|
||||
{
|
||||
if ($entity->getStock() == $cnt) {
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
<?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="form table table-bordered table-hover table-striped">
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<?= csrf_field() ?>
|
||||
<tr>
|
||||
<td class="label"><?= getFieldLabel_CategoryHelper($field, $fieldRules) ?></td>
|
||||
<td class="column">
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
|
||||
<td>
|
||||
<?= form_checkbox(["id" => "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?>
|
||||
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
|
||||
<?= $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"] ?>
|
||||
</td>
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<td nowrap><?= getFieldIndex_Row_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
|
||||
@ -36,6 +36,7 @@
|
||||
<li class="nav-item"><?= form_checkbox(array("id" => "batchjobuids_checkbox")) ?>ALL</li>
|
||||
<?php foreach ($batchjobFilters as $field) : ?><li class="nav-item"><?= getFieldFilter_OrderHelper($field, DEFAULTS['EMPTY'], $fieldFormOptions) ?></li><?php endforeach; ?>
|
||||
<li class="nav-item"><?= form_submit('', '일괄처리', array("class" => "btn btn-outline btn-warning")); ?></li>
|
||||
<li class="nav-item"><?= anchor(current_url() . '/insert', '입력', ["class" => "btn btn-sm btn-primary btn-circle", "target" => "_self"]) ?></li>
|
||||
</ul>
|
||||
<?= $pagination ?>
|
||||
</div>
|
||||
|
||||
@ -11,15 +11,12 @@
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align:center">
|
||||
<?php if ($entity->getStatus() == DEFAULTS['STATUS']) : ?>
|
||||
<?= $this->include('admin/product/orderform'); ?>
|
||||
<?php else : ?>
|
||||
이제품은 현재[<?= lang('Product.STATUS.' . $entity->getStatus()) ?>]입니다.
|
||||
<?php endif ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
<div style="text-align:center">
|
||||
<?php if ($entity->getStatus() == DEFAULTS['STATUS']) : ?>
|
||||
<?= $this->include('admin/product/orderform'); ?>
|
||||
<?php else : ?>
|
||||
이제품은 현재[<?= lang('Product.STATUS.' . $entity->getStatus()) ?>]입니다.
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
@ -5,5 +5,6 @@
|
||||
<div class="accordion accordion-flush">
|
||||
<?= $this->include($layout['path'] . '/left_menu/base'); ?>
|
||||
<?= $this->include($layout['path'] . '/left_menu/board'); ?>
|
||||
<?= $this->include($layout['path'] . '/left_menu/shoppingmall'); ?>
|
||||
</div>
|
||||
</div>
|
||||
10
app/Views/layouts/admin/left_menu_shoppingmall.php
Normal file
10
app/Views/layouts/admin/left_menu_shoppingmall.php
Normal file
@ -0,0 +1,10 @@
|
||||
<!-- left menu start -->
|
||||
<link href="/css/admin/left_menu.css" media="screen" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="/js/side_menu.js"></script>
|
||||
<div id="left_menu" class="shadow-lg rounded">
|
||||
<div class="accordion accordion-flush">
|
||||
<?= $this->include($layout['path'] . '/left_menu/base'); ?>
|
||||
<?= $this->include($layout['path'] . '/left_menu/board'); ?>
|
||||
<?= $this->include($layout['path'] . '/left_menu/shoppingmall'); ?>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user