feat: add designated shop detail and PII masking updates
Rebase current admin changes on top of origin/main and exclude local artifacts from tracking to reduce push payload. Made-with: Cursor
This commit is contained in:
@@ -18,25 +18,68 @@ class Company extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('cp_lg_idx', $lgIdx)->orderBy('cp_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
if ($this->request->is('post')) {
|
||||
$searchField = trim((string) ($this->request->getPost('search_field') ?? ''));
|
||||
$searchQuery = trim((string) ($this->request->getPost('search_query') ?? ''));
|
||||
session()->setFlashdata('company_search', [
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
]);
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 관리',
|
||||
'content' => view('admin/company/index', ['list' => $list, 'pager' => $pager]),
|
||||
return redirect()->to(mgmt_url('companies'));
|
||||
}
|
||||
|
||||
$fromGetField = trim((string) ($this->request->getGet('search_field') ?? ''));
|
||||
$fromGetQuery = trim((string) ($this->request->getGet('search_query') ?? ''));
|
||||
$flash = session()->getFlashdata('company_search');
|
||||
if ($fromGetField !== '' || $fromGetQuery !== '') {
|
||||
$searchField = $fromGetField;
|
||||
$searchQuery = $fromGetQuery;
|
||||
} elseif (is_array($flash)) {
|
||||
$searchField = trim((string) ($flash['search_field'] ?? ''));
|
||||
$searchQuery = trim((string) ($flash['search_query'] ?? ''));
|
||||
} else {
|
||||
$searchField = '';
|
||||
$searchQuery = '';
|
||||
}
|
||||
|
||||
$allowedFields = ['cp_idx', 'cp_type', 'cp_name', 'cp_biz_no', 'cp_rep_name', 'cp_tel', 'cp_addr'];
|
||||
if (! in_array($searchField, $allowedFields, true)) {
|
||||
$searchField = 'cp_name';
|
||||
}
|
||||
|
||||
$builder = $this->model->where('cp_lg_idx', $lgIdx);
|
||||
if ($searchQuery !== '') {
|
||||
if ($searchField === 'cp_idx') {
|
||||
if (ctype_digit($searchQuery)) {
|
||||
$builder->where('cp_idx', (int) $searchQuery);
|
||||
} else {
|
||||
$builder->where('cp_idx', 0);
|
||||
}
|
||||
} else {
|
||||
$builder->like($searchField, $searchQuery);
|
||||
}
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('cp_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
$pager->setPath('bag/companies');
|
||||
|
||||
return $this->renderWorkPage('업체 관리', 'admin/company/index', [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 등록',
|
||||
'content' => view('admin/company/create'),
|
||||
]);
|
||||
return $this->renderWorkPage('업체 등록', 'admin/company/create');
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -66,29 +109,26 @@ class Company extends BaseController
|
||||
'cp_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/companies'))->with('success', '업체가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 수정',
|
||||
'content' => view('admin/company/edit', ['item' => $item]),
|
||||
]);
|
||||
return $this->renderWorkPage('업체 수정', 'admin/company/edit', ['item' => $item]);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
@@ -110,18 +150,19 @@ class Company extends BaseController
|
||||
'cp_state' => (int) $this->request->getPost('cp_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/companies'))->with('success', '업체가 수정되었습니다.');
|
||||
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/companies'))->with('success', '업체가 삭제되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class DesignatedShop extends BaseController
|
||||
|
||||
public function export()
|
||||
{
|
||||
helper(['admin', 'export']);
|
||||
helper(['admin', 'export', 'pii_mask']);
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin/designated-shops'))->with('error', '지자체를 선택해 주세요.');
|
||||
@@ -104,7 +104,7 @@ class DesignatedShop extends BaseController
|
||||
$row->ds_idx,
|
||||
$row->ds_shop_no,
|
||||
$row->ds_name,
|
||||
$row->ds_rep_name,
|
||||
mask_person_name($row->ds_rep_name ?? null),
|
||||
$row->ds_biz_no,
|
||||
$row->ds_va_number,
|
||||
$row->ds_tel ?? '',
|
||||
@@ -121,6 +121,41 @@ class DesignatedShop extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정판매소 상세 (읽기 전용, 목록에서 연결)
|
||||
*/
|
||||
public function show(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if ($lgIdx === null || $lgIdx <= 0) {
|
||||
return redirect()->to(work_area_home_url())
|
||||
->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$shop = $this->shopModel->find($id);
|
||||
if ($shop === null || (int) $shop->ds_lg_idx !== $lgIdx) {
|
||||
return redirect()->to(mgmt_url('designated-shops'))
|
||||
->with('error', '해당 지정판매소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$currentLg = $this->lgModel->find($lgIdx);
|
||||
|
||||
$stateLabel = match ((int) $shop->ds_state) {
|
||||
1 => '정상',
|
||||
2 => '폐업',
|
||||
3 => '직권해지',
|
||||
default => (string) $shop->ds_state,
|
||||
};
|
||||
|
||||
return $this->renderWorkPage('지정판매소 정보', 'admin/designated_shop/show', [
|
||||
'shop' => $shop,
|
||||
'currentLg' => $currentLg,
|
||||
'stateLabel' => $stateLabel,
|
||||
'can_edit' => $this->isSuperAdmin() || $this->isLocalAdmin(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정판매소 등록 폼 (효과 지자체 기준)
|
||||
*/
|
||||
|
||||
@@ -18,35 +18,123 @@ class FreeRecipient extends BaseController
|
||||
|
||||
private function getCodeOptions(string $ckCode): array
|
||||
{
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', $ckCode)->first();
|
||||
return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', $ckCode)->first();
|
||||
|
||||
return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('fr_lg_idx', $lgIdx)->orderBy('fr_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
if ($this->request->is('post')) {
|
||||
$searchField = trim((string) ($this->request->getPost('search_field') ?? ''));
|
||||
$searchQuery = trim((string) ($this->request->getPost('search_query') ?? ''));
|
||||
session()->setFlashdata('free_recipient_search', [
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
]);
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 관리',
|
||||
'content' => view('admin/free_recipient/index', ['list' => $list, 'pager' => $pager]),
|
||||
return redirect()->to(mgmt_url('free-recipients'));
|
||||
}
|
||||
|
||||
$fromGetField = trim((string) ($this->request->getGet('search_field') ?? ''));
|
||||
$fromGetQuery = trim((string) ($this->request->getGet('search_query') ?? ''));
|
||||
$flash = session()->getFlashdata('free_recipient_search');
|
||||
if ($fromGetField !== '' || $fromGetQuery !== '') {
|
||||
$searchField = $fromGetField;
|
||||
$searchQuery = $fromGetQuery;
|
||||
} elseif (is_array($flash)) {
|
||||
$searchField = trim((string) ($flash['search_field'] ?? ''));
|
||||
$searchQuery = trim((string) ($flash['search_query'] ?? ''));
|
||||
} else {
|
||||
$searchField = '';
|
||||
$searchQuery = '';
|
||||
}
|
||||
|
||||
$allowedFields = ['fr_idx', 'fr_type_code', 'fr_name', 'fr_phone', 'fr_addr', 'fr_dong_code', 'fr_note'];
|
||||
if (! in_array($searchField, $allowedFields, true)) {
|
||||
$searchField = 'fr_name';
|
||||
}
|
||||
|
||||
$typeCodes = $this->getCodeOptions('H');
|
||||
$typeCodeMap = [];
|
||||
foreach ($typeCodes as $cd) {
|
||||
$typeCodeMap[(string) $cd->cd_code] = (string) $cd->cd_name;
|
||||
}
|
||||
|
||||
$dongCodes = $this->getCodeOptions('D');
|
||||
$dongCodeMap = [];
|
||||
foreach ($dongCodes as $cd) {
|
||||
$dongCodeMap[(string) $cd->cd_code] = (string) $cd->cd_name;
|
||||
}
|
||||
|
||||
$builder = $this->model->where('fr_lg_idx', $lgIdx);
|
||||
if ($searchQuery !== '') {
|
||||
if ($searchField === 'fr_idx') {
|
||||
if (ctype_digit($searchQuery)) {
|
||||
$builder->where('fr_idx', (int) $searchQuery);
|
||||
} else {
|
||||
$builder->where('fr_idx', 0);
|
||||
}
|
||||
} elseif ($searchField === 'fr_type_code') {
|
||||
$codes = [];
|
||||
foreach ($typeCodes as $cd) {
|
||||
$code = (string) ($cd->cd_code ?? '');
|
||||
$name = (string) ($cd->cd_name ?? '');
|
||||
if ($code !== '' && (stripos($code, $searchQuery) !== false || stripos($name, $searchQuery) !== false)) {
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
if ($codes === []) {
|
||||
$builder->where('fr_idx', 0);
|
||||
} else {
|
||||
$builder->whereIn('fr_type_code', array_values(array_unique($codes)));
|
||||
}
|
||||
} elseif ($searchField === 'fr_dong_code') {
|
||||
$codes = [];
|
||||
foreach ($dongCodes as $cd) {
|
||||
$code = (string) ($cd->cd_code ?? '');
|
||||
$name = (string) ($cd->cd_name ?? '');
|
||||
if ($code !== '' && (stripos($code, $searchQuery) !== false || stripos($name, $searchQuery) !== false)) {
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
if ($codes === []) {
|
||||
$builder->where('fr_idx', 0);
|
||||
} else {
|
||||
$builder->whereIn('fr_dong_code', array_values(array_unique($codes)));
|
||||
}
|
||||
} else {
|
||||
$builder->like($searchField, $searchQuery);
|
||||
}
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('fr_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
$pager->setPath('bag/free-recipients');
|
||||
|
||||
return $this->renderWorkPage('무료용 대상자 관리', 'admin/free_recipient/index', [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
'type_code_map' => $typeCodeMap,
|
||||
'dong_code_map' => $dongCodeMap,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 등록',
|
||||
'content' => view('admin/free_recipient/create', [
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]),
|
||||
return $this->renderWorkPage('무료용 대상자 등록', 'admin/free_recipient/create', [
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -75,24 +163,21 @@ class FreeRecipient extends BaseController
|
||||
'fr_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('success', '무료용 대상자가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('success', '무료용 대상자가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 수정',
|
||||
'content' => view('admin/free_recipient/edit', [
|
||||
'item' => $item,
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]),
|
||||
return $this->renderWorkPage('무료용 대상자 수정', 'admin/free_recipient/edit', [
|
||||
'item' => $item,
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -100,8 +185,8 @@ class FreeRecipient extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
@@ -123,18 +208,19 @@ class FreeRecipient extends BaseController
|
||||
'fr_state' => (int) $this->request->getPost('fr_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('success', '무료용 대상자가 수정되었습니다.');
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('success', '무료용 대상자가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->fr_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('error', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('success', '무료용 대상자가 삭제되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('free-recipients'))->with('success', '무료용 대상자가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ class Manager extends BaseController
|
||||
|
||||
private function getCodeOptions(string $ckCode): array
|
||||
{
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', $ckCode)->first();
|
||||
return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', $ckCode)->first();
|
||||
|
||||
return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
}
|
||||
|
||||
public function index()
|
||||
@@ -27,32 +30,105 @@ class Manager extends BaseController
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
helper('admin');
|
||||
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('mg_lg_idx', $lgIdx)->orderBy('mg_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
if ($this->request->is('post')) {
|
||||
$searchField = trim((string) ($this->request->getPost('search_field') ?? ''));
|
||||
$searchQuery = trim((string) ($this->request->getPost('search_query') ?? ''));
|
||||
session()->setFlashdata('manager_search', [
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
]);
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '담당자 관리',
|
||||
'content' => view('admin/manager/index', ['list' => $list, 'pager' => $pager]),
|
||||
return redirect()->to(mgmt_url('managers'));
|
||||
}
|
||||
|
||||
$fromGetField = trim((string) ($this->request->getGet('search_field') ?? ''));
|
||||
$fromGetQuery = trim((string) ($this->request->getGet('search_query') ?? ''));
|
||||
$flash = session()->getFlashdata('manager_search');
|
||||
if ($fromGetField !== '' || $fromGetQuery !== '') {
|
||||
$searchField = $fromGetField;
|
||||
$searchQuery = $fromGetQuery;
|
||||
} elseif (is_array($flash)) {
|
||||
$searchField = trim((string) ($flash['search_field'] ?? ''));
|
||||
$searchQuery = trim((string) ($flash['search_query'] ?? ''));
|
||||
} else {
|
||||
$searchField = '';
|
||||
$searchQuery = '';
|
||||
}
|
||||
|
||||
$allowedFields = ['mg_idx', 'mg_name', 'mg_dept_code', 'mg_position_code', 'mg_tel', 'mg_phone', 'mg_email'];
|
||||
if (! in_array($searchField, $allowedFields, true)) {
|
||||
$searchField = 'mg_name';
|
||||
}
|
||||
|
||||
$deptCodes = $this->getCodeOptions('S');
|
||||
$posCodes = $this->getCodeOptions('T');
|
||||
$deptCodeMap = [];
|
||||
foreach ($deptCodes as $cd) {
|
||||
$deptCodeMap[(string) $cd->cd_code] = (string) $cd->cd_name;
|
||||
}
|
||||
$posCodeMap = [];
|
||||
foreach ($posCodes as $cd) {
|
||||
$posCodeMap[(string) $cd->cd_code] = (string) $cd->cd_name;
|
||||
}
|
||||
|
||||
$builder = $this->model->where('mg_lg_idx', $lgIdx);
|
||||
if ($searchQuery !== '') {
|
||||
if ($searchField === 'mg_idx') {
|
||||
if (ctype_digit($searchQuery)) {
|
||||
$builder->where('mg_idx', (int) $searchQuery);
|
||||
} else {
|
||||
$builder->where('mg_idx', 0);
|
||||
}
|
||||
} elseif ($searchField === 'mg_dept_code' || $searchField === 'mg_position_code') {
|
||||
$sourceList = $searchField === 'mg_dept_code' ? $deptCodes : $posCodes;
|
||||
$codes = [];
|
||||
foreach ($sourceList as $cd) {
|
||||
$code = (string) ($cd->cd_code ?? '');
|
||||
$name = (string) ($cd->cd_name ?? '');
|
||||
if ($code !== '' && (stripos($code, $searchQuery) !== false || stripos($name, $searchQuery) !== false)) {
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
if ($codes === []) {
|
||||
$builder->where('mg_idx', 0);
|
||||
} else {
|
||||
$builder->whereIn($searchField, array_values(array_unique($codes)));
|
||||
}
|
||||
} else {
|
||||
$builder->like($searchField, $searchQuery);
|
||||
}
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('mg_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
$pager->setPath('bag/managers');
|
||||
|
||||
return $this->renderWorkPage('담당자 관리', 'admin/manager/index', [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
'dept_code_map' => $deptCodeMap,
|
||||
'pos_code_map' => $posCodeMap,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '담당자 등록',
|
||||
'content' => view('admin/manager/create', [
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]),
|
||||
return $this->renderWorkPage('담당자 등록', 'admin/manager/create', [
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
helper(['admin', 'url']);
|
||||
$rules = [
|
||||
'mg_name' => 'required|max_length[50]',
|
||||
'mg_tel' => 'permit_empty|max_length[20]',
|
||||
@@ -75,33 +151,30 @@ class Manager extends BaseController
|
||||
'mg_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('managers'))->with('success', '담당자가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
helper(['admin', 'url']);
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->mg_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '담당자 수정',
|
||||
'content' => view('admin/manager/edit', [
|
||||
'item' => $item,
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]),
|
||||
return $this->renderWorkPage('담당자 수정', 'admin/manager/edit', [
|
||||
'item' => $item,
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
helper(['admin', 'url']);
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->mg_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
@@ -122,18 +195,19 @@ class Manager extends BaseController
|
||||
'mg_state' => (int) $this->request->getPost('mg_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 수정되었습니다.');
|
||||
return redirect()->to(mgmt_url('managers'))->with('success', '담당자가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
helper(['admin', 'url']);
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->mg_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
return redirect()->to(mgmt_url('managers'))->with('error', '담당자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 삭제되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('managers'))->with('success', '담당자가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
@@ -7,6 +9,8 @@ use App\Models\SalesAgencyModel;
|
||||
|
||||
class SalesAgency extends BaseController
|
||||
{
|
||||
private const SCHEMA_ERROR = '판매 대행소 테이블에 sa_kind·sa_code 컬럼이 없습니다. DB에 writable/database/sales_agency_migrate_to_kind_code_name.sql(또는 신규용 sales_agency_tables.sql)을 적용한 뒤 다시 시도해 주세요.';
|
||||
|
||||
private SalesAgencyModel $model;
|
||||
|
||||
public function __construct()
|
||||
@@ -18,106 +22,150 @@ class SalesAgency extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('sa_lg_idx', $lgIdx)->orderBy('sa_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
$searchField = trim((string) ($this->request->getGet('search_field') ?? ''));
|
||||
$searchQuery = trim((string) ($this->request->getGet('search_query') ?? ''));
|
||||
$allowedFields = ['sa_idx', 'sa_kind', 'sa_code', 'sa_name'];
|
||||
if (! in_array($searchField, $allowedFields, true)) {
|
||||
$searchField = 'sa_name';
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 관리',
|
||||
'content' => view('admin/sales_agency/index', ['list' => $list, 'pager' => $pager]),
|
||||
$builder = $this->model->where('sa_lg_idx', $lgIdx);
|
||||
if ($searchQuery !== '') {
|
||||
if ($searchField === 'sa_idx') {
|
||||
if (ctype_digit($searchQuery)) {
|
||||
$builder->where('sa_idx', (int) $searchQuery);
|
||||
} else {
|
||||
// 번호 검색은 숫자만 허용한다.
|
||||
$builder->where('sa_idx', 0);
|
||||
}
|
||||
} else {
|
||||
$builder->like($searchField, $searchQuery);
|
||||
}
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('sa_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->model->pager;
|
||||
// 전체 URL·쿼리를 setPath에 넣으면 Pager URI 경로가 깨져 404가 난다. 경로만 지정한다(필터는 현재 GET이 병합됨).
|
||||
$pager->setPath('bag/sales-agencies');
|
||||
|
||||
return $this->renderWorkPage('판매 대행소 관리', 'admin/sales_agency/index', [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'search_field' => $searchField,
|
||||
'search_query' => $searchQuery,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 등록',
|
||||
'content' => view('admin/sales_agency/create'),
|
||||
]);
|
||||
helper('admin');
|
||||
if (! admin_effective_lg_idx()) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
return $this->renderWorkPage('판매 대행소 등록', 'admin/sales_agency/create');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
if (! $this->model->hasKindCodeColumns()) {
|
||||
return redirect()->back()->withInput()->with('error', self::SCHEMA_ERROR);
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'sa_name' => 'required|max_length[100]',
|
||||
'sa_biz_no' => 'permit_empty|max_length[20]',
|
||||
'sa_rep_name' => 'permit_empty|max_length[50]',
|
||||
'sa_tel' => 'permit_empty|max_length[20]',
|
||||
'sa_addr' => 'permit_empty|max_length[255]',
|
||||
'sa_kind' => 'required|max_length[50]',
|
||||
'sa_code' => 'required|max_length[50]',
|
||||
'sa_name' => 'required|max_length[100]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$code = trim((string) $this->request->getPost('sa_code'));
|
||||
if ($this->model->where('sa_lg_idx', $lgIdx)->where('sa_code', $code)->first() !== null) {
|
||||
return redirect()->back()->withInput()->with('error', '동일 지자체에 같은 대행소 코드가 이미 있습니다.');
|
||||
}
|
||||
|
||||
$this->model->insert([
|
||||
'sa_lg_idx' => admin_effective_lg_idx(),
|
||||
'sa_name' => $this->request->getPost('sa_name'),
|
||||
'sa_biz_no' => $this->request->getPost('sa_biz_no') ?? '',
|
||||
'sa_rep_name' => $this->request->getPost('sa_rep_name') ?? '',
|
||||
'sa_tel' => $this->request->getPost('sa_tel') ?? '',
|
||||
'sa_addr' => $this->request->getPost('sa_addr') ?? '',
|
||||
'sa_state' => 1,
|
||||
'sa_regdate' => date('Y-m-d H:i:s'),
|
||||
'sa_lg_idx' => $lgIdx,
|
||||
'sa_kind' => trim((string) $this->request->getPost('sa_kind')),
|
||||
'sa_code' => $code,
|
||||
'sa_name' => trim((string) $this->request->getPost('sa_name')),
|
||||
'sa_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('success', '판매 대행소가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('success', '판매 대행소가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->sa_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->sa_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 수정',
|
||||
'content' => view('admin/sales_agency/edit', ['item' => $item]),
|
||||
]);
|
||||
return $this->renderWorkPage('판매 대행소 수정', 'admin/sales_agency/edit', ['item' => $item]);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->sa_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$item = $this->model->find($id);
|
||||
if (! $item || ! $lgIdx || (int) $item->sa_lg_idx !== $lgIdx) {
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
if (! $this->model->hasKindCodeColumns()) {
|
||||
return redirect()->back()->withInput()->with('error', self::SCHEMA_ERROR);
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'sa_name' => 'required|max_length[100]',
|
||||
'sa_state' => 'required|in_list[0,1]',
|
||||
'sa_kind' => 'required|max_length[50]',
|
||||
'sa_code' => 'required|max_length[50]',
|
||||
'sa_name' => 'required|max_length[100]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$code = trim((string) $this->request->getPost('sa_code'));
|
||||
$dup = $this->model->where('sa_lg_idx', $lgIdx)->where('sa_code', $code)->where('sa_idx !=', $id)->first();
|
||||
if ($dup !== null) {
|
||||
return redirect()->back()->withInput()->with('error', '동일 지자체에 같은 대행소 코드가 이미 있습니다.');
|
||||
}
|
||||
|
||||
$this->model->update($id, [
|
||||
'sa_name' => $this->request->getPost('sa_name'),
|
||||
'sa_biz_no' => $this->request->getPost('sa_biz_no') ?? '',
|
||||
'sa_rep_name' => $this->request->getPost('sa_rep_name') ?? '',
|
||||
'sa_tel' => $this->request->getPost('sa_tel') ?? '',
|
||||
'sa_addr' => $this->request->getPost('sa_addr') ?? '',
|
||||
'sa_state' => (int) $this->request->getPost('sa_state'),
|
||||
'sa_kind' => trim((string) $this->request->getPost('sa_kind')),
|
||||
'sa_code' => $code,
|
||||
'sa_name' => trim((string) $this->request->getPost('sa_name')),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('success', '판매 대행소가 수정되었습니다.');
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('success', '판매 대행소가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->model->find($id);
|
||||
if (!$item || (int) $item->sa_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$item = $this->model->find($id);
|
||||
if (! $item || ! $lgIdx || (int) $item->sa_lg_idx !== $lgIdx) {
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('error', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('success', '판매 대행소가 삭제되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('sales-agencies'))->with('success', '삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user