vhost init...2

This commit is contained in:
최준흠 2024-05-08 13:26:52 +09:00
parent 47778e0ee9
commit dd57f23659
3 changed files with 54 additions and 88 deletions

View File

@ -4,7 +4,6 @@ namespace App\Controllers\Front\Billing;
use App\Controllers\Front\FrontController; use App\Controllers\Front\FrontController;
use App\Entities\BillingEntity; use App\Entities\BillingEntity;
use App\Entities\OrderEntity;
use App\Models\BillingModel; use App\Models\BillingModel;
use App\Models\OrderBillingModel; use App\Models\OrderBillingModel;
use App\Models\OrderModel; use App\Models\OrderModel;
@ -15,23 +14,19 @@ use Psr\Log\LoggerInterface;
class BillingController extends FrontController class BillingController extends FrontController
{ {
const DEFAULT_CATEGORY = "billinginfo";
private $_userModel = null; private $_userModel = null;
private $_orderModel = null; private $_orderModel = null;
private $_orderBillingModel = null; private $_orderBillingModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_model = new BillingModel(); $this->_model = new BillingModel();
$this->_viewDatas['className'] = 'Billing'; $this->_viewDatas['className'] = 'Billing';
$this->_viewPath .= strtolower($this->_viewDatas['className']); $this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title'); $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
$this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])]; $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])];
helper($this->_viewDatas['className']); helper($this->_viewDatas['className']);
//Default 회원정보 Category
$this->_category = DEFAULTS['CATEGORY_BILLING'];
$this->isRole('index');
//사용자정보 //사용자정보
$this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]); $this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]);
} }
@ -58,10 +53,10 @@ class BillingController extends FrontController
break; break;
case "index": case "index":
case "excel": case "excel":
return ["title", "price", "email", "phone", "type", "status", "created_at"]; return ["title", "price", "email", "phone", "type", "status", "created_at"];
break; break;
case "view": case "view":
return ["title", "price", "email", "phone", "type", "status", "updated_at", "created_at", 'response']; return ["title", "price", "email", "phone", "type", "status", "updated_at", "created_at", 'response'];
break; break;
default: default:
return []; return [];
@ -77,17 +72,17 @@ class BillingController extends FrontController
return ["status"]; return ["status"];
} }
final protected function getOrdersByBillingEntity(BillingEntity $entity): array //청구서용 Order정보 가져오기
private function getOrdersByBillingEntity(BillingEntity $entity): array
{ {
//청구서 연결 주문정보 가져오기
$orderBillings = $this->getOrderBillingModel()->getEntitys(['billing_uid' => $entity->getPrimaryKey()]); $orderBillings = $this->getOrderBillingModel()->getEntitys(['billing_uid' => $entity->getPrimaryKey()]);
$orders = array(); $orders = array();
foreach ($orderBillings as $orderBilling) { foreach ($orderBillings as $orderBilling) {
array_push( array_push(
$orders, $orders,
$this->getOrderModel()->getEntity( $this->getOrderModel()->getEntity(
[$this->getOrderModel()->getPrimaryKey() => $orderBilling->order_uid] [$this->getOrderModel()->getPrimaryKey() => $orderBilling->order_uid],
) ),
); );
} }
return $orders; return $orders;
@ -99,83 +94,40 @@ class BillingController extends FrontController
parent::insert_form_process(); parent::insert_form_process();
} }
//Insert관련 //청구서처리
private function linkOrderBilling(BillingEntity $entity, array $orders)
{
foreach ($orders as $order) {
$this->getOrderBillingModel()->create([
"billing_uid" => $entity->getPrimaryKey(),
'order_uid' => $order->getPrimaryKey()
]);
$this->getOrderModel()->modify($order, ['status' => DEFAULTS['STATUS']]);
}
}
protected function insert_process() protected function insert_process()
{ {
//title지정하기 //청구서 title지정하기
$this->_viewDatas['fieldDatas']['title'] = date("Y년m월") . " 청구서입니다."; $this->_viewDatas['fieldDatas']['title'] = date("Y년m월") . " 청구서입니다.";
//사용자정보 //청구서용 고객정보지정하기
$this->_viewDatas['fieldDatas']['email'] = $this->_viewDatas['user']->email; $user = $this->getUserModel()->getData($this->_viewDatas['user']);
$this->_viewDatas['fieldDatas']['phone'] = $this->_viewDatas['user']->phone; $this->_viewDatas['fieldDatas']['email'] = $user->getEmail();
return parent::insert_process(); $this->_viewDatas['fieldDatas']['phone'] = $user->getPhone();
} $entity = parent::insert_process();
final public function insert()
{
$msg = "";
try {
$this->_viewDatas = $this->init(__FUNCTION__);
$this->insert_validate();
//주문정보 가져오기
$order_uids = $this->request->getVar('order_uids') ?: throw new \Exception("주문정보가 지정되지 않았습니다.");
$orders = array();
foreach ($order_uids as $order_uid) {
array_push($orders, $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $order_uid]));
}
//Transaction 시작
$this->_model->transStart();
//Billing 생성
$entity = $this->insert_process();
//DB연결용
$this->linkOrderBilling($entity, $orders);
//Transaction Commit
$this->_model->transComplete();
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.";
//기존 return_url 무시
$this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']);
return redirect()->to(URLS['Billing']);
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); //주문정보 가져오기
log_message("error", $e->getMessage()); $order_uids = $this->request->getVar('order_uids') ?: throw new \Exception("주문정보가 지정되지 않았습니다.");
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $orders = array();
return redirect()->back()->withInput(); foreach ($order_uids as $order_uid) {
} finally { $order = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $order_uid]);
$this->_session->setFlashdata("return_message", $msg); $this->getOrderBillingModel()->create([
"billing_uid" => $entity->getPrimaryKey(),
'order_uid' => $order->getPrimaryKey(),
]);
$this->getOrderModel()->modify($order, ['status' => 'status']);
} }
return $entity;
} }
//Update관련 //Update관련
final public function update_form($uid) protected function update_form_process($entity)
{ {
try { //청구서 연결 주문정보 가져오기
$this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity);
//청구서정보 가져오기 if (!count($this->_viewDatas['orders'])) {
$this->_viewDatas['entity'] = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); throw new \Exception("해당하는 주문정보가 없습니다.");
//청구서 연결 주문정보 가져오기
$this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity);
if (!count($this->_viewDatas['orders'])) {
throw new \Exception("해당하는 주문정보가 없습니다.");
}
$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());
} }
return parent::update_form_process($entity);
} }
//View 관련 //View 관련
@ -191,6 +143,12 @@ class BillingController extends FrontController
} }
//Index관련 //Index관련
protected function index_process()
{
//Category 확인
$this->setCategory($this->request->getVar('category') ?: self::DEFAULT_CATEGORY);
parent::index_process();
}
protected function index_setCondition() protected function index_setCondition()
{ {
//사용자정보(user_uid)에 맞는 Biiling정보 가져오기 //사용자정보(user_uid)에 맞는 Biiling정보 가져오기
@ -202,7 +160,7 @@ class BillingController extends FrontController
//메일발송 //메일발송
final protected function sendMail(BillingEntity $entity): bool final protected function sendMail(BillingEntity $entity): bool
{ {
$this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]);
$this->_viewDatas['entity'] = $entity; $this->_viewDatas['entity'] = $entity;
$this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity); $this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity);
@ -211,10 +169,12 @@ class BillingController extends FrontController
$mail->setTo($entity->email); $mail->setTo($entity->email);
$mail->setCC(MALLS['master']); $mail->setCC(MALLS['master']);
$mail->setSubject($entity->getTitle()); $mail->setSubject($entity->getTitle());
$mail->setMessage(view( $mail->setMessage(
$this->_viewPath . '/billing', view(
['viewDatas' => $this->_viewDatas] $this->_viewPath . '/billing',
)); ['viewDatas' => $this->_viewDatas],
),
);
return $mail->send(); return $mail->send();
} }
} }

View File

@ -108,6 +108,12 @@ class UserController extends FrontController
} }
//Index관련 //Index관련
protected function index_process()
{
//Category 확인
$this->setCategory($this->request->getVar('category') ?: self::DEFAULT_CATEGORY);
parent::index_process();
}
//사용자 UID 조건추가 //사용자 UID 조건추가
protected function index_setCondition() protected function index_setCondition()
{ {

View File

@ -11,7 +11,7 @@ div#order {
/* border:1px solid red; */ /* border:1px solid red; */
} }
div#order div.orderbox { div#order div.orderbox {
position:fixed; /* position:fixed; */
width:200px; width:200px;
padding:5px; padding:5px;
border:1px solid gray; border:1px solid gray;