110 lines
4.1 KiB
PHP
110 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Front\Billing\Payment;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class DepositController extends PaymentController
|
|
{
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->_viewDatas['className'] = 'Deposit';
|
|
$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']);
|
|
}
|
|
|
|
public function getFields(string $action = ""): array
|
|
{
|
|
switch ($action) {
|
|
case 'insert':
|
|
return ["email", "phone"];
|
|
break;
|
|
default:
|
|
return [];
|
|
break;
|
|
}
|
|
}
|
|
protected function getFieldRule(string $field, array $rules, string $action = ""): array
|
|
{
|
|
switch ($field) {
|
|
case "email":
|
|
$rules[$field] = 'required|valid_email';
|
|
break;
|
|
case "phone":
|
|
$rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]';
|
|
break;
|
|
case "title":
|
|
$rules[$field] = 'required|string';
|
|
break;
|
|
case "price":
|
|
$rules[$field] = 'required|numeric';
|
|
break;
|
|
case "content":
|
|
$rules[$field] = 'required|string';
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules, $action);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getFieldFilters(): array
|
|
{
|
|
return [];
|
|
}
|
|
public function getFieldBatchFilters(): array
|
|
{
|
|
return parent::getFieldBatchFilters();
|
|
}
|
|
|
|
//Insert관련
|
|
protected function insert_form_process()
|
|
{
|
|
parent::insert_form_process();
|
|
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => ['price' => $this->_viewDatas['price']]];
|
|
}
|
|
public function insert_form()
|
|
{
|
|
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();
|
|
if (!count($this->_viewDatas['orders'])) {
|
|
throw new \Exception("해당하는 주문정보가 없습니다.");
|
|
}
|
|
$this->insert_form_process();
|
|
helper(['form']);
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return view($this->_viewPath . '/insert', ['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());
|
|
}
|
|
}
|
|
//무통장입금결제처리
|
|
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);
|
|
//결제처리
|
|
return $this->_model->modify($entity, ["status" => $this->_viewDatas['className']]);
|
|
}
|
|
}
|