132 lines
4.9 KiB
PHP
132 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Front\Order;
|
|
|
|
use App\Models\OrderModel;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use App\Controllers\Front\FrontController;
|
|
use App\Models\UserModel;
|
|
|
|
class OrderController extends FrontController
|
|
{
|
|
private $_userModel = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->_model = new OrderModel();
|
|
$this->_viewDatas['className'] = 'Order';
|
|
$this->_viewPath .= strtolower($this->_viewDatas['className']);
|
|
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
|
|
$this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])];
|
|
helper($this->_viewDatas['className']);
|
|
|
|
//Default 회원정보 Category
|
|
$this->_category = DEFAULTS['ORDER_CATEGORY'];
|
|
$this->isRole('index');
|
|
}
|
|
|
|
final protected function getUserModel()
|
|
{
|
|
return $this->_userModel = $this->_userModel ?: new UserModel();
|
|
}
|
|
|
|
public function getFields(string $action = ""): array
|
|
{
|
|
$fields = ["product_uid", "cost", "sale", "quantity", "price", "status"];
|
|
switch ($action) {
|
|
case "index":
|
|
case "excel":
|
|
return ['name', "cost", "sale", "quantity", "price", "status", "created_at"];
|
|
break;
|
|
case "view":
|
|
return ['name', "cost", "sale", "quantity", "price", "status", "updated_at", "created_at"];
|
|
break;
|
|
default:
|
|
return $fields;
|
|
break;
|
|
}
|
|
}
|
|
public function getFieldFilters(): array
|
|
{
|
|
return ['product_uid', "status"];
|
|
}
|
|
public function getFieldBatchFilters(): array
|
|
{
|
|
return ["status"];
|
|
}
|
|
|
|
//Update관련 (결제처리용)
|
|
protected function update_form_process($entity)
|
|
{
|
|
$entity = parent::update_form_process($entity);
|
|
$this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]);
|
|
return $entity;
|
|
}
|
|
final public function update_form($uid)
|
|
{
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
|
$this->_viewDatas['entity'] = $this->update_form_process($entity);
|
|
helper(['form']);
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return view($this->_viewPath . '/update', ['viewDatas' => $this->_viewDatas]);
|
|
} catch (\Exception $e) {
|
|
log_message("error", $e->getMessage());
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage());
|
|
}
|
|
}
|
|
public function update($uid)
|
|
{
|
|
$msg = "";
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
|
$this->update_validate($entity);
|
|
$entity = $this->update_process($entity);
|
|
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다.";
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
} catch (\Exception $e) {
|
|
$msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\n" . $e->getMessage();
|
|
log_message("error", $e->getMessage());
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return redirect()->back()->withInput();
|
|
} finally {
|
|
$this->_session->setFlashdata("return_message", $msg);
|
|
}
|
|
}
|
|
|
|
//View관련
|
|
protected function view_process($entity)
|
|
{
|
|
//권한체크
|
|
$this->isRole('view', $entity);
|
|
return parent::view_process($entity);
|
|
}
|
|
|
|
//Index관련
|
|
protected function index_process()
|
|
{
|
|
//권한체크
|
|
$this->isRole('index');
|
|
return parent::index_process();
|
|
}
|
|
protected function index_setCondition()
|
|
{
|
|
//세션에 Cart정보(order_uids)가 있으면
|
|
$uids = $this->_session->get(SESSION_NAMES['CART']) ?: array('NONE');
|
|
//또는 Login했으면 사용자정보(user_uid)에 맞는 Order정보 가져오기
|
|
if ($this->_session->get(SESSION_NAMES['ISLOGIN'])) {
|
|
$this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
|
|
if (count($uids)) {
|
|
$this->_model->orWhereIn('uid', $uids);
|
|
}
|
|
} elseif (count($uids)) {
|
|
$this->_model->whereIn('uid', $uids);
|
|
}
|
|
parent::index_setCondition();
|
|
}
|
|
}
|