From c43a16ed7928f3e4bb746a2183d98a06a5c0da2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E7=9A=84=E5=90=8D=E5=AD=97?= <你的邮箱> Date: Fri, 19 Sep 2025 17:52:34 +0900 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E3=82=B7=E3=83=BC=E3=83=AB=E7=99=BA?= =?UTF-8?q?=E8=A1=8C=E5=B1=A5=E6=AD=B4=E3=80=91=E3=83=97=E3=83=AB=E3=83=80?= =?UTF-8?q?=E3=82=A6=E3=83=B3=E5=86=85=E5=AE=B9=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/SealsController.php | 115 +++++++++--------- resources/views/admin/seals/list.blade.php | 52 ++++---- 2 files changed, 87 insertions(+), 80 deletions(-) diff --git a/app/Http/Controllers/Admin/SealsController.php b/app/Http/Controllers/Admin/SealsController.php index 51fb689..a3266d2 100644 --- a/app/Http/Controllers/Admin/SealsController.php +++ b/app/Http/Controllers/Admin/SealsController.php @@ -10,66 +10,69 @@ class SealsController extends Controller { public function list(Request $request) { - // ソート用パラメータ取得(指定がなければnull) - $sort = $request->input('sort'); - $sort_type = $request->input('sort_type', 'asc'); + $q = \DB::table('seal as s') + ->leftJoin('park as p','s.park_id','=','p.park_id') + ->leftJoin('regular_contract as rc','s.contract_id','=','rc.contract_id') + ->leftJoin('psection as ps','rc.psection_id','=','ps.psection_id') + ->select([ + 's.seal_issueid', + 's.park_id', + 'p.park_name', + 's.contract_id', + 'rc.psection_id', + \DB::raw('ps.psection_subject AS psection_subject'), + 'rc.contract_seal_issue', + 's.seal_day', + 's.seal_reason', + ]); - // sealテーブルを参照し、フィルター - $query = DB::table('seal'); - - // フィルター:発行日 - $periodType = $request->input('period_type'); - $recentPeriod = $request->input('recent_period'); - $sealDayFrom = $request->input('seal_day_from'); - $sealDayTo = $request->input('seal_day_to'); - - if ($periodType === 'range' && $sealDayFrom && $sealDayTo) { - $query->whereBetween('seal_day', [$sealDayFrom, $sealDayTo]); - } elseif ($periodType === 'recent' && $recentPeriod) { - $now = date('Y-m-d'); - switch ($recentPeriod) { - case '12m': - $from = date('Y-m-d', strtotime('-12 months', strtotime($now))); - break; - case '6m': - $from = date('Y-m-d', strtotime('-6 months', strtotime($now))); - break; - case '3m': - $from = date('Y-m-d', strtotime('-3 months', strtotime($now))); - break; - case '2m': - $from = date('Y-m-d', strtotime('-2 months', strtotime($now))); - break; - case '1m': - $from = date('Y-m-d', strtotime('-1 months', strtotime($now))); - break; - case '1w': - $from = date('Y-m-d', strtotime('-1 week', strtotime($now))); - break; - default: - $from = null; - } - if (isset($from)) { - $query->where('seal_day', '>=', $from); - } - } else { - // デフォルト:直近3ヶ月 - $now = date('Y-m-d'); - $from = date('Y-m-d', strtotime('-3 months', strtotime($now))); - $query->where('seal_day', '>=', $from); + // 駐輪場フィルタ + if($request->filled('park_id')){ + $q->where('s.park_id',$request->park_id); } - // ソート指定があればorderBy、なければDB物理順 - if ($sort) { - $list = $query->orderBy($sort, $sort_type)->paginate(20); - } else { - $list = $query->paginate(20); + // 期間フィルタ + $periodType = $request->input('period_type','range'); + if($periodType === 'range'){ + if($request->filled('seal_day_from')){ + $q->whereDate('s.seal_day','>=',$request->seal_day_from); + } + if($request->filled('seal_day_to')){ + $q->whereDate('s.seal_day','<=',$request->seal_day_to); + } + } elseif($periodType === 'recent' && $request->filled('recent_period')){ + $map = ['12m'=>12,'6m'=>6,'3m'=>3,'2m'=>2,'1m'=>1,'1w'=>'1w']; + $key = $request->recent_period; + if(isset($map[$key])){ + $from = $key==='1w' ? now()->subWeek() : now()->subMonths($map[$key]); + $q->where('s.seal_day','>=',$from->toDateString()); + } } - return view('admin.seals.list', [ - 'list' => $list, - 'sort' => $sort, - 'sort_type' => $sort_type, - ]); + // --- 並び替え: パラメータがある場合のみ適用 --- + $sort = $request->query('sort'); // デフォルト null + $sortType = $request->query('sort_type','asc'); // 指定なければ asc + $allow = [ + 'seal_issueid' => 's.seal_issueid', + 'park_id' => 'p.park_name', + 'contract_id' => 's.contract_id', + 'seal_day' => 's.seal_day', + 'contract_seal_issue' => 'rc.contract_seal_issue', + 'psection_subject' => 'ps.psection_subject', + ]; + if(isset($allow[$sort])){ + $sortType = $sortType === 'desc' ? 'desc' : 'asc'; + $q->orderBy($allow[$sort], $sortType); + } + // 並び替え指定が無い時は orderBy 不要 → DB の物理(主キー)順 + + $list = $q->paginate(20)->appends($request->query()); + + $parks = \DB::table('park') + ->select('park_id','park_name') + ->orderBy('park_name') + ->get(); + + return view('admin.seals.list', compact('list','parks','sort','sortType')); } } \ No newline at end of file diff --git a/resources/views/admin/seals/list.blade.php b/resources/views/admin/seals/list.blade.php index 721985c..e40af7e 100644 --- a/resources/views/admin/seals/list.blade.php +++ b/resources/views/admin/seals/list.blade.php @@ -22,46 +22,50 @@
| + | シール発行履歴ID | -+ | シール発行駐輪場 | -+ | 定期契約ID | 車種区分ID | -+ | 発行日 | -+ | 発行回数 | 理由 | @@ -115,7 +119,7 @@{{ $item->seal_issueid }} | {{ $item->park_name ?? $item->park_id }} | {{ $item->contract_id }} | -{{ $item->psection_name ?? $item->psection_id }} | +{{ $item->psection_subject ?? $item->psection_id }} | {{ $item->seal_day }} | {{ $item->contract_seal_issue }} | {{ $item->seal_reason }} |
|---|