shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-16 19:08:51 +09:00
parent 58b02cbdbb
commit 1064eefa1b
23 changed files with 226 additions and 160 deletions

View File

@ -62,7 +62,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('category', static function ($routes) { $routes->group('category', static function ($routes) {
$routes->get('', 'CategoryController::index'); $routes->get('', 'CategoryController::index');
$routes->get('excel', 'CategoryController::excel/$1'); $routes->get('excel', 'CategoryController::excel');
$routes->get('insert', 'CategoryController::insert_form'); $routes->get('insert', 'CategoryController::insert_form');
$routes->post('insert', 'CategoryController::insert'); $routes->post('insert', 'CategoryController::insert');
$routes->get('update/(:num)', 'CategoryController::update_form/$1'); $routes->get('update/(:num)', 'CategoryController::update_form/$1');
@ -76,7 +76,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('board', static function ($routes) { $routes->group('board', static function ($routes) {
$routes->get('', 'BoardController::index'); $routes->get('', 'BoardController::index');
$routes->get('excel', 'BoardController::excel/$1'); $routes->get('excel', 'BoardController::excel');
$routes->get('insert', 'BoardController::insert_form'); $routes->get('insert', 'BoardController::insert_form');
$routes->post('insert', 'BoardController::insert'); $routes->post('insert', 'BoardController::insert');
$routes->get('update/(:num)', 'BoardController::update_form/$1'); $routes->get('update/(:num)', 'BoardController::update_form/$1');
@ -91,7 +91,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('sitepage', static function ($routes) { $routes->group('sitepage', static function ($routes) {
$routes->get('', 'SitepageController::index'); $routes->get('', 'SitepageController::index');
$routes->get('excel', 'SitepageController::excel/$1'); $routes->get('excel', 'SitepageController::excel');
$routes->get('insert', 'SitepageController::insert_form'); $routes->get('insert', 'SitepageController::insert_form');
$routes->post('insert', 'SitepageController::insert'); $routes->post('insert', 'SitepageController::insert');
$routes->get('update/(:num)', 'SitepageController::update_form/$1'); $routes->get('update/(:num)', 'SitepageController::update_form/$1');
@ -103,7 +103,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('product', static function ($routes) { $routes->group('product', static function ($routes) {
$routes->get('', 'ProductController::index'); $routes->get('', 'ProductController::index');
$routes->get('excel', 'ProductController::excel/$1'); $routes->get('excel', 'ProductController::excel');
$routes->get('insert', 'ProductController::insert_form'); $routes->get('insert', 'ProductController::insert_form');
$routes->post('insert', 'ProductController::insert'); $routes->post('insert', 'ProductController::insert');
$routes->get('update/(:uuid)', 'ProductController::update_form/$1'); $routes->get('update/(:uuid)', 'ProductController::update_form/$1');
@ -116,6 +116,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('order', static function ($routes) { $routes->group('order', static function ($routes) {
$routes->get('', 'OrderController::index'); $routes->get('', 'OrderController::index');
$routes->get('excel', 'OrderController::excel');
$routes->get('update/(:uuid)', 'OrderController::update_form/$1'); $routes->get('update/(:uuid)', 'OrderController::update_form/$1');
$routes->post('update/(:uuid)', 'OrderController::update/$1'); $routes->post('update/(:uuid)', 'OrderController::update/$1');
$routes->get('view/(:uuid)', 'OrderController::view/$1'); $routes->get('view/(:uuid)', 'OrderController::view/$1');
@ -125,13 +126,14 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('billing', static function ($routes) { $routes->group('billing', static function ($routes) {
$routes->get('', 'BillingController::index'); $routes->get('', 'BillingController::index');
$routes->get('update/(:uuid)', 'BillingController::update_form/$1'); $routes->get('excel', 'BillingController::excel');
$routes->post('update/(:uuid)', 'BillingController::update/$1'); $routes->get('update/(:num)', 'BillingController::update_form/$1');
$routes->get('view/(:uuid)', 'BillingController::view/$1'); $routes->post('update/(:num)', 'BillingController::update/$1');
$routes->get('delete/(:uuid)', 'BillingController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('view/(:num)', 'BillingController::view/$1');
$routes->get('toggle/(:uuid)/(:hash)', 'BillingController::toggle/$1/$2'); $routes->get('delete/(:num)', 'BillingController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:num)/(:hash)', 'BillingController::toggle/$1/$2');
$routes->post('batchjob', 'BillingController::batchjob`'); $routes->post('batchjob', 'BillingController::batchjob`');
$routes->get('download/(:any)/(:uuid)', 'BillingController::download/$1/$2'); $routes->get('download/(:any)/(:num)', 'BillingController::download/$1/$2');
}); });
}); });
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) { $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
@ -148,7 +150,6 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
}); });
$routes->group('board', static function ($routes) { $routes->group('board', static function ($routes) {
$routes->get('', 'BoardController::index'); $routes->get('', 'BoardController::index');
$routes->get('excel', 'BoardController::excel/$1');
$routes->get('insert', 'BoardController::insert_form'); $routes->get('insert', 'BoardController::insert_form');
$routes->post('insert', 'BoardController::insert'); $routes->post('insert', 'BoardController::insert');
$routes->get('update/(:num)', 'BoardController::update_form/$1'); $routes->get('update/(:num)', 'BoardController::update_form/$1');
@ -164,7 +165,6 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
}); });
$routes->group('product', static function ($routes) { $routes->group('product', static function ($routes) {
$routes->get('', 'ProductController::index'); $routes->get('', 'ProductController::index');
$routes->get('excel', 'ProductController::excel/$1');
$routes->get('view/(:uuid)', 'ProductController::view/$1'); $routes->get('view/(:uuid)', 'ProductController::view/$1');
}); });
$routes->group('order', ['namespace' => 'App\Controllers\Front\Order'], static function ($routes) { $routes->group('order', ['namespace' => 'App\Controllers\Front\Order'], static function ($routes) {
@ -180,7 +180,8 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
}); });
}); });
$routes->group('billing', static function ($routes) { $routes->group('billing', static function ($routes) {
$routes->get('', 'BillingController::index'); $routes->get('', 'BillingController::index', ['filter' => 'authFilter:user']);
$routes->get('download/(:any)/(:num)', 'BillingController::download/$1/$2');
}); });
}); });
/* /*

View File

@ -24,14 +24,14 @@ class BillingController extends AdminController
{ {
switch ($action) { switch ($action) {
case 'update': case 'update':
return ["user_uid", 'order_uid', "title", "upload_file", "status"]; return ["user_uid", 'order_uid', "email", "phone", "title", "upload_file", "status"];
break; break;
case "index": case "index":
case "excel": case "excel":
return ["user_uid", "order_uid", "title", "upload_file", "status", "updated_at", "created_at"]; return ["user_uid", "order_uid", "email", "phone", "title", "upload_file", "status", "updated_at", "created_at"];
break; break;
case "view": case "view":
return ["user_uid", 'order_uid', "title", "upload_file", "status", "updated_at", "created_at", 'response']; return ["user_uid", 'order_uid', "email", "phone", "title", "upload_file", "status", "updated_at", "created_at", 'response'];
break; break;
default: default:
return []; return [];

View File

@ -550,10 +550,13 @@ abstract class BaseController extends Controller
private function index_getEntitys(): array private function index_getEntitys(): array
{ {
$this->index_setCondition(); $this->index_setCondition();
return $this->_viewDatas['page'] ? $this->_model->findAll( if (array_key_exists('page', $this->_viewDatas)) {
$this->_viewDatas['per_page'], return $this->_model->findAll(
$this->_viewDatas['page'] * $this->_viewDatas['per_page'] - $this->_viewDatas['per_page'] $this->_viewDatas['per_page'],
) : $this->_model->findAll(); $this->_viewDatas['page'] * $this->_viewDatas['per_page'] - $this->_viewDatas['per_page']
);
}
return $this->_model->findAll();
} }
public function index() public function index()
{ {
@ -596,37 +599,44 @@ abstract class BaseController extends Controller
} }
//Excel 관련 //Excel 관련
private function excel_spreadSheet(array $viewDatas) final protected function spreadSheet(string $html)
{ {
//Excepl 초기화 // //HTML저장
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); // file_put_contents($fileName . '.html', $html);
$sheet = $spreadsheet->getActiveSheet();
//Header용 //HTML Read
$column = 'A'; $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
foreach ($viewDatas['fields'] as $field) { $spreadsheet = $reader->loadFromString($html);
$sheet->setCellValue($column++ . '1', lang($this->_viewDatas['className'] . '.label.' . $field)); // from File의 경우
} // $spreadsheet = $reader->load($fileName . '.html');
//본문용
$line = 2; //Excel저장
foreach ($this->index_getEntitys() as $entity) { $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$column = 'A'; // $writer->save($fileName . '.xlsx');
foreach ($viewDatas['fields'] as $field) {
$value = in_array($field, $viewDatas['fieldFilters']) ? $viewDatas['fieldFormOptions'][$field][$entity->$field] : $entity->$field; // //PDF저장
$sheet->setCellValue($column . $line, $value); // $writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
$column++; // $writer->save($fileName . '.pdf');
} return $writer;
$line++;
}
return $spreadsheet;
} }
public function excel() public function excel()
{ {
try { try {
$this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas = $this->init(__FUNCTION__);
$fileName = date('Y-m-d_Hm') . '.xlsx'; $this->_viewDatas['Entitys'] = $this->index_getEntitys();
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_spreadSheet($this->_viewDatas), 'Xlsx'); $html = view(
$this->_viewPath . '/excel',
['viewDatas' => $this->_viewDatas]
);
//결과파일저장 //결과파일저장
$writer->save(PATHS['EXCEL'] . '/' . $fileName); $fileName = sprintf(
"%s/%s_%s",
PATHS['EXCEL'],
$this->_viewDatas['className'],
date('Y-m-d_Hm')
);
$writer = $this->spreadSheet($html);
$writer->save($fileName . '.xlsx');
//Download시 //Download시
header("Content-Type: application/vnd.ms-excel"); header("Content-Type: application/vnd.ms-excel");
header(sprintf("Content-Disposition: attachment; filename=%s", urlencode($fileName))); header(sprintf("Content-Disposition: attachment; filename=%s", urlencode($fileName)));
@ -642,25 +652,19 @@ abstract class BaseController extends Controller
} }
} }
//File Download관련 //File Download관련
public function download_process($entity) public function download_process($field, $entity)
{ {
return $entity; list($filename, $uploaded_filename) = explode(DEFAULTS['DELIMITER_FILE'], $entity->$field);
if (!is_file(PATHS['UPLOAD'] . "/" . $uploaded_filename)) {
throw new \Exception("첨부파일이 확인되지 않습니다.\n");
}
return $this->response->download(PATHS['UPLOAD'] . "/" . $uploaded_filename, null)->setFileName(date("Ymd") . '_' . $filename);
} }
public function download(string $field, $uid) public function download(string $field, $uid)
{ {
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
if (!$entity->$field) { return $this->download_process($field, $entity);
throw new \Exception("첨부파일이 확인되지 않습니다.");
}
$entity = $this->download_process($entity);
echo "TEST";
exit;
list($filename, $uploaded_filename) = explode(DEFAULTS['DELIMITER_FILE'], $entity->$field);
if (!is_file(PATHS['UPLOAD'] . "/" . $uploaded_filename)) {
throw new \Exception("파일이 확인되지 않습니다.\n" . PATHS['UPLOAD'] . "/" . $uploaded_filename);
}
return $this->response->download(PATHS['UPLOAD'] . "/" . $uploaded_filename, null)->setFileName(date("Ymd") . '_' . $filename);
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage());
} }

View File

@ -28,14 +28,14 @@ class BillingController extends FrontController
{ {
switch ($action) { switch ($action) {
case 'update': case 'update':
return ['order_uid', "title", "upload_file", "status"]; return ['order_uid', "email", "phone", "title", "upload_file", "status"];
break; break;
case "index": case "index":
case "excel": case "excel":
return ["order_uid", "title", "upload_file", "status", "updated_at", "created_at"]; return ["order_uid", "email", "phone", "title", "upload_file", "status", "updated_at", "created_at"];
break; break;
case "view": case "view":
return ['order_uid', "title", "upload_file", "status", "updated_at", "created_at", 'response']; return ['order_uid', "email", "phone", "title", "upload_file", "status", "updated_at", "created_at", 'response'];
break; break;
default: default:
return []; return [];
@ -50,4 +50,23 @@ class BillingController extends FrontController
{ {
return ["status"]; return ["status"];
} }
//Index관련
protected function index_setCondition()
{
//사용자정보(user_uid)에 맞는 Biiling정보 가져오기
$this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
$this->_model->where("status", DEFAULTS['STATUS']);
parent::index_setCondition();
}
//Download관련
public function download_process($field, $entity)
{
list($filename, $uploaded_filename) = explode(DEFAULTS['DELIMITER_FILE'], $entity->$field);
if (!is_file(PATHS['BILLING'] . "/" . $uploaded_filename)) {
throw new \Exception("첨부파일이 확인되지 않습니다.\n");
}
return $this->response->download(PATHS['BILLING'] . "/" . $uploaded_filename, null)->setFileName(date("Ymd") . '_' . $filename);
}
} }

View File

@ -145,10 +145,16 @@ class BoardController extends FrontController
parent::index_setCondition(); parent::index_setCondition();
} }
//Download관련 //Download관련
public function download_process($entity) public function download_process($field, $entity): array
{ {
$entity = parent::download_process($field, $entity);
//권한체크 //권한체크
$this->isRole('download', $entity); $this->isRole('download', $entity);
return parent::download_process($entity); list($filename, $uploaded_filename) = explode(DEFAULTS['DELIMITER_FILE'], $entity->$field);
if (!is_file(PATHS['UPLOAD'] . "/" . $uploaded_filename)) {
throw new \Exception("파일이 확인되지 않습니다.\n" . PATHS['UPLOAD'] . "/" . $uploaded_filename);
}
return array($filename, $uploaded_filename);
return parent::download_process($field, $entity);
} }
} }

View File

@ -30,11 +30,11 @@ class OrderController extends FrontController
$this->isRole('index'); $this->isRole('index');
} }
final protected function getUserModel() final protected function getUserModel(): UserModel
{ {
return $this->_userModel = $this->_userModel ?: new UserModel(); return $this->_userModel = $this->_userModel ?: new UserModel();
} }
final protected function getProductModel() final protected function getProductModel(): ProductModel
{ {
return $this->_productModel = $this->_productModel ?: new ProductModel(); return $this->_productModel = $this->_productModel ?: new ProductModel();
} }

View File

@ -23,7 +23,7 @@ class CardController extends PaymentController
{ {
switch ($action) { switch ($action) {
case 'update': case 'update':
return ["card_quota", "card_number", "card_expiration", "email", "mobile"]; return ["card_quota", "card_number", "card_expiration", "email", "phone"];
break; break;
default: default:
return []; return [];
@ -48,7 +48,7 @@ class CardController extends PaymentController
case "email": case "email":
$rules[$field] = 'required|valid_email'; $rules[$field] = 'required|valid_email';
break; break;
case "mobile": case "phone":
$rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]'; $rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]';
break; break;
default: default:
@ -98,19 +98,18 @@ class CardController extends PaymentController
} }
protected function update_process($entity) protected function update_process($entity)
{ {
//결제처리
$this->_viewDatas['fieldDatas'] = array("status" => $this->_viewDatas['className']);
$entity = parent::update_process($entity);
//카드결제 //카드결제
$response = $this->pg_process(); $response = $this->pg_process();
//청구서 발행정보 //청구서 발행정보
$this->_viewDatas['entity'] = $entity;
$subject = sprintf("%s %s 청구서입니다.", $entity->getTitle(), date("Y년 m월")); $subject = sprintf("%s %s 청구서입니다.", $entity->getTitle(), date("Y년 m월"));
$html = view( $html = view(
$this->_viewPath . 'billing', $this->_viewPath . '/billing',
['viewDatas' => $this->_viewDatas['fieldDatas']] ['viewDatas' => $this->_viewDatas]
); );
//청구서 발행 //결과파일저장
$this->billing($entity, $subject, $html); $this->createBilling($entity, $subject, $html, $response);
return $entity; //결제처리
return $this->_model->modify($entity, ["status" => $this->_viewDatas['className']]);
} }
} }

View File

@ -16,13 +16,18 @@ class DepositController extends PaymentController
$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']);
$this->_viewDatas['bank'] = [
"name" => getenv("payment.deposit.bank.name") ?: "은행명",
"account" => getenv("payment.deposit.bank.account") ?: "계좌번호",
"holder" => getenv("payment.deposit.bank.holder") ?: "예금주"
];
} }
public function getFields(string $action = ""): array public function getFields(string $action = ""): array
{ {
switch ($action) { switch ($action) {
case 'update': case 'update':
return ["email", "mobile"]; return ["email", "phone"];
break; break;
default: default:
return []; return [];
@ -38,7 +43,7 @@ class DepositController extends PaymentController
case "email": case "email":
$rules[$field] = 'required|valid_email'; $rules[$field] = 'required|valid_email';
break; break;
case "mobile": case "phone":
$rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]'; $rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]';
break; break;
default: default:
@ -57,32 +62,19 @@ class DepositController extends PaymentController
} }
//Insert관련 //Insert관련
//무통장입금결제Form
protected function update_form_process($entity)
{
$entity = parent::update_form_process($entity);
$this->_viewDatas['bank'] = [
"name" => getenv("payment.deposit.bank.name") ?: "은행명",
"account" => getenv("payment.deposit.bank.account") ?: "계좌번호",
"holder" => getenv("payment.deposit.bank.holder") ?: "예금주"
];
return $entity;
}
//무통장입금결제처리 //무통장입금결제처리
protected function update_process($entity) protected function update_process($entity)
{ {
//겔제처리
$this->_viewDatas['fieldDatas'] = array("status" => $this->_viewDatas['className']);
$entity = parent::update_process($entity);
//청구서 발행정보 //청구서 발행정보
$this->_viewDatas['entity'] = $entity;
$subject = sprintf("%s %s 청구서입니다.", $entity->getTitle(), date("Y년 m월")); $subject = sprintf("%s %s 청구서입니다.", $entity->getTitle(), date("Y년 m월"));
$html = view( $html = view(
$this->_viewPath . 'billing', $this->_viewPath . '/billing',
['viewDatas' => $this->_viewDatas['fieldDatas']] ['viewDatas' => $this->_viewDatas]
); );
//청구서 발행 //결과파일저장
$this->billing($entity, $subject, $html); $this->createBilling($entity, $subject, $html);
return $entity; //결제처리
return $this->_model->modify($entity, ["status" => $this->_viewDatas['className']]);
} }
} }

View File

@ -3,19 +3,26 @@
namespace App\Controllers\Front\Order\Payment; namespace App\Controllers\Front\Order\Payment;
use App\Controllers\Front\Order\OrderController; use App\Controllers\Front\Order\OrderController;
use App\Entities\BillingEntity;
use App\Entities\OrderEntity; use App\Entities\OrderEntity;
use App\Models\BillingModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Dompdf\Dompdf;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class PaymentController extends OrderController class PaymentController extends OrderController
{ {
protected $_billingModel = 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);
} }
final protected function getBillingModel(): BillingModel
{
return $this->_billingModel = $this->_billingModel ?: new BillingModel();
}
//Update관련 (결제처리용) //Update관련 (결제처리용)
protected function update_form_process($entity) protected function update_form_process($entity)
{ {
@ -46,10 +53,16 @@ class PaymentController extends OrderController
$this->_product = $this->getProductModel()->getEntity([$this->_model->getPrimaryKey() => $entity->product_uid]); $this->_product = $this->getProductModel()->getEntity([$this->_model->getPrimaryKey() => $entity->product_uid]);
$this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas = $this->init(__FUNCTION__);
$this->update_validate($entity); $this->update_validate($entity);
//Transaction 시작
$this->_model->transStart();
$entity = $this->update_process($entity); $entity = $this->update_process($entity);
//Transaction Commit
$this->_model->transComplete();
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다."; $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다.";
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) { } catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\n" . $e->getMessage(); $msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -60,30 +73,35 @@ class PaymentController extends OrderController
} }
//청구서관련 //청구서관련
final protected function billing(OrderEntity $entity, string $subject, string $html) final protected function createBilling(OrderEntity $entity, string $subject, string $html, $response = ''): BillingEntity
{ {
//Email 발송 //청구서파일 생성
$email = \Config\Services::email(); $fileName = sprintf("%s_%s", $entity->getPrimaryKey(), date('Y-m-d_Hm') . '.xlsx');
$email->setFrom(MALLS['support'], MALLS['title'], MALLS['master']); $writer = $this->spreadSheet($html);
$email->setTo($entity->email); $writer->save(PATHS['BILLING'] . '/' . $fileName);
$email->setCC(MALLS['master']); //메일발송
$email->setSubject($subject); $this->sendBilling($this->_viewDatas['fieldDatas']['email'], $subject, $html);
$email->setMessage($html); $fieldDatas = [
$email->send(); 'order_uid' => $entity->getPrimaryKey(),
'user_uid' => $this->_viewDatas['auth'][AUTH_FIELDS['ID']],
//PDF저장 'email' => $this->_viewDatas['fieldDatas']['email'],
$dompdf = new Dompdf(); 'phone' => $this->_viewDatas['fieldDatas']['phone'],
$dompdf->loadHtml($html); 'title' => $subject,
$dompdf->setPaper('A4', 'landscape'); 'content' => $html,
$dompdf->render(); 'upload_file' => sprintf("%s%s%s", $this->_viewDatas['className'] . '.xlsx', DEFAULTS['DELIMITER_FILE'], $fileName),
//Output the generated PDF to Browser 'response' => $response,
// $dompdf->stream(); 'status' => DEFAULTS['STATUS']
$filename = sprintf( ];
"%s/%s_%s.pdf", return $this->getBillingModel()->create($fieldDatas);
PATHS['BILLING'], }
$entity->getPrimaryKey(), final protected function sendBilling($email, string $subject, string $html): bool
date("Y-m") {
); $mail = \Config\Services::email();
file_put_contents($filename, $dompdf->output()); $mail->setFrom(MALLS['support'], MALLS['title'], MALLS['master']);
$mail->setTo($email);
$mail->setCC(MALLS['master']);
$mail->setSubject($subject);
$mail->setMessage($html);
return $mail->send();
} }
} }

View File

@ -158,10 +158,13 @@ CREATE TABLE shoppingmall.tw_order (
DROP TABLE IF EXISTS shoppingmall.tw_billing; DROP TABLE IF EXISTS shoppingmall.tw_billing;
CREATE TABLE shoppingmall.tw_billing ( CREATE TABLE shoppingmall.tw_billing (
uid int(10) UNSIGNED NOT NULL AUTO_INCREMENT, uid int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
order_uid varchar(36) NULL COMMENT '주문 정보', order_uid varchar(36) NOT NULL COMMENT '주문 정보',
user_uid varchar(36) NULL COMMENT '사용자 정보', user_uid varchar(36) NOT NULL COMMENT '사용자 정보',
email varchar(50) NOT NULL,
phone varchar(20) NULL COMMENT '연락처',
title varchar(255) NOT NULL COMMENT '청구서제목', title varchar(255) NOT NULL COMMENT '청구서제목',
upload_file varchar(255) NULL COMMENT 'PDF 파일명', content text NOT NULL COMMENT '정구서내용',
upload_file varchar(255) NULL COMMENT '파일명',
response text NULL COMMENT '결제처리결과', response text NULL COMMENT '결제처리결과',
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용, unuse: 사용않함 등등', status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용, unuse: 사용않함 등등',
updated_at timestamp NULL DEFAULT NULL, updated_at timestamp NULL DEFAULT NULL,

View File

@ -12,7 +12,7 @@ class BillingEntity extends BaseEntity
//기본기능 //기본기능
final public function getTitle(): string final public function getTitle(): string
{ {
return $this->attributes['name']; return $this->attributes['title'];
} }
//추가기능 //추가기능
//파일관련 Field전용 //파일관련 Field전용
@ -21,9 +21,10 @@ class BillingEntity extends BaseEntity
if (is_null($this->attributes[$field])) { if (is_null($this->attributes[$field])) {
return ""; return "";
} }
$files = explode(DEFAULTS['DELIMITER_FILE'], $this->attributes[$field]);
return anchor( return anchor(
$url, $url,
ICONS['IMAGE_FILE'] . $this->attributes[$field], ICONS['IMAGE_FILE'] . $files[0],
["target" => "_self"] ["target" => "_self"]
); );
} }

View File

@ -136,17 +136,26 @@ function getFieldIndex_Row_BillingHelper($field, $entity, array $viewDatas): str
switch ($field) { switch ($field) {
case 'title': case 'title':
case 'name': case 'name':
$uid = lang("{$viewDatas['className']}.label.uid") . ' : ' . str_split($entity->getPrimaryKey(), 4)[0] . '-xx-' . str_split($entity->getPrimaryKey(), 4)[1]; return anchor(
$title = anchor(
current_url() . '/view/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['category']->getPrimaryKey(), current_url() . '/view/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['category']->getPrimaryKey(),
$value, $value,
["target" => "_self"] ["target" => "_self"]
); );
return sprintf("%s<BR>%s", $uid, $title); break;
case 'order_uid':
case 'user_uid':
return getFieldView_BillingHelper($field, $entity, $viewDatas);
break; break;
case 'board_file': case 'board_file':
case 'upload_file': case 'upload_file':
return $entity->getFileDownload(base_url() . $viewDatas['control'] . '/billing', $field); // echo var_export($entity, true);
// exit;
return $entity->getFileDownload(
base_url() .
$viewDatas['control'] .
"/billing/download/{$field}/{$entity->getPrimaryKey()}",
$field
);
break; break;
default: default:
return getFieldView_BillingHelper($field, $entity, $viewDatas); return getFieldView_BillingHelper($field, $entity, $viewDatas);
@ -160,16 +169,20 @@ function getFieldIndex_Row_BillingHelper_Admin($field, $entity, array $viewDatas
switch ($field) { switch ($field) {
case 'title': case 'title':
case 'name': case 'name':
$uid = lang("{$viewDatas['className']}.label.uid") . ' : ' . str_split($entity->getPrimaryKey(), 4)[0] . '-xx-' . str_split($entity->getPrimaryKey(), 4)[1]; return anchor(
$title = anchor(
current_url() . '/view/' . $entity->getPrimaryKey(), current_url() . '/view/' . $entity->getPrimaryKey(),
$value, $value,
["target" => "_self"] ["target" => "_self"]
); );
return sprintf("%s<BR>%s", $uid, $title);
break; break;
case 'user_uid': case 'board_file':
return getFieldView_BillingHelper($field, $entity, $viewDatas); case 'upload_file':
return $entity->getFileDownload(
base_url() .
$viewDatas['control'] .
"/billing/download/{$field}/{$entity->getPrimaryKey()}",
$field
);
break; break;
default: default:
if (in_array($field, $viewDatas['fieldFilters'])) { if (in_array($field, $viewDatas['fieldFilters'])) {

View File

@ -73,16 +73,6 @@ function getFieldView_BoardHelper($field, $entity, array $viewDatas)
} }
return $value; return $value;
break; break;
case 'board_file':
case 'upload_file':
return $entity->getFileDownload(
base_url() .
$viewDatas['control'] .
"/board/download/{$field}/{$entity->getPrimaryKey()}" .
'?category=' . $viewDatas['category']->getPrimaryKey(),
$field
);
break;
case 'photo': case 'photo':
return $entity->getFileImage('middle', $field); return $entity->getFileImage('middle', $field);
break; break;
@ -151,6 +141,16 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $viewDatas): strin
); );
return sprintf("%s%s %s", $depth, $reply, $view); return sprintf("%s%s %s", $depth, $reply, $view);
break; break;
case 'board_file':
case 'upload_file':
return $entity->getFileDownload(
base_url() .
$viewDatas['control'] .
"/board/download/{$field}/{$entity->getPrimaryKey()}" .
'?category=' . $viewDatas['category']->getPrimaryKey(),
$field
);
break;
default: default:
return getFieldView_BoardHelper($field, $entity, $viewDatas); return getFieldView_BoardHelper($field, $entity, $viewDatas);
break; break;
@ -182,7 +182,12 @@ function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $viewDatas):
break; break;
case 'board_file': case 'board_file':
case 'upload_file': case 'upload_file':
return $entity->getFileDownload(base_url() . $viewDatas['control'] . '/board', $field); return $entity->getFileDownload(
base_url() .
$viewDatas['control'] .
"/board/download/{$field}/{$entity->getPrimaryKey()}",
$field
);
break; break;
default: default:
if (in_array($field, $viewDatas['fieldFilters'])) { if (in_array($field, $viewDatas['fieldFilters'])) {

View File

@ -49,8 +49,8 @@ function getFieldForm_CardHelper($field, $value, array $viewDatas, array $attrib
case 'email': case 'email':
return form_input($field, $viewDatas['user']->email); return form_input($field, $viewDatas['user']->email);
break; break;
case 'mobile': case 'phone':
return form_input($field, $viewDatas['user']->mobile); return form_input($field, $viewDatas['user']->phone);
break; break;
default: default:
return form_input($field, $value); return form_input($field, $value);

View File

@ -20,8 +20,8 @@ function getFieldForm_DepositHelper($field, $value, array $viewDatas, array $att
case 'email': case 'email':
return form_input($field, $viewDatas['user']->email); return form_input($field, $viewDatas['user']->email);
break; break;
case 'mobile': case 'phone':
return form_input($field, $viewDatas['user']->mobile); return form_input($field, $viewDatas['user']->phone);
break; break;
default: default:
return form_input($field, $value); return form_input($field, $value);

View File

@ -5,6 +5,8 @@ return [
'uid' => "청구서번호", 'uid' => "청구서번호",
'order_uid' => "주문정보", 'order_uid' => "주문정보",
'user_uid' => "사용자정보", 'user_uid' => "사용자정보",
'email' => '이메일',
'phone' => '연락처',
'title' => "청구서명", 'title' => "청구서명",
'upload_file' => "청구서파일", 'upload_file' => "청구서파일",
'response' => "결제처리결과", 'response' => "결제처리결과",

View File

@ -7,7 +7,7 @@ return [
'card_number' => '카드번호', 'card_number' => '카드번호',
'card_expiration' => '유효기간', 'card_expiration' => '유효기간',
'email' => '이메일', 'email' => '이메일',
'mobile' => '인증휴대폰', 'phone' => '연락처',
], ],
"CARD_QUOTA" => [ "CARD_QUOTA" => [
"00" => "일시불", "00" => "일시불",

View File

@ -4,6 +4,6 @@ return [
'label' => [ 'label' => [
'order_uid' => '주문번호', 'order_uid' => '주문번호',
'email' => '이메일', 'email' => '이메일',
'mobile' => '인증휴대폰', 'phone' => '연락처',
], ],
]; ];

View File

@ -8,15 +8,14 @@ use App\Entities\ProductEntity;
class BillingModel extends BaseModel class BillingModel extends BaseModel
{ {
private $_order_options = null; private $_order_options = null;
protected $table = "tw_order"; protected $table = "tw_billing";
protected $useAutoIncrement = false;
protected $returnType = BillingEntity::class; protected $returnType = BillingEntity::class;
protected $useSoftDeletes = true; protected $useSoftDeletes = true;
public function __construct() public function __construct()
{ {
parent::__construct('Billing'); parent::__construct('Billing');
$this->allowedFields = [ $this->allowedFields = [
...$this->allowedFields, 'order_uid', "user_uid", ...$this->allowedFields, 'order_uid', "user_uid", "email", "phone",
"title", "upload_file", "response", "status" "title", "upload_file", "response", "status"
]; ];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
@ -31,6 +30,12 @@ class BillingModel extends BaseModel
case 'order_uid': case 'order_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}/]"; $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; break;
case "email":
$rules[$field] = "required|trim|valid_email";
break;
case "phone":
$rules[$field] = "if_exist|string";
break;
case $this->getTitleField(): case $this->getTitleField():
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
break; break;
@ -38,7 +43,7 @@ class BillingModel extends BaseModel
$rules[$field] = "if_exist|string"; $rules[$field] = "if_exist|string";
break; break;
case "response": case "response":
$rules[$field] = "required|string"; $rules[$field] = "if_exist|string";
break; break;
default: default:
$rules = parent::getFieldRule($field, $rules, $action); $rules = parent::getFieldRule($field, $rules, $action);

View File

@ -16,7 +16,6 @@
<?php foreach ($viewDatas['entitys'] as $entity) : ?> <?php foreach ($viewDatas['entitys'] as $entity) : ?>
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)"> <tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
<td nowrap> <td nowrap>
<!-- 사용자가 자신의 작성한것인지 확인되면 update 가능-->
<?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?> <?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?>
</td> </td>
<?php foreach ($viewDatas['fields'] as $field) : ?> <?php foreach ($viewDatas['fields'] as $field) : ?>

View File

@ -1,4 +1,4 @@
<link href="/css/front/billing.css" media="screen" rel="stylesheet" type="text/css" /> <link href="<?= base_url("css/front/billing.css") ?>" media=" screen" rel="stylesheet" type="text/css" />
<table id="billing"> <table id="billing">
<tr> <tr>
<td class="label">상품명</td> <td class="label">상품명</td>

View File

@ -12,8 +12,7 @@
"twbs/bootstrap": "5.2.3", "twbs/bootstrap": "5.2.3",
"guzzlehttp/guzzle": "^7.7", "guzzlehttp/guzzle": "^7.7",
"google/apiclient": "2.12.1", "google/apiclient": "2.12.1",
"tinymce/tinymce": "^6.6", "tinymce/tinymce": "^6.6"
"dompdf/dompdf": "^2.0"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9", "fakerphp/faker": "^1.9",