This commit is contained in:
115
app/Controllers/manage/Phone.php
Normal file
115
app/Controllers/manage/Phone.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace App\Controllers\manage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\manage\PhoneModel;
|
||||
|
||||
|
||||
|
||||
class Phone extends BaseController
|
||||
{
|
||||
private $phoneModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->phoneModel = new PhoneModel();
|
||||
}
|
||||
|
||||
public function lists(): string
|
||||
{
|
||||
$codes = $this->phoneModel->getCodes();
|
||||
|
||||
return view("pages/manage/phone/lists", ['code' => $codes]);
|
||||
}
|
||||
|
||||
// 전화확인 목록조회
|
||||
public function getDuplPhoneList()
|
||||
{
|
||||
$start = (int) $this->request->getGet('start') ?: 0;
|
||||
$end = (int) $this->request->getGet('length') ?: 10;
|
||||
|
||||
$data = [
|
||||
'srchTxt' => $this->request->getGet('search[value]') ?: '',
|
||||
];
|
||||
|
||||
$totalCount = $this->phoneModel->getTotalCount($data);
|
||||
$datas = $this->phoneModel->getDuplPhoneList($start, $end, $data);
|
||||
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 전화정보 저장
|
||||
public function savePhone()
|
||||
{
|
||||
try {
|
||||
|
||||
if ($this->validPhone($this->request->getPost('phone_number'))) {
|
||||
return $this->response->setJSON([
|
||||
'code' => '1',
|
||||
'msg' => '유효하지 않은 연락처'
|
||||
]);
|
||||
}
|
||||
|
||||
$type = $this->request->getPost('type');
|
||||
$data = [
|
||||
$this->request->getPost('phone_number'), // 연락처
|
||||
$this->request->getPost('use_yn'),
|
||||
$this->request->getPost('s_date'),
|
||||
$this->request->getPost('e_date'),
|
||||
$this->request->getPost('address'),
|
||||
$this->request->getPost('owner'),
|
||||
$this->request->getPost('applicant'),
|
||||
$this->request->getPost('relation'),
|
||||
$this->request->getPost('cpid'),
|
||||
$this->request->getPost(index: 'memo'),
|
||||
session('usr_id'),
|
||||
];
|
||||
|
||||
if ($type === "create") {
|
||||
|
||||
// INSERT dupl_phone_list
|
||||
$this->phoneModel->insertDuplPhone($data);
|
||||
|
||||
} else if ($type === "update") {
|
||||
|
||||
array_push($data, $this->request->getPost("phone_number"));
|
||||
|
||||
// UPDATE dupl_phone_list
|
||||
$this->phoneModel->updateDuplPhone($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->response->setJSON([
|
||||
'code' => '0',
|
||||
'msg' => 'success'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 연락처 유효성검사
|
||||
private function validPhone($phone)
|
||||
{
|
||||
if (preg_match('/^01[0-9]-?\d{3,4}-?\d{4}$/', $phone)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user