diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 29acaad..3f02d89 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -23,13 +23,52 @@ class UsersController $row->usertype_subject1 ?? '', $row->usertype_subject2 ?? '', $row->usertype_subject3 ?? '', - ])->filter(fn ($v) => $v !== '')->implode('/'); + ])->filter(fn($v) => $v !== '')->implode('/'); return [$row->user_categoryid => $label !== '' ? $label : (string) $row->user_categoryid]; }) ->toArray(); } + /** + * 利用者分類1(一覧絞り込み用) + */ + private function buildCategory1Options() + { + return DB::table('regular_contract') + ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') + ->whereNotNull('usertype.usertype_subject1') + ->distinct() + ->orderBy('usertype.usertype_subject1') + ->pluck('usertype.usertype_subject1'); + } + + /** + * 利用者分類2(一覧絞り込み用) + */ + private function buildCategory2Options() + { + return DB::table('regular_contract') + ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') + ->whereNotNull('usertype.usertype_subject2') + ->distinct() + ->orderBy('usertype.usertype_subject2') + ->pluck('usertype.usertype_subject2'); + } + + /** + * 利用者分類3(一覧絞り込み用) + */ + private function buildCategory3Options() + { + return DB::table('regular_contract') + ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') + ->whereNotNull('usertype.usertype_subject3') + ->distinct() + ->orderBy('usertype.usertype_subject3') + ->pluck('usertype.usertype_subject3'); + } + /** * 利用者一覧 * - テーブル名: user @@ -81,7 +120,9 @@ class UsersController $phone = trim((string) $request->input('phone', '')); // 携帯/自宅の両方対象 $crime = trim((string) $request->input('crime', '')); // 防犯登録番号(暫定: qr_code) $email = trim((string) $request->input('email', '')); - $user_categoryid = (string) $request->input('user_categoryid', ''); + $user_category1 = trim((string) $request->input('user_category1', '')); + $user_category2 = trim((string) $request->input('user_category2', '')); + $user_category3 = trim((string) $request->input('user_category3', '')); $tag_qr_flag = (string) $request->input('tag_qr_flag', ''); // 0=タグ / 1=QR $quit_flag = (string) $request->input('quit_flag', ''); // 0=いいえ / 1=はい $quit_from = (string) $request->input('quit_from', ''); // YYYY-MM-DD @@ -120,8 +161,18 @@ class UsersController $query->where('user.user_primemail', 'like', "%{$email}%"); // ▼ セレクト/ラジオ('' 以外なら適用。'0' も通す) - if ($user_categoryid !== '') - $query->where('user.user_categoryid', $user_categoryid); + if ($user_category1 !== '') { + $query->where('usertype.usertype_subject1', $user_category1); + } + + if ($user_category2 !== '') { + $query->where('usertype.usertype_subject2', $user_category2); + } + + if ($user_category3 !== '') { + $query->where('usertype.usertype_subject3', $user_category3); + } + if ($tag_qr_flag !== '') $query->where('user.tag_qr_flag', (int) $tag_qr_flag); if ($quit_flag !== '') @@ -134,7 +185,7 @@ class UsersController $query->where('user.user_quitday', '<=', $quit_to); // ▼ 並び & ページング - $list = $query->orderBy("user.{$sort}", $sortType)->paginate(20); + $list = $query->orderBy("user.{$sort}", $sortType)->paginate(50); // ▼ 画面に渡す(フォーム再描画用に絞り込み値も) return view('admin.users.list', [ @@ -149,12 +200,16 @@ class UsersController 'phone' => $phone, 'crime' => $crime, 'email' => $email, - 'user_categoryid' => $user_categoryid, 'tag_qr_flag' => $tag_qr_flag, 'quit_flag' => $quit_flag, 'quit_from' => $quit_from, 'quit_to' => $quit_to, - 'categoryOptions' => $this->buildCategoryOptions(), + 'user_category1' => $user_category1, + 'user_category2' => $user_category2, + 'user_category3' => $user_category3, + 'category1Options' => $this->buildCategory1Options(), + 'category2Options' => $this->buildCategory2Options(), + 'category3Options' => $this->buildCategory3Options(), ]); } @@ -186,9 +241,19 @@ class UsersController $q->where('user_primemail', 'like', "%{$v}%"); // ▼ セレクト/ラジオ('' だけスキップ。'0' は適用) - $val = (string) $request->input('user_categoryid', ''); - if ($val !== '') - $q->where('user_categoryid', $val); + $q->leftJoin('usertype', 'user.user_categoryid', '=', 'usertype.user_categoryid'); + + if (($v = trim((string) $request->input('user_category1', ''))) !== '') { + $q->where('usertype.usertype_subject1', $v); + } + + if (($v = trim((string) $request->input('user_category2', ''))) !== '') { + $q->where('usertype.usertype_subject2', $v); + } + + if (($v = trim((string) $request->input('user_category3', ''))) !== '') { + $q->where('usertype.usertype_subject3', $v); + } $val = (string) $request->input('tag_qr_flag', ''); if ($val !== '') @@ -375,19 +440,19 @@ class UsersController $categoryOptions = $this->buildCategoryOptions(); -// ▼ 退会処理専用(hiddenフィールド quit_action があれば退会処理) -if ($request->has('quit_action')) { - DB::table('user')->where('user_seq', $seq)->update([ - 'user_quit_flag' => 1, - 'user_quitday' => now()->format('Y-m-d'), - 'ope_id' => $request->input('ope_id') ?? auth()->user()->ope_id ?? null, - 'updated_at' => now(), - ]); + // ▼ 退会処理専用(hiddenフィールド quit_action があれば退会処理) + if ($request->has('quit_action')) { + DB::table('user')->where('user_seq', $seq)->update([ + 'user_quit_flag' => 1, + 'user_quitday' => now()->format('Y-m-d'), + 'ope_id' => $request->input('ope_id') ?? auth()->user()->ope_id ?? null, + 'updated_at' => now(), + ]); - return redirect() - ->route('users_edit', ['seq' => $seq]) - ->with('status', '退会処理が完了しました。'); -} + return redirect() + ->route('users_edit', ['seq' => $seq]) + ->with('status', '退会処理が完了しました。'); + } if ($request->isMethod('get')) { diff --git a/composer.json b/composer.json index 792b992..6834cc8 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,10 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, + "files": [ + "app/Helpers/ListQueryHelper.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/resources/views/admin/users/_form.blade.php b/resources/views/admin/users/_form.blade.php index 4f48471..27efffb 100644 --- a/resources/views/admin/users/_form.blade.php +++ b/resources/views/admin/users/_form.blade.php @@ -502,9 +502,7 @@ {{-- 削除ボタン(別フォームを呼び出す) --}} - - 戻る - + 戻る @if ($isEdit && $hasDeleteRoute) @endif diff --git a/resources/views/admin/users/add.blade.php b/resources/views/admin/users/add.blade.php index 6dda189..2bec4f6 100644 --- a/resources/views/admin/users/add.blade.php +++ b/resources/views/admin/users/add.blade.php @@ -524,7 +524,7 @@ - 戻る + 戻る diff --git a/resources/views/admin/users/list.blade.php b/resources/views/admin/users/list.blade.php index 6e98a9e..4938f5a 100644 --- a/resources/views/admin/users/list.blade.php +++ b/resources/views/admin/users/list.blade.php @@ -10,21 +10,6 @@ $curDir = 'desc'; } - $queryBase = collect([ - 'user_id' => $user_id ?? null, - 'user_categoryid' => $user_categoryid ?? null, - 'user_tag_serial' => $user_tag_serial ?? null, - 'quit_flag' => $quit_flag ?? null, - 'user_phonetic' => $user_phonetic ?? null, - 'phone' => $phone ?? null, - 'email' => $email ?? null, - 'tag_qr_flag' => $tag_qr_flag ?? null, - 'quit_from' => $quit_from ?? null, - 'quit_to' => $quit_to ?? null, - ])->filter(function ($value) { - return !is_null($value) && $value !== ''; - })->all(); - $thClass = function (string $key) use ($curSort, $curDir) { if ($curSort !== $key) { return 'sorting'; @@ -32,9 +17,12 @@ return $curDir === 'asc' ? 'sorting_asc' : 'sorting_desc'; }; - $urlFor = function (string $key) use ($curSort, $curDir, $queryBase) { + $urlFor = function (string $key) use ($curSort, $curDir) { $next = ($curSort === $key && $curDir === 'asc') ? 'desc' : 'asc'; - return route('users', array_merge($queryBase, ['sort' => $key, 'dir' => $next])); + return route('users', keepUserListQuery([ + 'sort' => $key, + 'dir' => $next, + ])); }; @endphp {{-- ▼ コンテンツヘッダー(パンくず) --}} @@ -100,18 +88,42 @@ value="{{ $user_id ?? '' }}" placeholder="利用者ID"> + {{-- 分類名1 --}}
- - - @if(!empty($categoryOptions)) - @foreach($categoryOptions as $val => $label) - - @endforeach - @endif + @foreach($category1Options as $val) + + @endforeach + +
+ + {{-- 分類名2 --}} +
+ + +
+ + {{-- 分類名3 --}} +
+ +
@@ -248,13 +260,13 @@
- 新規 + 新規 {{-- ▼ クリックで隠しフォーム送信 --}}
- {{ $list->appends(request()->except('page'))->links('pagination') }} + {{ $list->appends(keepUserListQuery())->links('pagination') }}
@@ -271,7 +283,9 @@ 利用者ID タグ/QRフラグ - 利用者分類ID + 利用者分類1 + 利用者分類2 + 利用者分類3 利用者名 フリガナ @@ -309,16 +323,22 @@ @endphp {{-- 利用者ID(リンク) --}} - {{ $item->user_id }} - {{ $item->user_name }} + + + {{ $item->user_id }} {{ $item->user_name }} + + {{-- タグ/QR --}} {{ $item->tag_qr_flag ? 'QR' : 'タグ' }} {{-- 利用者分類ID/氏名/フリガナ --}} - {{ $categoryDisplay ?: $item->user_categoryid }} + {{ $item->usertype_subject1 }} + {{ $item->usertype_subject2 }} + {{ $item->usertype_subject3 }} {{ $item->user_name }} {{ $item->user_phonetic }} {{-- 生年月日/年齢 --}} - {{ $item->user_birthdate ? \Illuminate\Support\Str::limit($item->user_birthdate, 10, '') : '' }} + + {{ $item->user_birthdate ? \Illuminate\Support\Str::limit($item->user_birthdate, 10, '') : '' }} {{ $item->user_age }} {{-- 連絡先 --}} @@ -328,7 +348,8 @@ {{-- 本人確認(書類/チェック/日時) --}} {{ __($item->user_idcard) }} {{ $chk === '1' ? '手動チェックOK' : '未チェック' }} - {{ $item->user_chk_day ? \Illuminate\Support\Str::limit($item->user_chk_day, 10, '') : '' }} + + {{ $item->user_chk_day ? \Illuminate\Support\Str::limit($item->user_chk_day, 10, '') : '' }} {{-- 退会 --}} {{ $item->user_quit_flag ? 'はい' : 'いいえ' }}