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\Entities\BillingEntity;
use App\Entities\OrderEntity;
use App\Models\BillingModel;
use App\Models\OrderBillingModel;
use App\Models\OrderModel;
@ -15,23 +14,19 @@ use Psr\Log\LoggerInterface;
class BillingController extends FrontController
{
const DEFAULT_CATEGORY = "billinginfo";
private $_userModel = null;
private $_orderModel = null;
private $_orderBillingModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new BillingModel();
$this->_viewDatas['className'] = 'Billing';
$this->_model = new BillingModel();
$this->_viewDatas['className'] = 'Billing';
$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['CATEGORY_BILLING'];
$this->isRole('index');
//사용자정보
$this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]);
}
@ -58,10 +53,10 @@ class BillingController extends FrontController
break;
case "index":
case "excel":
return ["title", "price", "email", "phone", "type", "status", "created_at"];
return ["title", "price", "email", "phone", "type", "status", "created_at"];
break;
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;
default:
return [];
@ -77,17 +72,17 @@ class BillingController extends FrontController
return ["status"];
}
final protected function getOrdersByBillingEntity(BillingEntity $entity): array
//청구서용 Order정보 가져오기
private function getOrdersByBillingEntity(BillingEntity $entity): array
{
//청구서 연결 주문정보 가져오기
$orderBillings = $this->getOrderBillingModel()->getEntitys(['billing_uid' => $entity->getPrimaryKey()]);
$orders = array();
$orders = array();
foreach ($orderBillings as $orderBilling) {
array_push(
$orders,
$this->getOrderModel()->getEntity(
[$this->getOrderModel()->getPrimaryKey() => $orderBilling->order_uid]
)
[$this->getOrderModel()->getPrimaryKey() => $orderBilling->order_uid],
),
);
}
return $orders;
@ -99,83 +94,40 @@ class BillingController extends FrontController
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()
{
//title지정하기
//청구서 title지정하기
$this->_viewDatas['fieldDatas']['title'] = date("Y년m월") . " 청구서입니다.";
//사용자정보
$this->_viewDatas['fieldDatas']['email'] = $this->_viewDatas['user']->email;
$this->_viewDatas['fieldDatas']['phone'] = $this->_viewDatas['user']->phone;
return 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();
//청구서용 고객정보지정하기
$user = $this->getUserModel()->getData($this->_viewDatas['user']);
$this->_viewDatas['fieldDatas']['email'] = $user->getEmail();
$this->_viewDatas['fieldDatas']['phone'] = $user->getPhone();
$entity = parent::insert_process();
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\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);
//주문정보 가져오기
$order_uids = $this->request->getVar('order_uids') ?: throw new \Exception("주문정보가 지정되지 않았습니다.");
$orders = array();
foreach ($order_uids as $order_uid) {
$order = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $order_uid]);
$this->getOrderBillingModel()->create([
"billing_uid" => $entity->getPrimaryKey(),
'order_uid' => $order->getPrimaryKey(),
]);
$this->getOrderModel()->modify($order, ['status' => 'status']);
}
return $entity;
}
//Update관련
final public function update_form($uid)
protected function update_form_process($entity)
{
try {
$this->_viewDatas = $this->init(__FUNCTION__);
//청구서정보 가져오기
$this->_viewDatas['entity'] = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
//청구서 연결 주문정보 가져오기
$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());
//청구서 연결 주문정보 가져오기
$this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity);
if (!count($this->_viewDatas['orders'])) {
throw new \Exception("해당하는 주문정보가 없습니다.");
}
return parent::update_form_process($entity);
}
//View 관련
@ -191,6 +143,12 @@ class BillingController extends FrontController
}
//Index관련
protected function index_process()
{
//Category 확인
$this->setCategory($this->request->getVar('category') ?: self::DEFAULT_CATEGORY);
parent::index_process();
}
protected function index_setCondition()
{
//사용자정보(user_uid)에 맞는 Biiling정보 가져오기
@ -202,7 +160,7 @@ class BillingController extends FrontController
//메일발송
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['orders'] = $this->getOrdersByBillingEntity($entity);
@ -211,10 +169,12 @@ class BillingController extends FrontController
$mail->setTo($entity->email);
$mail->setCC(MALLS['master']);
$mail->setSubject($entity->getTitle());
$mail->setMessage(view(
$this->_viewPath . '/billing',
['viewDatas' => $this->_viewDatas]
));
$mail->setMessage(
view(
$this->_viewPath . '/billing',
['viewDatas' => $this->_viewDatas],
),
);
return $mail->send();
}
}

View File

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

View File

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