diff --git a/app/Http/Controllers/Admin/ReservesController.php b/app/Http/Controllers/Admin/ReservesController.php index 5d3c9eb..96c237e 100644 --- a/app/Http/Controllers/Admin/ReservesController.php +++ b/app/Http/Controllers/Admin/ReservesController.php @@ -6,6 +6,10 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; +use App\Models\Park; +use App\Models\PriceA; +use App\Models\PriceB; +use Illuminate\Support\Facades\Auth; class ReservesController { @@ -24,7 +28,7 @@ class ReservesController { // ── 並び順(既定: reserve_id DESC)────────────────────────────── $sort = $request->input('sort', 'reserve_id'); - $sortType = strtolower($request->input('sort_type', 'desc')) === 'asc' ? 'asc' : 'desc'; + $sortType = strtolower($request->input('sort_type', 'asc')) === 'desc' ? 'desc' : 'asc'; // ── 絞り込み(必要最低限:利用者/駐輪場/期間)────────────────── $userId = trim((string) $request->input('user_id', '')); @@ -32,14 +36,32 @@ class ReservesController $fromDt = $request->input('reserve_date_from', ''); $toDt = $request->input('reserve_date_to', ''); $keyword = trim((string) $request->input('keyword', '')); // 利用者名かな など + $validFlag = trim((string) $request->input('valid_flag', '')); + $mailSentFrom = $request->input('mail_sent_from', ''); + $mailSentTo = $request->input('mail_sent_to', ''); + + $priceUnion = DB::query()->fromSub(function ($sub) { + $sub->from('price_a') + ->select('price_parkplaceid', 'prine_name') + ->unionAll( + DB::table('price_b')->select('price_parkplaceid', 'prine_name') + ); + }, 'price_union'); // ── クエリ構築 ──────────────────────────────────────────────── $q = DB::table('reserve as r') - ->leftJoin('user as u', 'u.user_id', '=', 'r.user_id') // user: user_name, user_phonetic 等【turn12file9†L26-L34】 - ->leftJoin('park as p', 'p.park_id', '=', 'r.park_id') // park: park_name 等【turn12file4†L17-L25】 + ->leftJoin('user as u', 'u.user_id', '=', 'r.user_id') + ->leftJoin('park as p', 'p.park_id', '=', 'r.park_id') + ->leftJoin('psection as ps', 'ps.psection_id', '=', 'r.psection_id') + ->leftJoin('ptype as pt', 'pt.ptype_id', '=', 'r.ptype_id') + ->leftJoin('usertype as t', 't.user_categoryid', '=', 'r.user_categoryid') + ->leftJoinSub($priceUnion, 'price_union', function ($join) { + $join->on('price_union.price_parkplaceid', '=', 'r.price_parkplaceid'); + }) ->select([ 'r.reserve_id', 'r.contract_id', + 'r.contract_created_at', 'r.user_id', 'r.park_id', 'r.price_parkplaceid', @@ -47,19 +69,36 @@ class ReservesController 'r.reserve_date', 'r.reserve_start', 'r.reserve_end', + 'r.reserve_reduction', + 'r.reserve_auto_remind', + 'r.reserve_manual_remind', + DB::raw('r.`800m_flag` as flag_800m'), 'r.reserve_cancelday', 'r.valid_flag', + 'r.reserve_manual', + 'r.reserve_notice', + 'r.sent_date', + 'r.reserve_order', + 'r.valid_flag', 'r.ope_id', + 'r.user_categoryid', DB::raw('u.user_name as user_name'), DB::raw('u.user_phonetic as user_phonetic'), DB::raw('u.user_mobile as user_mobile'), DB::raw('p.park_name as park_name'), + DB::raw('pt.ptype_subject as ptype_subject'), + DB::raw('ps.psection_subject as psection_subject'), + DB::raw('price_union.price_parkplaceid as display_price_parkplaceid'), + DB::raw('price_union.prine_name as display_prine_name'), + DB::raw('t.usertype_subject1 as usertype_subject1'), + DB::raw('t.usertype_subject2 as usertype_subject2'), + DB::raw('t.usertype_subject3 as usertype_subject3'), ]); if ($userId !== '') $q->where('r.user_id', 'like', "%{$userId}%"); if ($parkId !== '') - $q->where('r.park_id', 'like', "%{$parkId}%"); + $q->where('r.park_id', '=', (int) $parkId); if ($fromDt) $q->whereDate('r.reserve_date', '>=', $fromDt); @@ -72,36 +111,108 @@ class ReservesController ->orWhere('u.user_phonetic', 'like', "%{$keyword}%"); }); } + if (in_array($validFlag, ['0', '1'], true)) { + $q->where('r.valid_flag', '=', (int) $validFlag); + } + if ($mailSentFrom !== null && $mailSentFrom !== '') { + $q->where('r.sent_date', '>=', $mailSentFrom); + } + if ($mailSentTo !== null && $mailSentTo !== '') { + $q->where('r.sent_date', '<=', $mailSentTo); + } // ソート許可カラム(JOIN 先も含む) $sortable = [ 'reserve_id', 'contract_id', + 'contract_created_at', + 'user_categoryid', 'user_id', - 'park_id', 'reserve_date', - 'reserve_start', - 'reserve_end', + 'park_price_name', + 'price_parkplaceid', + 'psection_subject', + 'ptype_subject', + 'park_name', + 'reserve_reduction', + 'reserve_auto_remind', + 'reserve_manual_remind', + 'flag_800m', 'reserve_cancelday', 'valid_flag', - 'ope_id', - 'user_name', - 'user_phonetic', - 'user_mobile', - 'park_name', + 'sent_date', + 'reserve_manual', + 'reserve_notice', + 'reserve_order', ]; - if (!in_array($sort, $sortable, true)) + if (!in_array($sort, $sortable, true)) { $sort = 'reserve_id'; + } $sortMap = [ - 'user_name' => 'u.user_name', - 'user_phonetic' => 'u.user_phonetic', - 'user_mobile' => 'u.user_mobile', - 'park_name' => 'p.park_name', + 'reserve_id' => DB::raw('r.reserve_id'), + 'contract_id' => DB::raw('r.contract_id'), + 'contract_created_at' => DB::raw('r.contract_created_at'), + 'user_categoryid' => DB::raw('r.user_categoryid'), + 'user_id' => DB::raw('r.user_id'), + 'reserve_date' => DB::raw('r.reserve_date'), + 'park_price_name' => DB::raw('price_union.prine_name'), + 'price_parkplaceid' => DB::raw('r.price_parkplaceid'), + 'psection_subject' => DB::raw('ps.psection_subject'), + 'ptype_subject' => DB::raw('pt.ptype_subject'), + 'park_name' => DB::raw('p.park_name'), + 'reserve_reduction' => DB::raw('r.reserve_reduction'), + 'reserve_auto_remind' => DB::raw('r.reserve_auto_remind'), + 'reserve_manual_remind' => DB::raw('r.reserve_manual_remind'), + 'flag_800m' => DB::raw('r.`800m_flag`'), + 'reserve_cancelday' => DB::raw('r.reserve_cancelday'), + 'valid_flag' => DB::raw('r.valid_flag'), + 'sent_date' => DB::raw('r.sent_date'), + 'reserve_manual' => DB::raw('r.reserve_manual'), + 'reserve_notice' => DB::raw('r.reserve_notice'), + 'reserve_order' => DB::raw('r.reserve_order'), ]; - $sortCol = $sortMap[$sort] ?? ('r.' . $sort); + $sortColumn = $sortMap[$sort] ?? DB::raw('r.reserve_id'); + $q->orderBy($sortColumn, $sortType); - $list = $q->orderBy($sortCol, $sortType)->paginate(50); + $parkOptions = Park::query() + ->orderBy('park_id', 'asc') + ->pluck('park_name', 'park_id') + ->toArray(); + + $list = $q->paginate(50); + + $placeIds = $list->getCollection() + ->pluck('price_parkplaceid') + ->filter() + ->unique() + ->values() + ->all(); + + if (!empty($placeIds)) { + $priceNamesA = PriceA::query() + ->whereIn('price_parkplaceid', $placeIds) + ->pluck('prine_name', 'price_parkplaceid') + ->toArray(); + + $priceNamesB = PriceB::query() + ->whereIn('price_parkplaceid', $placeIds) + ->pluck('prine_name', 'price_parkplaceid') + ->toArray(); + + // 駐輪場所名のマッピング(price_b で上書き) + $priceNames = array_replace($priceNamesA, $priceNamesB); + + $list->setCollection( + $list->getCollection()->map(function ($row) use ($priceNames) { + $id = $row->price_parkplaceid ?? null; + $row->display_prine_name = ($id !== null && array_key_exists($id, $priceNames)) + ? $priceNames[$id] + : null; + return $row; + }) + ); + } return view('admin.reserves.list', [ 'list' => $list, @@ -113,6 +224,10 @@ class ReservesController 'reserve_date_from' => $fromDt, 'reserve_date_to' => $toDt, 'keyword' => $keyword, + 'valid_flag' => $validFlag, + 'mail_sent_from' => $mailSentFrom, + 'mail_sent_to' => $mailSentTo, + 'parkOptions' => $parkOptions, ]); } @@ -122,7 +237,44 @@ class ReservesController public function add(Request $request) { if ($request->isMethod('get')) { - return view('admin.reserves.add'); + $userTypes = DB::table('usertype') + ->orderBy('user_categoryid', 'asc') + ->get([ + 'user_categoryid', + 'usertype_subject1', + 'usertype_subject2', + 'usertype_subject3', + ]) + ->map(function ($row) { + $labels = array_filter([ + $row->usertype_subject1, + $row->usertype_subject2, + $row->usertype_subject3, + ], fn ($v) => $v !== null && $v !== ''); + $row->display_name = $labels ? implode('/', $labels) : ''; + return $row; + }); + + $parks = Park::query() + ->orderBy('park_id', 'asc') + ->get(['park_id', 'park_name']); + + $priceA = PriceA::query() + ->select('price_parkplaceid', 'prine_name') + ->get(); + $priceB = PriceB::query() + ->select('price_parkplaceid', 'prine_name') + ->get(); + $priceOptions = $priceA->merge($priceB) + ->sortBy('price_parkplaceid', SORT_NATURAL) + ->unique('price_parkplaceid') + ->values(); + + return view('admin.reserves.add', [ + 'userTypes' => $userTypes, + 'parks' => $parks, + 'priceOptions' => $priceOptions, + ]); } // 予約の最低限バリデーション(必要に応じて追加) @@ -141,19 +293,28 @@ class ReservesController return back()->withErrors($v)->withInput(); } + $now = now(); + $opeId = optional(Auth::user())->ope_id; + + $nextReserveId = DB::transaction(function () { + $currentMax = DB::table('reserve')->max('reserve_id'); + return $currentMax ? $currentMax + 1 : 1; + }); + DB::table('reserve')->insert([ + 'reserve_id' => $nextReserveId, 'user_id' => (int) $request->input('user_id'), 'park_id' => (int) $request->input('park_id'), - 'contract_id' => $request->input('contract_id'), // 任意:regular_contract と紐づける場合【turn12file7†L20-L28】 + 'contract_id' => $request->input('contract_id'), 'price_parkplaceid' => $request->input('price_parkplaceid'), 'psection_id' => $request->input('psection_id'), 'reserve_date' => $request->input('reserve_date'), - 'reserve_start' => $request->input('reserve_start'), - 'reserve_end' => $request->input('reserve_end'), + 'reserve_start' => $now, + 'reserve_end' => $now, 'valid_flag' => $request->input('valid_flag'), - 'ope_id' => $request->input('ope_id'), - 'created_at' => now(), - 'updated_at' => now(), + 'ope_id' => $opeId, + 'created_at' => $now, + 'updated_at' => $now, ]); return redirect()->route('reserves')->with('success', '予約を登録しました。'); @@ -264,8 +425,7 @@ class ReservesController $parkOptions = DB::table('park') ->orderBy('park_id', 'asc') - ->limit(5000) - ->pluck(DB::raw("concat(park_id, ' ', park_name)"), 'park_id') + ->pluck('park_name', 'park_id') ->toArray(); $userTypeOptions = Schema::hasTable('usertype') diff --git a/resources/views/admin/reserves/add.blade.php b/resources/views/admin/reserves/add.blade.php index c9154a3..9ca0cb3 100644 --- a/resources/views/admin/reserves/add.blade.php +++ b/resources/views/admin/reserves/add.blade.php @@ -48,8 +48,9 @@
-
- +
+ + 戻る
@@ -57,26 +58,25 @@
{{-- 画面上部(ID系) --}} -
- -
- -
-
- +
- {{-- 任意:必要に応じて選択肢を与える(今は簡易にテキスト or 「全て」) --}}
@@ -92,42 +92,56 @@
- +
- +
- +
- +
- +
- +
- +
@@ -150,14 +164,14 @@
- +
- +
@@ -179,7 +193,7 @@
- +
@@ -229,49 +243,58 @@
- +
- -
小さいほど優先度が高い想定
+
- {{-- 任意:開始/終了(必要なら表示) --}} -
- -
- -
+
+ + 戻る
- -
- -
- -
-
- -
- -
- -
-
- -
- -
+ +@push('scripts') + +@endpush @endsection diff --git a/resources/views/admin/reserves/edit.blade.php b/resources/views/admin/reserves/edit.blade.php index e317afa..e0d6c1b 100644 --- a/resources/views/admin/reserves/edit.blade.php +++ b/resources/views/admin/reserves/edit.blade.php @@ -4,22 +4,90 @@ @section('content') @php - // 只读显示用:从现有 options 推断名称(不改控制器也能显示) + // 読み取り専用表示用:既存のオプションから名称を推定(コントローラを変更せず表示可能) $userName = ''; if (!empty($row->user_id ?? null) && !empty($userOptions[$row->user_id] ?? null)) { // $userOptions 形如 "12345 山田太郎" → 去掉开头ID只留名字 @@ -37,14 +105,15 @@

編集

+
+ +
- - @if(session('success'))
{{ session('success') }}
@endif @@ -60,263 +129,242 @@
+
+ + + 戻る +
+ {{-- GET と同一ルートで POST 更新 --}}
@csrf - -
-
- {{-- 左カラム(目标图顺序) --}} -
- {{-- 定期予約ID(読み取り) --}} -
- -
-
- - {{-- 定期契約ID --}} -
- -
- -
-
- - {{-- 利用者分類ID(先頭「全て」) --}} -
- -
- -
-
- - {{-- 予約日時 --}} -
- -
- -
-
- - {{-- 利用者名(読み取り)※目標画面に合わせて表示のみ --}} -
- -
-
- - {{-- 利用者ID --}} -
- -
- -
-
- - {{-- 駐輪場(読み取り) --}} -
- -
-
- - {{-- 駐輪場ID --}} -
- -
- -
-
- - {{-- 駐輪場所ID --}} -
- -
- -
-
- - {{-- 車種区分ID --}} -
- -
- -
-
- - {{-- 駐輪分類ID --}} -
- -
- -
-
+
+
+ +
+
+
- {{-- 右カラム(目标图顺序) --}} -
- {{-- 減免措置 --}} -
- -
- @php $reduction = old('reduction', $row->reduction ?? ''); @endphp - - -
-
+
+ +
+ +
+
- {{-- 自動リマインド日 --}} -
- -
- -
-
+
+ +
+ +
+
- {{-- 手動リマインド日 --}} -
- -
- -
-
+
+ +
+ +
+
- {{-- 800M以内フラグ --}} -
- -
- @php $m800 = old('within_800m_flag', $row->within_800m_flag ?? ''); @endphp - - -
-
+
+ +
+ @php + $selectedUserId = old('user_id', $row->user_id ?? ''); + $selectedUserLabel = $selectedUserId !== '' ? ($userOptions[$selectedUserId] ?? $selectedUserId) : ''; + @endphp + + +
+
- {{-- 解約日 --}} -
- -
- -
-
+
+ +
+ +
+
- {{-- 有効フラグ --}} -
- -
- @php $valid = old('valid_flag', $row->valid_flag ?? ''); @endphp - - -
-
+
+ +
+ +
+
- {{-- 空き待ちメール送信日時 --}} -
- -
- -
-
+
+ +
+ +
+
- {{-- 手動通知 --}} -
- -
- @php $mnotice = old('manual_notice', $row->manual_notice ?? ''); @endphp - - -
-
+
+ +
+ +
+
- {{-- 手動通知方法 --}} -
- -
- @php $mhow = old('manual_notice_method', $row->manual_notice_method ?? ''); @endphp - - -
※ 必要に応じて選択肢は調整してください。
-
-
+
+ +
+ +
+
- {{-- 空き待ち順 --}} -
- -
- -
-
+
+ +
+ @php $reduction = old('reduction', $row->reduction ?? ''); @endphp + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ @php $m800 = old('within_800m_flag', $row->within_800m_flag ?? ''); @endphp + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ @php $valid = old('valid_flag', $row->valid_flag ?? ''); @endphp + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ @php $mnotice = old('manual_notice', $row->manual_notice ?? ''); @endphp + + +
+
+ +
+ +
+ @php $mhow = old('manual_notice_method', $row->manual_notice_method ?? ''); @endphp + + +
+
+ +
+ +
+
- {{-- 下部操作(保留:目标图底部有登録/削除) --}} - - + {{-- 下部操作(参照画面の下部にも登録/削除ボタンあり) --}} + + {{-- 削除POST(confirmed + ids[]) --}}