diff --git a/app/Controllers/Admin/CodeDetail.php b/app/Controllers/Admin/CodeDetail.php index 919c5d0..d0ec40a 100644 --- a/app/Controllers/Admin/CodeDetail.php +++ b/app/Controllers/Admin/CodeDetail.php @@ -7,6 +7,7 @@ namespace App\Controllers\Admin; use App\Controllers\BaseController; use App\Models\CodeKindModel; use App\Models\CodeDetailModel; +use App\Models\LocalGovernmentModel; use CodeIgniter\HTTP\RedirectResponse; use Config\Roles; @@ -47,9 +48,22 @@ class CodeDetail extends BaseController return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 종류를 찾을 수 없습니다.'); } + $level = (int) session()->get('mb_level'); + $canPlatformScope = Roles::isSuperAdminEquivalent($level); + $govs = $canPlatformScope + ? model(LocalGovernmentModel::class)->where('lg_state', 1)->orderBy('lg_name', 'ASC')->findAll() + : []; + + helper('admin'); + return view('admin/layout', [ 'title' => '세부코드 등록 — ' . $kind->ck_name, - 'content' => view('admin/code_detail/create', ['kind' => $kind]), + 'content' => view('admin/code_detail/create', [ + 'kind' => $kind, + 'canPlatformScope' => $canPlatformScope, + 'localGovernments' => $govs, + 'effectiveLgIdx' => admin_effective_lg_idx(), + ]), ]); } @@ -71,10 +85,50 @@ class CodeDetail extends BaseController } $ckIdx = (int) $this->request->getPost('cd_ck_idx'); + $kind = $this->kindModel->find($ckIdx); + if ($kind === null) { + return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 종류를 찾을 수 없습니다.'); + } + + helper('admin'); + $level = (int) session()->get('mb_level'); + + if (Roles::isSuperAdminEquivalent($level)) { + $scope = $this->request->getPost('cd_scope') === 'local' ? 'local' : 'platform'; + if ($scope === 'platform') { + $cdSource = 'platform'; + $cdLgIdx = 0; + } else { + $cdLgIdx = (int) $this->request->getPost('cd_lg_idx'); + if ($cdLgIdx < 1) { + return redirect()->back()->withInput()->with('error', '지자체 전용인 경우 소속 지자체를 선택해 주세요.'); + } + $gov = model(LocalGovernmentModel::class)->find($cdLgIdx); + if ($gov === null) { + return redirect()->back()->withInput()->with('error', '유효하지 않은 지자체입니다.'); + } + $cdSource = 'local'; + } + } else { + $lg = admin_effective_lg_idx(); + if ($lg === null || (int) $lg < 1) { + return redirect()->to(site_url('bag/code-kinds'))->with('error', '지자체를 선택한 뒤 등록해 주세요.'); + } + $cdSource = 'local'; + $cdLgIdx = (int) $lg; + } + + $cdCode = (string) $this->request->getPost('cd_code'); + $dup = $this->detailModel->where('cd_ck_idx', $ckIdx)->where('cd_code', $cdCode)->where('cd_lg_idx', $cdLgIdx)->first(); + if ($dup !== null) { + return redirect()->back()->withInput()->with('error', '같은 종류·코드값·소속 범위에 이미 등록된 행이 있습니다.'); + } $this->detailModel->insert([ 'cd_ck_idx' => $ckIdx, - 'cd_code' => $this->request->getPost('cd_code'), + 'cd_source' => $cdSource, + 'cd_lg_idx' => $cdLgIdx, + 'cd_code' => $cdCode, 'cd_name' => $this->request->getPost('cd_name'), 'cd_sort' => (int) ($this->request->getPost('cd_sort') ?: 0), 'cd_state' => 1, @@ -95,6 +149,11 @@ class CodeDetail extends BaseController return redirect()->to(site_url('bag/code-kinds'))->with('error', '세부코드를 찾을 수 없습니다.'); } + helper('admin'); + if (! Roles::canEditCodeDetailRow((int) session()->get('mb_level'), $item, admin_effective_lg_idx())) { + return redirect()->to(site_url('bag/code-details/' . $item->cd_ck_idx))->with('error', '이 세부코드를 수정할 권한이 없습니다.'); + } + $kind = $this->kindModel->find($item->cd_ck_idx); return view('admin/layout', [ @@ -117,6 +176,11 @@ class CodeDetail extends BaseController return redirect()->to(site_url('bag/code-kinds'))->with('error', '세부코드를 찾을 수 없습니다.'); } + helper('admin'); + if (! Roles::canEditCodeDetailRow((int) session()->get('mb_level'), $item, admin_effective_lg_idx())) { + return redirect()->to(site_url('bag/code-details/' . $item->cd_ck_idx))->with('error', '이 세부코드를 수정할 권한이 없습니다.'); + } + $rules = [ 'cd_name' => 'required|max_length[100]', 'cd_sort' => 'permit_empty|is_natural', @@ -147,6 +211,11 @@ class CodeDetail extends BaseController return redirect()->to(site_url('bag/code-kinds'))->with('error', '세부코드를 찾을 수 없습니다.'); } + helper('admin'); + if (! Roles::canEditCodeDetailRow((int) session()->get('mb_level'), $item, admin_effective_lg_idx())) { + return redirect()->to(site_url('bag/code-details/' . $item->cd_ck_idx))->with('error', '이 세부코드를 삭제할 권한이 없습니다.'); + } + $ckIdx = $item->cd_ck_idx; $this->detailModel->delete($id); diff --git a/app/Controllers/Admin/CodeKind.php b/app/Controllers/Admin/CodeKind.php index 5a128a8..d3577a2 100644 --- a/app/Controllers/Admin/CodeKind.php +++ b/app/Controllers/Admin/CodeKind.php @@ -19,10 +19,10 @@ class CodeKind extends BaseController $this->kindModel = model(CodeKindModel::class); } - private function redirectIfCannotManageCodeMaster(): ?RedirectResponse + private function redirectIfCannotManageCodeKindMaster(): ?RedirectResponse { - if (! Roles::canManageCodeMaster((int) session()->get('mb_level'))) { - return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 관리 권한이 없습니다.'); + if (! Roles::canManageCodeKindMaster((int) session()->get('mb_level'))) { + return redirect()->to(site_url('bag/code-kinds'))->with('error', '코드 종류는 super admin·본부 관리자만 관리할 수 있습니다.'); } return null; @@ -30,7 +30,7 @@ class CodeKind extends BaseController public function create() { - if ($r = $this->redirectIfCannotManageCodeMaster()) { + if ($r = $this->redirectIfCannotManageCodeKindMaster()) { return $r; } @@ -42,7 +42,7 @@ class CodeKind extends BaseController public function store() { - if ($r = $this->redirectIfCannotManageCodeMaster()) { + if ($r = $this->redirectIfCannotManageCodeKindMaster()) { return $r; } @@ -67,7 +67,7 @@ class CodeKind extends BaseController public function edit(int $id) { - if ($r = $this->redirectIfCannotManageCodeMaster()) { + if ($r = $this->redirectIfCannotManageCodeKindMaster()) { return $r; } @@ -84,7 +84,7 @@ class CodeKind extends BaseController public function update(int $id) { - if ($r = $this->redirectIfCannotManageCodeMaster()) { + if ($r = $this->redirectIfCannotManageCodeKindMaster()) { return $r; } @@ -112,7 +112,7 @@ class CodeKind extends BaseController public function delete(int $id) { - if ($r = $this->redirectIfCannotManageCodeMaster()) { + if ($r = $this->redirectIfCannotManageCodeKindMaster()) { return $r; } diff --git a/app/Controllers/Admin/Company.php b/app/Controllers/Admin/Company.php index 36d22ee..8492574 100644 --- a/app/Controllers/Admin/Company.php +++ b/app/Controllers/Admin/Company.php @@ -18,25 +18,19 @@ 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); + $list = $this->model->where('cp_lg_idx', $lgIdx)->orderBy('cp_idx', 'DESC')->paginate(20); $pager = $this->model->pager; - return view('admin/layout', [ - 'title' => '업체 관리', - 'content' => view('admin/company/index', ['list' => $list, 'pager' => $pager]), - ]); + return $this->renderWorkPage('업체 관리', 'admin/company/index', ['list' => $list, 'pager' => $pager]); } public function create() { - return view('admin/layout', [ - 'title' => '업체 등록', - 'content' => view('admin/company/create'), - ]); + return $this->renderWorkPage('업체 등록', 'admin/company/create'); } public function store() @@ -66,29 +60,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 +101,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', '업체가 삭제되었습니다.'); } } diff --git a/app/Controllers/Admin/DesignatedShop.php b/app/Controllers/Admin/DesignatedShop.php index 32c3649..d29d8ba 100644 --- a/app/Controllers/Admin/DesignatedShop.php +++ b/app/Controllers/Admin/DesignatedShop.php @@ -39,7 +39,7 @@ class DesignatedShop extends BaseController $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin')) + return redirect()->to(work_area_home_url()) ->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.'); } @@ -73,17 +73,14 @@ class DesignatedShop extends BaseController $db = \Config\Database::connect(); $gugunCodes = $db->query("SELECT DISTINCT ds_gugun_code FROM designated_shop WHERE ds_lg_idx = ? AND ds_gugun_code != '' ORDER BY ds_gugun_code", [$lgIdx])->getResult(); - return view('admin/layout', [ - 'title' => '지정판매소 관리', - 'content' => view('admin/designated_shop/index', [ - 'list' => $list, - 'lgMap' => $lgMap, - 'pager' => $pager, - 'dsName' => $dsName ?? '', - 'dsGugunCode' => $dsGugunCode ?? '', - 'dsState' => $dsState ?? '', - 'gugunCodes' => $gugunCodes, - ]), + return $this->renderWorkPage('지정판매소 관리', 'admin/designated_shop/index', [ + 'list' => $list, + 'lgMap' => $lgMap, + 'pager' => $pager, + 'dsName' => $dsName ?? '', + 'dsGugunCode' => $dsGugunCode ?? '', + 'dsState' => $dsState ?? '', + 'gugunCodes' => $gugunCodes, ]); } @@ -92,7 +89,7 @@ class DesignatedShop extends BaseController helper(['admin', 'export']); $lgIdx = admin_effective_lg_idx(); if (!$lgIdx) { - return redirect()->to(site_url('admin/designated-shops'))->with('error', '지자체를 선택해 주세요.'); + return redirect()->to(mgmt_url('designated-shops'))->with('error', '지자체를 선택해 주세요.'); } $list = $this->shopModel->where('ds_lg_idx', $lgIdx)->orderBy('ds_idx', 'DESC')->findAll(); @@ -129,22 +126,19 @@ class DesignatedShop extends BaseController helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.'); } $currentLg = $this->lgModel->find($lgIdx); if ($currentLg === null) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '선택한 지자체 정보를 찾을 수 없습니다.'); } - return view('admin/layout', [ - 'title' => '지정판매소 등록', - 'content' => view('admin/designated_shop/create', [ - 'localGovs' => [], - 'currentLg' => $currentLg, - ]), + return $this->renderWorkPage('지정판매소 등록', 'admin/designated_shop/create', [ + 'localGovs' => [], + 'currentLg' => $currentLg, ]); } @@ -154,7 +148,7 @@ class DesignatedShop extends BaseController public function store() { if (! $this->isSuperAdmin() && ! $this->isLocalAdmin()) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '지정판매소 등록은 관리자만 가능합니다.'); } @@ -211,7 +205,7 @@ class DesignatedShop extends BaseController $this->shopModel->insert($data); - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('success', '지정판매소가 등록되었습니다.'); } @@ -222,31 +216,28 @@ class DesignatedShop extends BaseController public function edit(int $id) { if (! $this->isSuperAdmin() && ! $this->isLocalAdmin()) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '권한이 없습니다.'); } helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '작업할 지자체가 선택되지 않았습니다.'); } $shop = $this->shopModel->find($id); if ($shop === null || (int) $shop->ds_lg_idx !== $lgIdx) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '해당 지정판매소를 찾을 수 없거나 수정할 수 없습니다.'); } $currentLg = $this->lgModel->find($lgIdx); - return view('admin/layout', [ - 'title' => '지정판매소 수정', - 'content' => view('admin/designated_shop/edit', [ - 'shop' => $shop, - 'currentLg' => $currentLg, - ]), + return $this->renderWorkPage('지정판매소 수정', 'admin/designated_shop/edit', [ + 'shop' => $shop, + 'currentLg' => $currentLg, ]); } @@ -256,20 +247,20 @@ class DesignatedShop extends BaseController public function update(int $id) { if (! $this->isSuperAdmin() && ! $this->isLocalAdmin()) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '권한이 없습니다.'); } helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '작업할 지자체가 선택되지 않았습니다.'); } $shop = $this->shopModel->find($id); if ($shop === null || (int) $shop->ds_lg_idx !== $lgIdx) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '해당 지정판매소를 찾을 수 없거나 수정할 수 없습니다.'); } @@ -305,7 +296,7 @@ class DesignatedShop extends BaseController $this->shopModel->update($id, $data); - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('success', '지정판매소 정보가 수정되었습니다.'); } @@ -316,26 +307,26 @@ class DesignatedShop extends BaseController public function delete(int $id) { if (! $this->isSuperAdmin() && ! $this->isLocalAdmin()) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '권한이 없습니다.'); } helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '작업할 지자체가 선택되지 않았습니다.'); } $shop = $this->shopModel->find($id); if ($shop === null || (int) $shop->ds_lg_idx !== $lgIdx) { - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('error', '해당 지정판매소를 찾을 수 없거나 삭제할 수 없습니다.'); } $this->shopModel->delete($id); - return redirect()->to(site_url('admin/designated-shops')) + return redirect()->to(mgmt_url('designated-shops')) ->with('success', '지정판매소가 삭제되었습니다.'); } @@ -347,7 +338,7 @@ class DesignatedShop extends BaseController helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin')) + return redirect()->to(work_area_home_url()) ->with('error', '작업할 지자체가 선택되지 않았습니다.'); } @@ -356,11 +347,8 @@ class DesignatedShop extends BaseController ->where('ds_state', 1) ->findAll(); - return view('admin/layout', [ - 'title' => '지정판매소 지도', - 'content' => view('admin/designated_shop/map', [ - 'shops' => $shops, - ]), + return $this->renderWorkPage('지정판매소 지도', 'admin/designated_shop/map', [ + 'shops' => $shops, ]); } @@ -372,7 +360,7 @@ class DesignatedShop extends BaseController helper('admin'); $lgIdx = admin_effective_lg_idx(); if ($lgIdx === null || $lgIdx <= 0) { - return redirect()->to(site_url('admin')) + return redirect()->to(work_area_home_url()) ->with('error', '작업할 지자체가 선택되지 않았습니다.'); } @@ -400,14 +388,11 @@ class DesignatedShop extends BaseController $totalActive = $this->shopModel->where('ds_lg_idx', $lgIdx)->where('ds_state', 1)->countAllResults(false); $totalInactive = $this->shopModel->where('ds_lg_idx', $lgIdx)->where('ds_state !=', 1)->countAllResults(false); - return view('admin/layout', [ - 'title' => '지정판매소 현황', - 'content' => view('admin/designated_shop/status', [ - 'newByYear' => $newByYear, - 'cancelByYear' => $cancelByYear, - 'totalActive' => $totalActive, - 'totalInactive' => $totalInactive, - ]), + return $this->renderWorkPage('지정판매소 현황', 'admin/designated_shop/status', [ + 'newByYear' => $newByYear, + 'cancelByYear' => $cancelByYear, + 'totalActive' => $totalActive, + 'totalInactive' => $totalInactive, ]); } diff --git a/app/Controllers/Admin/FreeRecipient.php b/app/Controllers/Admin/FreeRecipient.php index 79448ce..dd8da1b 100644 --- a/app/Controllers/Admin/FreeRecipient.php +++ b/app/Controllers/Admin/FreeRecipient.php @@ -18,35 +18,32 @@ 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); + $list = $this->model->where('fr_lg_idx', $lgIdx)->orderBy('fr_idx', 'DESC')->paginate(20); $pager = $this->model->pager; - return view('admin/layout', [ - 'title' => '무료용 대상자 관리', - 'content' => view('admin/free_recipient/index', ['list' => $list, 'pager' => $pager]), - ]); + return $this->renderWorkPage('무료용 대상자 관리', 'admin/free_recipient/index', ['list' => $list, 'pager' => $pager]); } 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 +72,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 +94,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 +117,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', '무료용 대상자가 삭제되었습니다.'); } } diff --git a/app/Controllers/Admin/Manager.php b/app/Controllers/Admin/Manager.php index c3bce32..4e2b7ab 100644 --- a/app/Controllers/Admin/Manager.php +++ b/app/Controllers/Admin/Manager.php @@ -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,28 @@ 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; - return view('admin/layout', [ - 'title' => '담당자 관리', - 'content' => view('admin/manager/index', ['list' => $list, 'pager' => $pager]), - ]); + return $this->renderWorkPage('담당자 관리', 'admin/manager/index', ['list' => $list, 'pager' => $pager]); } 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 +74,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 +118,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', '담당자가 삭제되었습니다.'); } } diff --git a/app/Controllers/Admin/SalesAgency.php b/app/Controllers/Admin/SalesAgency.php index 08befa7..ed75380 100644 --- a/app/Controllers/Admin/SalesAgency.php +++ b/app/Controllers/Admin/SalesAgency.php @@ -1,5 +1,7 @@ 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); + $list = $this->model->where('sa_lg_idx', $lgIdx)->orderForDisplay()->paginate(20); $pager = $this->model->pager; - return view('admin/layout', [ - 'title' => '판매 대행소 관리', - 'content' => view('admin/sales_agency/index', ['list' => $list, 'pager' => $pager]), - ]); + return $this->renderWorkPage('판매 대행소 관리', 'admin/sales_agency/index', ['list' => $list, 'pager' => $pager]); } 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', '삭제되었습니다.'); } } diff --git a/app/Controllers/Admin/User.php b/app/Controllers/Admin/User.php index 87db294..3e5e450 100644 --- a/app/Controllers/Admin/User.php +++ b/app/Controllers/Admin/User.php @@ -121,8 +121,10 @@ class User extends BaseController if (! $member) { return redirect()->to(site_url('admin/users'))->with('error', '회원을 찾을 수 없습니다.'); } - $member->mb_email = pii_decrypt($member->mb_email ?? ''); - $member->mb_phone = pii_decrypt($member->mb_phone ?? ''); + $email = pii_decrypt($member->mb_email ?? ''); + $phone = pii_decrypt($member->mb_phone ?? ''); + $member->mb_email = $email; + $member->mb_phone = $phone; return view('admin/layout', [ 'title' => '회원 수정', 'content' => view('admin/user/edit', [ diff --git a/app/Models/CodeDetailModel.php b/app/Models/CodeDetailModel.php index 268069c..76ebe11 100644 --- a/app/Models/CodeDetailModel.php +++ b/app/Models/CodeDetailModel.php @@ -1,5 +1,7 @@ where('cd_ck_idx', $ckIdx); - if ($activeOnly) { - $builder->where('cd_state', 1); + if ($effectiveLgIdx === null || $effectiveLgIdx < 1) { + return $this->where('cd_lg_idx', 0); } - return $builder->orderBy('cd_sort', 'ASC')->findAll(); + + return $this->groupStart() + ->where('cd_lg_idx', 0) + ->orWhere('cd_lg_idx', $effectiveLgIdx) + ->groupEnd(); + } + + /** + * 특정 코드 종류의 세부코드 목록 + * + * @param int|null $effectiveLgIdx 테넌트 범위 (null=플랫폼만) + */ + public function getByKind(int $ckIdx, bool $activeOnly = false, ?int $effectiveLgIdx = null): array + { + $this->where('cd_ck_idx', $ckIdx); + $this->filterByTenantScope($effectiveLgIdx); + if ($activeOnly) { + $this->where('cd_state', 1); + } + + return $this->orderBy('cd_sort', 'ASC')->orderBy('cd_idx', 'ASC')->findAll(); + } + + /** + * 동일 세부코드값: 지자체 전용이 있으면 우선, 없으면 플랫폼 + */ + public function findResolvedByKindAndCode(int $ckIdx, string $code, ?int $effectiveLgIdx): ?object + { + if ($effectiveLgIdx !== null && $effectiveLgIdx > 0) { + $local = $this->where('cd_ck_idx', $ckIdx)->where('cd_code', $code)->where('cd_lg_idx', $effectiveLgIdx)->first(); + if ($local !== null) { + return $local; + } + } + + return $this->where('cd_ck_idx', $ckIdx)->where('cd_code', $code)->where('cd_lg_idx', 0)->first(); } } diff --git a/app/Models/SalesAgencyModel.php b/app/Models/SalesAgencyModel.php index 8707266..2c9b54b 100644 --- a/app/Models/SalesAgencyModel.php +++ b/app/Models/SalesAgencyModel.php @@ -1,5 +1,7 @@ getFieldNames($this->table); + $cache = in_array('sa_kind', $cols, true) && in_array('sa_code', $cols, true); + } + + return $cache; + } + + /** + * 신규 스키마면 구분·코드 순, 아니면 명·PK 순(옛 DB 호환). + * + * @return $this + */ + public function orderForDisplay() + { + return $this->hasKindCodeColumns() + ? $this->orderBy('sa_kind', 'ASC')->orderBy('sa_code', 'ASC') + : $this->orderBy('sa_name', 'ASC')->orderBy('sa_idx', 'ASC'); + } } diff --git a/app/Views/admin/code_detail/create.php b/app/Views/admin/code_detail/create.php index 20b035c..5f653fb 100644 --- a/app/Views/admin/code_detail/create.php +++ b/app/Views/admin/code_detail/create.php @@ -30,6 +30,39 @@ + +
등록 범위
+ + +