diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d238bea..ad5e020 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -176,10 +176,11 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->group('billing', ['namespace' => 'App\Controllers\Front\Billing', 'filter' => 'authFilter:user'], static function ($routes) { $routes->get('', 'BillingController::index'); $routes->post('', 'BillingController::insert'); - $routes->get('card', 'CardController::insert_form'); - $routes->post('card', 'CardController::insert'); - $routes->get('deposit', 'DepositController::insert_form'); - $routes->post('deposit', 'DepositController::insert'); + $routes->get('view/(:num)', 'BillingController::view/$1'); + $routes->get('card/(:num)', 'CardController::update_form/$1'); + $routes->post('card/(:num)', 'CardController::update/$1'); + $routes->get('deposit/(:num)', 'DepositController::update_form/$1'); + $routes->post('deposit/(:num)', 'DepositController::update/$1'); }); }); /* diff --git a/app/Controllers/Admin/BillingController.php b/app/Controllers/Admin/BillingController.php index 44dad75..1a0e92a 100644 --- a/app/Controllers/Admin/BillingController.php +++ b/app/Controllers/Admin/BillingController.php @@ -20,27 +20,30 @@ class BillingController extends AdminController helper($this->_viewDatas['className']); } - final public function getFields(string $action = ""): array + public function getFields(string $action = ""): array { switch ($action) { + case "insert": + return ["price"]; + break; case "index": case "excel": - return ["email", "phone", "title", "upload_file", "status", "updated_at", "created_at"]; + return ["user_uid", "title", "price", "email", "phone", "status", "updated_at", "created_at"]; break; case "view": - return ["user_uid", 'order_uid', "email", "phone", "title", "upload_file", "status", "updated_at", "created_at", 'response']; + return ["user_uid", "title", "price", "email", "phone", "status", "updated_at", "created_at", 'response']; break; default: return []; break; } } - final public function getFieldFilters(): array + public function getFieldFilters(): array { - return ["user_uid", 'order_uid', "status"]; + return ["user_uid", "status"]; } - final public function getFieldBatchFilters(): array + public function getFieldBatchFilters(): array { - return ["status"]; + return ["user_uid", "status"]; } } diff --git a/app/Controllers/Front/Billing/BillingController.php b/app/Controllers/Front/Billing/BillingController.php index 1f1dc3e..89fc636 100644 --- a/app/Controllers/Front/Billing/BillingController.php +++ b/app/Controllers/Front/Billing/BillingController.php @@ -58,10 +58,10 @@ class BillingController extends FrontController break; case "index": case "excel": - return ["email", "phone", "title", "price", "status", "updated_at", "created_at"]; + return ["title", "price", "email", "phone", "status", "created_at"]; break; case "view": - return ["email", "phone", "title", "price", "status", "updated_at", "created_at", 'response']; + return ["type", "title", "price", "email", "phone", "status", "updated_at", "created_at", 'response']; break; default: return []; @@ -77,6 +77,22 @@ class BillingController extends FrontController return ["status"]; } + final protected function getOrdersByBillingEntity(BillingEntity $entity): array + { + //청구서 연결 주문정보 가져오기 + $orderBillings = $this->getOrderBillingModel()->getEntitys(['billing_uid' => $entity->getPrimaryKey()]); + $orders = array(); + foreach ($orderBillings as $orderBilling) { + array_push( + $orders, + $this->getOrderModel()->getEntity( + [$this->getOrderModel()->getPrimaryKey() => $orderBilling->order_uid] + ) + ); + } + return $orders; + } + //Insert관련 (결제처리용) protected function insert_form_process() { @@ -84,13 +100,14 @@ class BillingController extends FrontController } //Insert관련 - private function linkOrderBilling(BillingEntity $entity, array $order_uids) + private function linkOrderBilling(BillingEntity $entity, array $orders) { - foreach ($order_uids as $order_uid) { + foreach ($orders as $order) { $this->getOrderBillingModel()->create([ "billing_uid" => $entity->getPrimaryKey(), - 'order_uid' => $order_uid + 'order_uid' => $order->getPrimaryKey() ]); + $this->getOrderModel()->modify($order, ['status' => DEFAULTS['STATUS']]); } } protected function insert_process() @@ -110,12 +127,16 @@ class BillingController extends FrontController $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, $order_uids); + $this->linkOrderBilling($entity, $orders); //Transaction Commit $this->_model->transComplete(); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; @@ -135,6 +156,17 @@ class BillingController extends FrontController } } + //View 관련 + protected function view_process($entity) + { + $entity = parent::view_process($entity); + //청구서 연결 주문정보 가져오기 + $this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity); + if (!count($this->_viewDatas['orders'])) { + throw new \Exception("해당하는 주문정보가 없습니다."); + } + return $entity; + } //Index관련 protected function index_setCondition() @@ -146,36 +178,21 @@ class BillingController extends FrontController } //추가기능 - //청구서관련 - final protected function createBilling(OrderEntity $entity, string $subject, string $html, $response = ''): BillingEntity - { - //청구서파일 생성 - $fileName = sprintf("%s_%s", $entity->getPrimaryKey(), date('Y-m-d_Hm') . '.xlsx'); - $writer = $this->spreadSheet($html); - $writer->save(PATHS['BILLING'] . '/' . $fileName); - //메일발송 - $this->sendBilling($this->_viewDatas['fieldDatas']['email'], $subject, $html); - $fieldDatas = [ - 'order_uid' => $entity->getPrimaryKey(), - 'user_uid' => $this->_viewDatas['auth'][AUTH_FIELDS['ID']], - 'email' => $this->_viewDatas['fieldDatas']['email'], - 'phone' => $this->_viewDatas['fieldDatas']['phone'], - 'title' => $subject, - 'content' => $html, - 'upload_file' => sprintf("%s%s%s", $this->_viewDatas['className'] . '.xlsx', DEFAULTS['DELIMITER_FILE'], $fileName), - 'response' => $response, - 'status' => DEFAULTS['STATUS'] - ]; - return $this->_model->create($fieldDatas); - } - final protected function sendBilling($email, string $subject, string $html): bool + final protected function sendMail(BillingEntity $entity): bool { + $this->_viewDatas = $this->init(__FUNCTION__); + $this->_viewDatas['entity'] = $entity; + $this->_viewDatas['orders'] = $this->getOrdersByBillingEntity($entity); + $mail = \Config\Services::email(); $mail->setFrom(MALLS['support'], MALLS['title'], MALLS['master']); - $mail->setTo($email); + $mail->setTo($entity->email); $mail->setCC(MALLS['master']); - $mail->setSubject($subject); - $mail->setMessage($html); + $mail->setSubject($entity->getTitle()); + $mail->setMessage(view( + $this->_viewPath . '/billing', + ['viewDatas' => $this->_viewDatas] + )); return $mail->send(); } } diff --git a/app/Controllers/Front/Billing/DepositController.php b/app/Controllers/Front/Billing/DepositController.php index 57ebf70..ad0ee93 100644 --- a/app/Controllers/Front/Billing/DepositController.php +++ b/app/Controllers/Front/Billing/DepositController.php @@ -1,12 +1,12 @@ _viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => ['price' => $this->_viewDatas['price']]]; - } - public function insert_form() + //Update관련 + public function update_form($uid) { try { $this->_viewDatas = $this->init(__FUNCTION__); - //결제금액 가져오기 - $this->_viewDatas['price'] = $this->request->getVar('price') ?: throw new \Exception("결제금액이 지정되지 않았습니다."); - //주문정보 가져오기 - $order_uids = $this->request->getVar('order_uids') ?: throw new \Exception("주문정보가 지정되지 않았습니다."); - // echo var_export($order_uids, true); - // exit; - $this->_viewDatas['orders'] = $this->getOrderModel()->whereIn($this->getOrderModel()->getPrimaryKey(), $order_uids)->findAll(); + //청구서정보 가져오기 + $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->insert_form_process(); + $this->update_form_process($entity); helper(['form']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - return view($this->_viewPath . '/insert', ['viewDatas' => $this->_viewDatas]); + 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()); @@ -94,16 +77,8 @@ class DepositController extends PaymentController //무통장입금결제처리 protected function update_process($entity) { - //청구서 발행정보 - $this->_viewDatas['entity'] = $entity; - $subject = sprintf("%s %s 청구서입니다.", $entity->getTitle(), date("Y년 m월")); - $html = view( - $this->_viewPath . '/billing', - ['viewDatas' => $this->_viewDatas] - ); - //결과파일저장 - $this->createBilling($entity, $subject, $html); + $this->_viewDatas['fieldDatas']["type"] = $this->_viewDatas['className']; //결제처리 - return $this->_model->modify($entity, ["status" => $this->_viewDatas['className']]); + return parent::update_process($entity); } } diff --git a/app/Database/shoppingmall.sql b/app/Database/shoppingmall.sql index f7588ea..d08f9e4 100644 --- a/app/Database/shoppingmall.sql +++ b/app/Database/shoppingmall.sql @@ -161,7 +161,7 @@ DROP TABLE IF EXISTS shoppingmall.tw_billing; CREATE TABLE shoppingmall.tw_billing ( uid int(10) UNSIGNED NOT NULL AUTO_INCREMENT, user_uid varchar(36) NOT NULL COMMENT '사용자 정보', - type varchar(10) NULL DEFAULT 'Card' COMMENT 'Card: 카드결제, Deposit:무통장입금', + type varchar(10) NULL COMMENT 'Card: 카드결제, Deposit:무통장입금', email varchar(50) NOT NULL, phone varchar(20) NULL COMMENT '연락처', title varchar(255) NOT NULL COMMENT '청구서제목', diff --git a/app/Helpers/Billing_helper.php b/app/Helpers/Billing_helper.php index bbe381f..1364ce9 100644 --- a/app/Helpers/Billing_helper.php +++ b/app/Helpers/Billing_helper.php @@ -73,14 +73,7 @@ function getFieldView_BillingHelper($field, $entity, array $viewDatas) return number_format(!$value ? 0 : $value) . "원"; break; case 'price': - $price = number_format(!$value ? 0 : $value) . "원"; - $paymentday = $entity->paymentday; - return sprintf( - "%s:%s
%s", - lang("{$viewDatas['className']}.label.paymentday"), - $paymentday, - $price - ); + return number_format(!$value ? 0 : $value) . "원"; break; case 'stock': case 'view_cnt': @@ -121,7 +114,7 @@ function getFieldIndex_Column_BillingHelper($field, array $viewDatas) switch ($field) { case 'title': case 'name': - return sprintf("%s", $columnData); + return sprintf("%s", $columnData); break; default: return sprintf("%s", $columnData); @@ -161,18 +154,19 @@ function getFieldIndex_Row_BillingHelper($field, $entity, array $viewDatas): str //미납인경우 if ($value == DEFAULTS['STATUS']) { $card = anchor( - URLS['cardPayment'] . '/' . $entity->getPrimaryKey(), - ICONS['CARD'] . lang("{$viewDatas['className']}.PAYMENT.CARD"), + URLS['card'] . '/' . $entity->getPrimaryKey(), + ICONS['CARD'] . lang("{$viewDatas['className']}.TYPE.CARD"), ["class" => "btn btn-sm btn-primary btn-circle", "style" => "color:white", "target" => "_self"] ); $deposit = anchor( - URLS['depositPayment'] . '/' . $entity->getPrimaryKey(), - ICONS['DEPOSIT'] . lang("{$viewDatas['className']}.PAYMENT.DEPOSIT"), + URLS['deposit'] . '/' . $entity->getPrimaryKey(), + ICONS['DEPOSIT'] . lang("{$viewDatas['className']}.TYPE.DEPOSIT"), ["class" => "btn btn-sm btn-info btn-circle", "style" => "color:white", "target" => "_self"] ); return sprintf("%s
%s", $card, $deposit); } else { - return getFieldView_OrderHelper($field, $entity, $viewDatas); + //결제처리가된경우 + return getFieldView_OrderHelper('type', $entity, $viewDatas); } break; default: diff --git a/app/Language/ko/Billing.php b/app/Language/ko/Billing.php index 81fe474..c7d772d 100644 --- a/app/Language/ko/Billing.php +++ b/app/Language/ko/Billing.php @@ -3,12 +3,13 @@ return [ 'title' => "청구서 정보", 'label' => [ 'uid' => "청구서번호", - 'order_uid' => "주문정보", 'user_uid' => "사용자정보", + 'type' => "결제방식", + 'email' => "메일", + 'phone' => "연라처", 'title' => "청구서명", 'price' => "청구금액", - 'upload_file' => "청구서파일", - 'response' => "결제처리결과", + 'response' => "결제결과", 'status' => "상태", 'updated_at' => "수정일", 'created_at' => "작성일" @@ -17,7 +18,7 @@ return [ "use" => "미납", "unuse" => "납부완료", ], - "PAYMENT" => [ + "TYPE" => [ 'CARD' => " 카 드 결 제", 'DEPOSIT' => " 무통장입금", ] diff --git a/app/Models/BillingModel.php b/app/Models/BillingModel.php index d6af6f3..6894ab3 100644 --- a/app/Models/BillingModel.php +++ b/app/Models/BillingModel.php @@ -9,7 +9,6 @@ class BillingModel extends BaseModel private $_order_options = null; protected $table = "tw_billing"; protected $returnType = BillingEntity::class; - protected $useSoftDeletes = true; public function __construct() { parent::__construct('Billing'); diff --git a/app/Views/front/billing/billing.php b/app/Views/front/billing/billing.php new file mode 100644 index 0000000..8e54ec3 --- /dev/null +++ b/app/Views/front/billing/billing.php @@ -0,0 +1,37 @@ +" media="screen" rel="stylesheet" type="text/css" /> +
+ + + + + + + + + + + + + + + + + + + +
주문정보 +
    + +
  • getTitle() ?> * quantity ?>개 = price) ?>원
  • + +
+
결제금액price) ?>원
은행정보 +
    + +
  • , ,
  • + +
+
+ +
+
\ No newline at end of file diff --git a/app/Views/front/billing/deposit/insert.php b/app/Views/front/billing/deposit/update.php similarity index 95% rename from app/Views/front/billing/deposit/insert.php rename to app/Views/front/billing/deposit/update.php index 7833783..0c7fd65 100644 --- a/app/Views/front/billing/deposit/insert.php +++ b/app/Views/front/billing/deposit/update.php @@ -17,7 +17,7 @@ 결제금액 - 원 + price) ?>원 은행정보 diff --git a/app/Views/front/billing/view.php b/app/Views/front/billing/view.php new file mode 100644 index 0000000..9041b6c --- /dev/null +++ b/app/Views/front/billing/view.php @@ -0,0 +1,42 @@ +extend('layouts/front') ?> +section('content') ?> + +
+
head) ?>
+ + + + + + + + + + + + + + + + + + + +
주문정보 +
    + +
  • getTitle() ?> * quantity ?>개 = price) ?>원
  • + +
+
결제금액price) ?>원
은행정보 +
    + +
  • , ,
  • + +
+
+ +
+
tail) ?>
+
+endSection() ?> \ No newline at end of file diff --git a/app/Views/front/order/index.php b/app/Views/front/order/index.php index 330d124..41fb9a9 100644 --- a/app/Views/front/order/index.php +++ b/app/Views/front/order/index.php @@ -34,9 +34,11 @@ - price ?> - sale ?> - + status == 'unuse') : ?> + price ?> + sale ?> + + @@ -52,7 +54,7 @@
결제정보
상품수 - +
상품금액 @@ -67,7 +69,11 @@
- "btn btn-outline btn-primary")); ?> + + "btn btn-outline btn-primary")); ?> + + 결제할 주문건수가 없습니다. +