【利用者マスタ】「処理実現方式設計」指摘対応
Some checks failed
Deploy main / deploy (push) Failing after 9s

This commit is contained in:
你的名字 2025-12-15 17:49:05 +09:00
parent e41309ca4c
commit f547220af5
5 changed files with 149 additions and 62 deletions

View File

@ -23,13 +23,52 @@ class UsersController
$row->usertype_subject1 ?? '', $row->usertype_subject1 ?? '',
$row->usertype_subject2 ?? '', $row->usertype_subject2 ?? '',
$row->usertype_subject3 ?? '', $row->usertype_subject3 ?? '',
])->filter(fn ($v) => $v !== '')->implode('/'); ])->filter(fn($v) => $v !== '')->implode('/');
return [$row->user_categoryid => $label !== '' ? $label : (string) $row->user_categoryid]; return [$row->user_categoryid => $label !== '' ? $label : (string) $row->user_categoryid];
}) })
->toArray(); ->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 * - テーブル名: user
@ -81,7 +120,9 @@ class UsersController
$phone = trim((string) $request->input('phone', '')); // 携帯/自宅の両方対象 $phone = trim((string) $request->input('phone', '')); // 携帯/自宅の両方対象
$crime = trim((string) $request->input('crime', '')); // 防犯登録番号(暫定: qr_code $crime = trim((string) $request->input('crime', '')); // 防犯登録番号(暫定: qr_code
$email = trim((string) $request->input('email', '')); $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 $tag_qr_flag = (string) $request->input('tag_qr_flag', ''); // 0=タグ / 1=QR
$quit_flag = (string) $request->input('quit_flag', ''); // 0=いいえ / 1=はい $quit_flag = (string) $request->input('quit_flag', ''); // 0=いいえ / 1=はい
$quit_from = (string) $request->input('quit_from', ''); // YYYY-MM-DD $quit_from = (string) $request->input('quit_from', ''); // YYYY-MM-DD
@ -120,8 +161,18 @@ class UsersController
$query->where('user.user_primemail', 'like', "%{$email}%"); $query->where('user.user_primemail', 'like', "%{$email}%");
// ▼ セレクト/ラジオ('' 以外なら適用。'0' も通す) // ▼ セレクト/ラジオ('' 以外なら適用。'0' も通す)
if ($user_categoryid !== '') if ($user_category1 !== '') {
$query->where('user.user_categoryid', $user_categoryid); $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 !== '') if ($tag_qr_flag !== '')
$query->where('user.tag_qr_flag', (int) $tag_qr_flag); $query->where('user.tag_qr_flag', (int) $tag_qr_flag);
if ($quit_flag !== '') if ($quit_flag !== '')
@ -134,7 +185,7 @@ class UsersController
$query->where('user.user_quitday', '<=', $quit_to); $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', [ return view('admin.users.list', [
@ -149,12 +200,16 @@ class UsersController
'phone' => $phone, 'phone' => $phone,
'crime' => $crime, 'crime' => $crime,
'email' => $email, 'email' => $email,
'user_categoryid' => $user_categoryid,
'tag_qr_flag' => $tag_qr_flag, 'tag_qr_flag' => $tag_qr_flag,
'quit_flag' => $quit_flag, 'quit_flag' => $quit_flag,
'quit_from' => $quit_from, 'quit_from' => $quit_from,
'quit_to' => $quit_to, '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}%"); $q->where('user_primemail', 'like', "%{$v}%");
// ▼ セレクト/ラジオ('' だけスキップ。'0' は適用) // ▼ セレクト/ラジオ('' だけスキップ。'0' は適用)
$val = (string) $request->input('user_categoryid', ''); $q->leftJoin('usertype', 'user.user_categoryid', '=', 'usertype.user_categoryid');
if ($val !== '')
$q->where('user_categoryid', $val); 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', ''); $val = (string) $request->input('tag_qr_flag', '');
if ($val !== '') if ($val !== '')
@ -375,8 +440,8 @@ class UsersController
$categoryOptions = $this->buildCategoryOptions(); $categoryOptions = $this->buildCategoryOptions();
// ▼ 退会処理専用hiddenフィールド quit_action があれば退会処理) // ▼ 退会処理専用hiddenフィールド quit_action があれば退会処理)
if ($request->has('quit_action')) { if ($request->has('quit_action')) {
DB::table('user')->where('user_seq', $seq)->update([ DB::table('user')->where('user_seq', $seq)->update([
'user_quit_flag' => 1, 'user_quit_flag' => 1,
'user_quitday' => now()->format('Y-m-d'), 'user_quitday' => now()->format('Y-m-d'),
@ -387,7 +452,7 @@ if ($request->has('quit_action')) {
return redirect() return redirect()
->route('users_edit', ['seq' => $seq]) ->route('users_edit', ['seq' => $seq])
->with('status', '退会処理が完了しました。'); ->with('status', '退会処理が完了しました。');
} }
if ($request->isMethod('get')) { if ($request->isMethod('get')) {

View File

@ -24,7 +24,10 @@
"App\\": "app/", "App\\": "app/",
"Database\\Factories\\": "database/factories/", "Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/" "Database\\Seeders\\": "database/seeders/"
} },
"files": [
"app/Helpers/ListQueryHelper.php"
]
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {

View File

@ -502,9 +502,7 @@
{{-- 削除ボタン(別フォームを呼び出す) --}} {{-- 削除ボタン(別フォームを呼び出す) --}}
<button type="button" class="btn btn-danger ml-2" id="delete_edit">削除</button> <button type="button" class="btn btn-danger ml-2" id="delete_edit">削除</button>
<a href="{{ route('users', keepUserListQuery()) }}" class="btn btn-secondary ml-2">戻る</a>
<a href="{{ route('users') }}" class="btn btn-secondary ml-2">戻る</a>
@if ($isEdit && $hasDeleteRoute) @if ($isEdit && $hasDeleteRoute)
<button type="button" class="btn btn-warning ml-2" id="quitForm">退会</button> <button type="button" class="btn btn-warning ml-2" id="quitForm">退会</button>
@endif @endif

View File

@ -524,7 +524,7 @@
</div> </div>
</div> </div>
<button type="submit" class="btn btn-success register">登録</button> <button type="submit" class="btn btn-success register">登録</button>
<a href="{{ route('users') }}" class="btn btn-secondary ml-2">戻る</a> <a href="{{ route('users', keepUserListQuery()) }}"class="btn btn-secondary">戻る</a>
</div> </div>
</div> </div>

View File

@ -10,21 +10,6 @@
$curDir = 'desc'; $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) { $thClass = function (string $key) use ($curSort, $curDir) {
if ($curSort !== $key) { if ($curSort !== $key) {
return 'sorting'; return 'sorting';
@ -32,9 +17,12 @@
return $curDir === 'asc' ? 'sorting_asc' : 'sorting_desc'; 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'; $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 @endphp
{{-- コンテンツヘッダー(パンくず) --}} {{-- コンテンツヘッダー(パンくず) --}}
@ -100,18 +88,42 @@
value="{{ $user_id ?? '' }}" placeholder="利用者ID"> value="{{ $user_id ?? '' }}" placeholder="利用者ID">
</div> </div>
{{-- 分類名1 --}}
<div class="form-group d-flex align-items-center mb-2"> <div class="form-group d-flex align-items-center mb-2">
<label class="filter-label">利用者分類</label> <label class="filter-label">分類名1</label>
<select class="form-control filter-input" name="user_categoryid"> <select class="form-control filter-input" name="user_category1">
<option value="">全て</option> <option value="">全て</option>
@if(!empty($categoryOptions)) @foreach($category1Options as $val)
@foreach($categoryOptions as $val => $label) <option value="{{ $val }}" @selected(($user_category1 ?? '') === $val)>
<option value="{{ $val }}" @if(($user_categoryid ?? '') == (string) $val) selected {{ $val }}
@endif> </option>
{{ $label }} @endforeach
</select>
</div>
{{-- 分類名2 --}}
<div class="form-group d-flex align-items-center mb-2">
<label class="filter-label">分類名2</label>
<select class="form-control filter-input" name="user_category2">
<option value="">全て</option>
@foreach($category2Options as $val)
<option value="{{ $val }}" @selected(($user_category2 ?? '') === $val)>
{{ $val }}
</option>
@endforeach
</select>
</div>
{{-- 分類名3 --}}
<div class="form-group d-flex align-items-center mb-2">
<label class="filter-label">分類名3</label>
<select class="form-control filter-input" name="user_category3">
<option value="">全て</option>
@foreach($category3Options as $val)
<option value="{{ $val }}" @selected(($user_category3 ?? '') === $val)>
{{ $val }}
</option> </option>
@endforeach @endforeach
@endif
</select> </select>
</div> </div>
@ -248,13 +260,13 @@
<div class="d-flex align-items-center mb-2"> <div class="d-flex align-items-center mb-2">
<div> <div>
<a href="{{ route('users_add') }}" class="btn btn-primary">新規</a> <a href="{{ route('users_add', keepUserListQuery()) }}"class="btn btn-primary">新規</a>
{{-- クリックで隠しフォーム送信 --}} {{-- クリックで隠しフォーム送信 --}}
<button type="button" class="btn btn-outline-success" <button type="button" class="btn btn-outline-success"
onclick="document.getElementById('csvForm').submit();">CSV出力</button> onclick="document.getElementById('csvForm').submit();">CSV出力</button>
</div> </div>
<div class="ml-auto"> <div class="ml-auto">
{{ $list->appends(request()->except('page'))->links('pagination') }} {{ $list->appends(keepUserListQuery())->links('pagination') }}
</div> </div>
</div> </div>
@ -271,7 +283,9 @@
<a href="{{ $urlFor('user_id') }}" class="header-link">利用者ID</a> <a href="{{ $urlFor('user_id') }}" class="header-link">利用者ID</a>
</th> </th>
<th style="width:110px;">タグ/QRフラグ</th> <th style="width:110px;">タグ/QRフラグ</th>
<th style="width:140px;">利用者分類ID</th> <th style="width:140px;">利用者分類1</th>
<th style="width:140px;">利用者分類2</th>
<th style="width:140px;">利用者分類3</th>
<th style="width:160px;">利用者名</th> <th style="width:160px;">利用者名</th>
<th style="width:160px;" class="{{ $thClass('user_phonetic') }}"> <th style="width:160px;" class="{{ $thClass('user_phonetic') }}">
<a href="{{ $urlFor('user_phonetic') }}" class="header-link">フリガナ</a> <a href="{{ $urlFor('user_phonetic') }}" class="header-link">フリガナ</a>
@ -309,16 +323,22 @@
@endphp @endphp
<tr> <tr>
{{-- 利用者IDリンク --}} {{-- 利用者IDリンク --}}
<td class="text-nowrap"><a href="{{ $userEditUrl }}">{{ $item->user_id }} <td class="text-nowrap">
{{ $item->user_name }}</a></td> <a href="{{ route('users_edit',array_merge(['seq' => $item->user_seq], keepUserListQuery())) }}">
{{ $item->user_id }} {{ $item->user_name }}
</a>
</td>
{{-- タグQR --}} {{-- タグQR --}}
<td>{{ $item->tag_qr_flag ? '' : 'タグ' }}</td> <td>{{ $item->tag_qr_flag ? '' : 'タグ' }}</td>
{{-- 利用者分類ID氏名フリガナ --}} {{-- 利用者分類ID氏名フリガナ --}}
<td>{{ $categoryDisplay ?: $item->user_categoryid }}</td> <td>{{ $item->usertype_subject1 }}</td>
<td>{{ $item->usertype_subject2 }}</td>
<td>{{ $item->usertype_subject3 }}</td>
<td>{{ $item->user_name }}</td> <td>{{ $item->user_name }}</td>
<td>{{ $item->user_phonetic }}</td> <td>{{ $item->user_phonetic }}</td>
{{-- 生年月日/年齢 --}} {{-- 生年月日/年齢 --}}
<td class="text-right">{{ $item->user_birthdate ? \Illuminate\Support\Str::limit($item->user_birthdate, 10, '') : '' }} <td class="text-right">
{{ $item->user_birthdate ? \Illuminate\Support\Str::limit($item->user_birthdate, 10, '') : '' }}
</td> </td>
<td class="text-right">{{ $item->user_age }}</td> <td class="text-right">{{ $item->user_age }}</td>
{{-- 連絡先 --}} {{-- 連絡先 --}}
@ -328,7 +348,8 @@
{{-- 本人確認(書類/チェック/日時) --}} {{-- 本人確認(書類/チェック/日時) --}}
<td>{{ __($item->user_idcard) }}</td> <td>{{ __($item->user_idcard) }}</td>
<td class="text-nowrap">{{ $chk === '1' ? '手動チェックOK' : '未チェック' }}</td> <td class="text-nowrap">{{ $chk === '1' ? '手動チェックOK' : '未チェック' }}</td>
<td class="text-right">{{ $item->user_chk_day ? \Illuminate\Support\Str::limit($item->user_chk_day, 10, '') : '' }} <td class="text-right">
{{ $item->user_chk_day ? \Illuminate\Support\Str::limit($item->user_chk_day, 10, '') : '' }}
</td> </td>
{{-- 退会 --}} {{-- 退会 --}}
<td>{{ $item->user_quit_flag ? 'はい' : 'いいえ' }}</td> <td>{{ $item->user_quit_flag ? 'はい' : 'いいえ' }}</td>