P2-07~14 판매대행소/담당자/업체/무료대상자 CRUD 일괄 구현
- 4개 테이블 생성 (sales_agency, manager, company, free_recipient) - 4개 Model + 4개 Controller + 12개 View - 담당자: 소속(S)/직위(T) 코드 연동 - 업체: 협회/제작업체/회수업체 유형 분류 - 무료대상자: 무상지급구분(H)/동코드(D) 연동 - 모두 지자체별 멀티테넌시 적용 - 24개 라우트 추가 - E2E 테스트 9개 전체 통과 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
126
app/Controllers/Admin/Company.php
Normal file
126
app/Controllers/Admin/Company.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\CompanyModel;
|
||||
|
||||
class Company extends BaseController
|
||||
{
|
||||
private CompanyModel $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = model(CompanyModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('cp_lg_idx', $lgIdx)->orderBy('cp_idx', 'DESC')->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 관리',
|
||||
'content' => view('admin/company/index', ['list' => $list]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 등록',
|
||||
'content' => view('admin/company/create'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
$rules = [
|
||||
'cp_type' => 'required|in_list[협회,제작업체,회수업체]',
|
||||
'cp_name' => 'required|max_length[100]',
|
||||
'cp_biz_no' => 'permit_empty|max_length[20]',
|
||||
'cp_rep_name' => 'permit_empty|max_length[50]',
|
||||
'cp_tel' => 'permit_empty|max_length[20]',
|
||||
'cp_addr' => 'permit_empty|max_length[255]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->insert([
|
||||
'cp_lg_idx' => admin_effective_lg_idx(),
|
||||
'cp_type' => $this->request->getPost('cp_type'),
|
||||
'cp_name' => $this->request->getPost('cp_name'),
|
||||
'cp_biz_no' => $this->request->getPost('cp_biz_no') ?? '',
|
||||
'cp_rep_name' => $this->request->getPost('cp_rep_name') ?? '',
|
||||
'cp_tel' => $this->request->getPost('cp_tel') ?? '',
|
||||
'cp_addr' => $this->request->getPost('cp_addr') ?? '',
|
||||
'cp_state' => 1,
|
||||
'cp_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '업체 수정',
|
||||
'content' => view('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', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'cp_type' => 'required|in_list[협회,제작업체,회수업체]',
|
||||
'cp_name' => 'required|max_length[100]',
|
||||
'cp_state' => 'required|in_list[0,1]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->update($id, [
|
||||
'cp_type' => $this->request->getPost('cp_type'),
|
||||
'cp_name' => $this->request->getPost('cp_name'),
|
||||
'cp_biz_no' => $this->request->getPost('cp_biz_no') ?? '',
|
||||
'cp_rep_name' => $this->request->getPost('cp_rep_name') ?? '',
|
||||
'cp_tel' => $this->request->getPost('cp_tel') ?? '',
|
||||
'cp_addr' => $this->request->getPost('cp_addr') ?? '',
|
||||
'cp_state' => (int) $this->request->getPost('cp_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '업체를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/companies'))->with('success', '업체가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
139
app/Controllers/Admin/FreeRecipient.php
Normal file
139
app/Controllers/Admin/FreeRecipient.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\FreeRecipientModel;
|
||||
use App\Models\CodeKindModel;
|
||||
use App\Models\CodeDetailModel;
|
||||
|
||||
class FreeRecipient extends BaseController
|
||||
{
|
||||
private FreeRecipientModel $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = model(FreeRecipientModel::class);
|
||||
}
|
||||
|
||||
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) : [];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('fr_lg_idx', $lgIdx)->orderBy('fr_idx', 'DESC')->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 관리',
|
||||
'content' => view('admin/free_recipient/index', ['list' => $list]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 등록',
|
||||
'content' => view('admin/free_recipient/create', [
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
$rules = [
|
||||
'fr_type_code' => 'required|max_length[20]',
|
||||
'fr_name' => 'required|max_length[100]',
|
||||
'fr_end_date' => 'permit_empty|valid_date[Y-m-d]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->insert([
|
||||
'fr_lg_idx' => admin_effective_lg_idx(),
|
||||
'fr_type_code' => $this->request->getPost('fr_type_code'),
|
||||
'fr_name' => $this->request->getPost('fr_name'),
|
||||
'fr_phone' => $this->request->getPost('fr_phone') ?? '',
|
||||
'fr_addr' => $this->request->getPost('fr_addr') ?? '',
|
||||
'fr_dong_code' => $this->request->getPost('fr_dong_code') ?? '',
|
||||
'fr_note' => $this->request->getPost('fr_note') ?? '',
|
||||
'fr_end_date' => $this->request->getPost('fr_end_date') ?: null,
|
||||
'fr_state' => 1,
|
||||
'fr_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 대상자 수정',
|
||||
'content' => view('admin/free_recipient/edit', [
|
||||
'item' => $item,
|
||||
'typeCodes' => $this->getCodeOptions('H'),
|
||||
'dongCodes' => $this->getCodeOptions('D'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(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', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'fr_name' => 'required|max_length[100]',
|
||||
'fr_state' => 'required|in_list[0,1]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->update($id, [
|
||||
'fr_type_code' => $this->request->getPost('fr_type_code') ?? $item->fr_type_code,
|
||||
'fr_name' => $this->request->getPost('fr_name'),
|
||||
'fr_phone' => $this->request->getPost('fr_phone') ?? '',
|
||||
'fr_addr' => $this->request->getPost('fr_addr') ?? '',
|
||||
'fr_dong_code' => $this->request->getPost('fr_dong_code') ?? '',
|
||||
'fr_note' => $this->request->getPost('fr_note') ?? '',
|
||||
'fr_end_date' => $this->request->getPost('fr_end_date') ?: null,
|
||||
'fr_state' => (int) $this->request->getPost('fr_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '대상자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/free-recipients'))->with('success', '무료용 대상자가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
138
app/Controllers/Admin/Manager.php
Normal file
138
app/Controllers/Admin/Manager.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\ManagerModel;
|
||||
use App\Models\CodeKindModel;
|
||||
use App\Models\CodeDetailModel;
|
||||
|
||||
class Manager extends BaseController
|
||||
{
|
||||
private ManagerModel $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = model(ManagerModel::class);
|
||||
}
|
||||
|
||||
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) : [];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('mg_lg_idx', $lgIdx)->orderBy('mg_idx', 'DESC')->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '담당자 관리',
|
||||
'content' => view('admin/manager/index', ['list' => $list]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '담당자 등록',
|
||||
'content' => view('admin/manager/create', [
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
$rules = [
|
||||
'mg_name' => 'required|max_length[50]',
|
||||
'mg_tel' => 'permit_empty|max_length[20]',
|
||||
'mg_phone' => 'permit_empty|max_length[20]',
|
||||
'mg_email' => 'permit_empty|valid_email|max_length[100]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->insert([
|
||||
'mg_lg_idx' => admin_effective_lg_idx(),
|
||||
'mg_name' => $this->request->getPost('mg_name'),
|
||||
'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '',
|
||||
'mg_position_code' => $this->request->getPost('mg_position_code') ?? '',
|
||||
'mg_tel' => $this->request->getPost('mg_tel') ?? '',
|
||||
'mg_phone' => $this->request->getPost('mg_phone') ?? '',
|
||||
'mg_email' => $this->request->getPost('mg_email') ?? '',
|
||||
'mg_state' => 1,
|
||||
'mg_regdate' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$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 view('admin/layout', [
|
||||
'title' => '담당자 수정',
|
||||
'content' => view('admin/manager/edit', [
|
||||
'item' => $item,
|
||||
'deptCodes' => $this->getCodeOptions('S'),
|
||||
'positionCodes' => $this->getCodeOptions('T'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$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', '담당자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'mg_name' => 'required|max_length[50]',
|
||||
'mg_state' => 'required|in_list[0,1]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->model->update($id, [
|
||||
'mg_name' => $this->request->getPost('mg_name'),
|
||||
'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '',
|
||||
'mg_position_code' => $this->request->getPost('mg_position_code') ?? '',
|
||||
'mg_tel' => $this->request->getPost('mg_tel') ?? '',
|
||||
'mg_phone' => $this->request->getPost('mg_phone') ?? '',
|
||||
'mg_email' => $this->request->getPost('mg_email') ?? '',
|
||||
'mg_state' => (int) $this->request->getPost('mg_state'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$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', '담당자를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/managers'))->with('success', '담당자가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
122
app/Controllers/Admin/SalesAgency.php
Normal file
122
app/Controllers/Admin/SalesAgency.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\SalesAgencyModel;
|
||||
|
||||
class SalesAgency extends BaseController
|
||||
{
|
||||
private SalesAgencyModel $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = model(SalesAgencyModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$list = $this->model->where('sa_lg_idx', $lgIdx)->orderBy('sa_idx', 'DESC')->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 관리',
|
||||
'content' => view('admin/sales_agency/index', ['list' => $list]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 등록',
|
||||
'content' => view('admin/sales_agency/create'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
helper('admin');
|
||||
$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]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$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'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '판매 대행소 수정',
|
||||
'content' => view('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', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'sa_name' => 'required|max_length[100]',
|
||||
'sa_state' => 'required|in_list[0,1]',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$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'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/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', '대행소를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return redirect()->to(site_url('admin/sales-agencies'))->with('success', '판매 대행소가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user