2026-03-25 17:41:15 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
|
use App\Models\CompanyModel;
|
|
|
|
|
|
|
|
|
|
class Company extends BaseController
|
|
|
|
|
{
|
|
|
|
|
private CompanyModel $model;
|
|
|
|
|
|
2026-04-22 15:35:28 +09:00
|
|
|
private function companyTypeOptions(): array
|
|
|
|
|
{
|
|
|
|
|
return ['협회', '제작업체', '회수업체'];
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 17:41:15 +09:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->model = model(CompanyModel::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
helper('admin');
|
|
|
|
|
$lgIdx = admin_effective_lg_idx();
|
2026-04-08 00:19:00 +09:00
|
|
|
if (! $lgIdx) {
|
|
|
|
|
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 15:35:28 +09:00
|
|
|
$companyType = trim((string) ($this->request->getGet('cp_type') ?? ''));
|
|
|
|
|
$typeOptions = $this->companyTypeOptions();
|
|
|
|
|
|
|
|
|
|
$builder = $this->model->where('cp_lg_idx', $lgIdx);
|
|
|
|
|
if ($companyType !== '' && in_array($companyType, $typeOptions, true)) {
|
|
|
|
|
$builder->where('cp_type', $companyType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list = $builder->orderBy('cp_idx', 'DESC')->paginate(20);
|
2026-03-26 16:40:49 +09:00
|
|
|
$pager = $this->model->pager;
|
2026-03-25 17:41:15 +09:00
|
|
|
|
2026-04-22 15:35:28 +09:00
|
|
|
$queryForPager = [];
|
|
|
|
|
if ($companyType !== '' && in_array($companyType, $typeOptions, true)) {
|
|
|
|
|
$queryForPager['cp_type'] = $companyType;
|
|
|
|
|
}
|
|
|
|
|
$pagerPath = mgmt_url('companies');
|
|
|
|
|
if ($queryForPager !== []) {
|
|
|
|
|
$pagerPath .= '?' . http_build_query($queryForPager);
|
|
|
|
|
}
|
|
|
|
|
$pager->setPath($pagerPath);
|
|
|
|
|
|
|
|
|
|
return $this->renderWorkPage('업체 관리', 'admin/company/index', [
|
|
|
|
|
'list' => $list,
|
|
|
|
|
'pager' => $pager,
|
|
|
|
|
'cpType' => $companyType,
|
|
|
|
|
'typeOptions' => $typeOptions,
|
|
|
|
|
]);
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
2026-04-08 00:19:00 +09:00
|
|
|
return $this->renderWorkPage('업체 등록', 'admin/company/create');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-08 00:19:00 +09:00
|
|
|
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 등록되었습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function edit(int $id)
|
|
|
|
|
{
|
|
|
|
|
helper('admin');
|
|
|
|
|
$item = $this->model->find($id);
|
2026-04-08 00:19:00 +09:00
|
|
|
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
|
|
|
|
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
2026-04-08 00:19:00 +09:00
|
|
|
return $this->renderWorkPage('업체 수정', 'admin/company/edit', ['item' => $item]);
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(int $id)
|
|
|
|
|
{
|
|
|
|
|
helper('admin');
|
|
|
|
|
$item = $this->model->find($id);
|
2026-04-08 00:19:00 +09:00
|
|
|
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
|
|
|
|
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-08 00:19:00 +09:00
|
|
|
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 수정되었습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delete(int $id)
|
|
|
|
|
{
|
|
|
|
|
helper('admin');
|
|
|
|
|
$item = $this->model->find($id);
|
2026-04-08 00:19:00 +09:00
|
|
|
if (! $item || (int) $item->cp_lg_idx !== admin_effective_lg_idx()) {
|
|
|
|
|
return redirect()->to(mgmt_url('companies'))->with('error', '업체를 찾을 수 없습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->model->delete($id);
|
2026-04-08 00:19:00 +09:00
|
|
|
|
|
|
|
|
return redirect()->to(mgmt_url('companies'))->with('success', '업체가 삭제되었습니다.');
|
2026-03-25 17:41:15 +09:00
|
|
|
}
|
|
|
|
|
}
|