From b3d48f8608d47e161c3691c8cd8a60fd16e99248 Mon Sep 17 00:00:00 2001 From: Yuka Higashide Date: Mon, 1 Sep 2025 17:07:55 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=9C=9F=E5=A5=91=E7=B4=84=E6=9C=89?= =?UTF-8?q?=E7=84=A1=E3=81=AE=E5=88=A4=E5=AE=9A=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/UserEditController.php | 98 +++++++------------ .../views/regular_contract/info.blade.php | 73 +++++++------- resources/views/user/confirm.blade.php | 38 ++++++- resources/views/user/edit.blade.php | 14 +-- 4 files changed, 119 insertions(+), 104 deletions(-) diff --git a/app/Http/Controllers/UserEditController.php b/app/Http/Controllers/UserEditController.php index 1b5c66d..0b3bc8c 100644 --- a/app/Http/Controllers/UserEditController.php +++ b/app/Http/Controllers/UserEditController.php @@ -75,46 +75,35 @@ class UserEditController extends Controller $today_time = date('H:i'); $in_grace = false; - // 契約月の猶予期間判定 - if ($end_day < $start_day) { - // 例:20~翌月5日 - if ((int)$today_day > $start_day && (int)$today_month == (int)$contract_month) { - $start_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = date('Y-m-t', strtotime($contract_periode)) . ' 23:59'; + // 契約終了月のみ猶予期間判定 + if ((int)$today_year === (int)$contract_year) { + // 開始日 < 終了日:契約終了月の開始日~終了日 + if ($start_day < $end_day && (int)$today_month === (int)$contract_month) { + $start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; + $end_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; $today_datetime = date('Y-m-d') . ' ' . $today_time; if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } - } else { - // 通常:開始日~終了日(時間含む) - if ((int)$today_day >= $start_day && (int)$today_day <= $end_day && (int)$today_month == (int)$contract_month) { - $start_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $end_day) . ' ' . $end_time; + // 開始日 > 終了日:契約終了月の開始日~翌月の終了日 + if ($start_day > $end_day && (int)$today_month === (int)$contract_month) { + $start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; + $end_year = date('Y', strtotime($contract_periode . ' +1 month')); + $end_month = date('m', strtotime($contract_periode . ' +1 month')); + $end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; $today_datetime = date('Y-m-d') . ' ' . $today_time; if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } - } - - // 契約月の翌月の猶予期間判定(追加) - $next_month = date('m', strtotime($contract_periode . ' +1 month')); - $next_year = date('Y', strtotime($contract_periode . ' +1 month')); - if ((int)$today_month == (int)$next_month && (int)$today_year == (int)$next_year) { - $today_datetime = date('Y-m-d') . ' ' . $today_time; - if ($end_day < $start_day) { - // 例:20~翌月5日(翌月分) - $start_datetime = $next_year . '-' . $next_month . '-01 00:00'; - $end_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; - if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { - $in_grace = true; - } - } else { - // 通常:開始日~終了日(翌月分) - $start_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; - if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { + // 開始日 > 終了日:契約終了月の翌月の終了日(翌月分) + if ($start_day > $end_day && (int)$today_month === (int)date('m', strtotime($contract_periode . ' +1 month'))) { + $end_year = date('Y', strtotime($contract_periode . ' +1 month')); + $end_month = date('m', strtotime($contract_periode . ' +1 month')); + $end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; + $today_datetime = date('Y-m-d') . ' ' . $today_time; + if (strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } @@ -279,46 +268,35 @@ class UserEditController extends Controller $today_time = date('H:i'); $in_grace = false; - // 契約月の猶予期間判定 - if ($end_day < $start_day) { - // 例:20~翌月5日 - if ((int)$today_day > $start_day && (int)$today_month == (int)$contract_month) { - $start_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = date('Y-m-t', strtotime($contract_periode)) . ' 23:59'; + // 契約終了月のみ猶予期間判定 + if ((int)$today_year === (int)$contract_year) { + // 開始日 < 終了日:契約終了月の開始日~終了日 + if ($start_day < $end_day && (int)$today_month === (int)$contract_month) { + $start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; + $end_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; $today_datetime = date('Y-m-d') . ' ' . $today_time; if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } - } else { - // 通常:開始日~終了日(時間含む) - if ((int)$today_day >= $start_day && (int)$today_day <= $end_day && (int)$today_month == (int)$contract_month) { - $start_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = date('Y-m-', strtotime($contract_periode)) . sprintf('%02d', $end_day) . ' ' . $end_time; + // 開始日 > 終了日:契約終了月の開始日~翌月の終了日 + if ($start_day > $end_day && (int)$today_month === (int)$contract_month) { + $start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; + $end_year = date('Y', strtotime($contract_periode . ' +1 month')); + $end_month = date('m', strtotime($contract_periode . ' +1 month')); + $end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; $today_datetime = date('Y-m-d') . ' ' . $today_time; if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } - } - - // 契約月の翌月の猶予期間判定(追加) - $next_month = date('m', strtotime($contract_periode . ' +1 month')); - $next_year = date('Y', strtotime($contract_periode . ' +1 month')); - if ((int)$today_month == (int)$next_month && (int)$today_year == (int)$next_year) { - $today_datetime = date('Y-m-d') . ' ' . $today_time; - if ($end_day < $start_day) { - // 例:20~翌月5日(翌月分) - $start_datetime = $next_year . '-' . $next_month . '-01 00:00'; - $end_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; - if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { - $in_grace = true; - } - } else { - // 通常:開始日~終了日(翌月分) - $start_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time; - $end_datetime = $next_year . '-' . $next_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; - if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) { + // 開始日 > 終了日:契約終了月の翌月の終了日(翌月分) + if ($start_day > $end_day && (int)$today_month === (int)date('m', strtotime($contract_periode . ' +1 month'))) { + $end_year = date('Y', strtotime($contract_periode . ' +1 month')); + $end_month = date('m', strtotime($contract_periode . ' +1 month')); + $end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time; + $today_datetime = date('Y-m-d') . ' ' . $today_time; + if (strtotime($today_datetime) <= strtotime($end_datetime)) { $in_grace = true; } } diff --git a/resources/views/regular_contract/info.blade.php b/resources/views/regular_contract/info.blade.php index 60fd1fd..da5d4db 100644 --- a/resources/views/regular_contract/info.blade.php +++ b/resources/views/regular_contract/info.blade.php @@ -32,44 +32,51 @@ return null; $start_hm = $contract->update_grace_period_start_time; $end_dd = $contract->update_grace_period_end_date; $end_hm = $contract->update_grace_period_end_time; - // dd→今月のdd日, HH:mm→HH:mm:00 でCarbon化 - $start_dt = safeCarbonFromDDHM($start_dd, $start_hm); - // $start_dd > $end_ddなら$end_ddは次月扱い - if (is_numeric($start_dd) && is_numeric($end_dd) && $start_dd > $end_dd) { - $next_month = $now->copy()->addMonth(); - $end_date = $next_month->format('Y-m-') . str_pad($end_dd, 2, '0', STR_PAD_LEFT); - $end_time = $end_hm . ':00'; - try { - $end_dt = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $end_date . ' ' . $end_time); - } catch (Exception $e) { - $end_dt = null; - } - } else { - $end_dt = safeCarbonFromDDHM($end_dd, $end_hm); - } - $month_end = $now->copy()->endOfMonth(); + $contract_end_dt = $contract->contract_periode ? \Carbon\Carbon::parse($contract->contract_periode) : null; + $periode_month = $contract_end_dt ? $contract_end_dt->month : null; + $periode_year = $contract_end_dt ? $contract_end_dt->year : null; $bg = 'alert-warning'; $btn_text = '更新する'; $btn_active = true; - // 追加: contract_periodeの月より現在月が前なら一律「ご契約中」 - $periode_month = $contract->contract_periode ? \Carbon\Carbon::parse($contract->contract_periode)->month : null; - if (!empty($contract->contract_periode)) { - $periode_month = \Carbon\Carbon::parse($contract->contract_periode)->month; - } - if ($periode_month && $now->month < $periode_month) { - $bg='bg-white' ; - $btn_text='ご契約中' ; - $btn_active=false; + // 契約終了月以外は「ご契約中」 + if ($periode_month && $periode_year && ($now->month != $periode_month || $now->year != $periode_year)) { + $bg = 'bg-white'; + $btn_text = 'ご契約中'; + $btn_active = false; + } else { + // 猶予期間のCarbon生成 + if (is_numeric($start_dd) && is_numeric($end_dd)) { + // 開始日 + $start_date = $contract_end_dt->format('Y-m-') . str_pad($start_dd, 2, '0', STR_PAD_LEFT); + $start_time = ($start_hm && preg_match('/^\d{2}:\d{2}$/', $start_hm)) ? $start_hm : '00:00'; + $start_dt = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $start_date . ' ' . $start_time . ':00'); + // 終了日 + if ($start_dd < $end_dd) { + // 終了月も契約終了月 + $end_date=$contract_end_dt->format('Y-m-') . str_pad($end_dd, 2, '0', STR_PAD_LEFT); + $end_time = ($end_hm && preg_match('/^\d{2}:\d{2}$/', $end_hm)) ? $end_hm : '23:59'; + $end_dt = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $end_date . ' ' . $end_time . ':00'); } else { + // 終了日は契約終了月の翌月 + $next_month_dt = $contract_end_dt->copy()->addMonth(); + $end_date = $next_month_dt->format('Y-m-') . str_pad($end_dd, 2, '0', STR_PAD_LEFT); + $end_time = ($end_hm && preg_match('/^\d{2}:\d{2}$/', $end_hm)) ? $end_hm : '23:59'; + $end_dt = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $end_date . ' ' . $end_time . ':00'); + } + } else { + $start_dt = null; + $end_dt = null; + } + // 以降は既存のボタン・背景色判定ロジック if ($update_flag===0) { - $bg='bg-white' ; - $btn_text='手続き中' ; + $bg='bg-white'; + $btn_text='手続き中'; $btn_active=false; } elseif ($update_flag===1) { - $bg='bg-white' ; - $btn_text='更新済' ; + $bg='bg-white'; + $btn_text='更新済'; $btn_active=false; } elseif (!is_null($end_dt) && $end_dt->gt($start_dt)) { @@ -78,9 +85,8 @@ return null; $btn_text = 'ご契約中'; $btn_active = false; } else { - // 修正: 契約終了日を過ぎていて、更新可能期間内は赤背景 - $periode_dt = $contract->contract_periode ? \Carbon\Carbon::parse($contract->contract_periode) : null; - if ($periode_dt && $now->gt($periode_dt) && $start_dt && $end_dt && $now->between($start_dt, $end_dt)) { + // 契約終了日を過ぎていて、更新可能期間内は赤背景 + if ($contract_end_dt && $now->gt($contract_end_dt) && $start_dt && $end_dt && $now->between($start_dt, $end_dt)) { $bg = 'alert-danger'; $btn_text = '更新する'; $btn_active = true; @@ -96,7 +102,7 @@ return null; $bg = 'bg-white'; $btn_text = 'ご契約中'; $btn_active = false; - } elseif ($now->gte($start_dt) && $now->lte($month_end)) { + } elseif ($now->gte($start_dt) && $now->lte($contract_end_dt->copy()->endOfMonth())) { $bg = 'alert-warning'; $btn_text = '更新する'; $btn_active = true; @@ -108,6 +114,7 @@ return null; } } @endphp + @endphp @if($bg == 'bg-white')
@elseif($bg == 'alert-warning') diff --git a/resources/views/user/confirm.blade.php b/resources/views/user/confirm.blade.php index b703079..7872caf 100644 --- a/resources/views/user/confirm.blade.php +++ b/resources/views/user/confirm.blade.php @@ -39,7 +39,17 @@
-

{{ ($input['user_regident_zip_1'] ?? $user->user_regident_zip_1 ?? '') }}-{{ ($input['user_regident_zip_2'] ?? $user->user_regident_zip_2 ?? '') }}{{ ($input['user_regident_pre'] ?? $user->user_regident_pre ?? '') }}{{ ($input['user_regident_city'] ?? $user->user_regident_city ?? '') }}{{ ($input['user_regident_add'] ?? $user->user_regident_add ?? '') }}

+

+ @php + $zip1 = $input['user_regident_zip_1'] ?? $user->user_regident_zip_1 ?? ''; + $zip2 = $input['user_regident_zip_2'] ?? $user->user_regident_zip_2 ?? ''; + $pre = $input['user_regident_pre'] ?? $user->user_regident_pre ?? ''; + $city = $input['user_regident_city'] ?? $user->user_regident_city ?? ''; + $add = $input['user_regident_add'] ?? $user->user_regident_add ?? ''; + $zip = ($zip1 && $zip2) ? $zip1.'-'.$zip2 : (($zip1 || $zip2) ? $zip1.$zip2 : ''); + @endphp + {{ $zip }}{{ $pre }}{{ $city }}{{ $add }} +

@@ -67,7 +77,12 @@
-

{{ implode('-', $input['user_homephone']) }}

+

+ @php + $home = array_filter($input['user_homephone'] ?? []); + @endphp + {{ $home ? implode('-', $home) : '' }} +

@foreach ($input['user_homephone'] as $val) @endforeach @@ -77,7 +92,12 @@
-

{{ implode('-', $input['user_mobile']) }}

+

+ @php + $mobile = array_filter($input['user_mobile'] ?? []); + @endphp + {{ $mobile ? implode('-', $mobile) : '' }} +

@foreach ($input['user_mobile'] as $val) @endforeach @@ -145,7 +165,17 @@
-

{{ ($input['user_relate_zip_1'] ?? $user->user_relate_zip_1 ?? '') }}-{{ ($input['user_relate_zip_2'] ?? $user->user_relate_zip_2 ?? '') }}{{ ($input['user_relate_pre'] ?? $user->user_relate_pre ?? '') }}{{ ($input['user_relate_city'] ?? $user->user_relate_city ?? '') }}{{ ($input['user_relate_add'] ?? $user->user_relate_add ?? '') }}

+

+ @php + $zip1 = $input['user_relate_zip_1'] ?? $user->user_relate_zip_1 ?? ''; + $zip2 = $input['user_relate_zip_2'] ?? $user->user_relate_zip_2 ?? ''; + $pre = $input['user_relate_pre'] ?? $user->user_relate_pre ?? ''; + $city = $input['user_relate_city'] ?? $user->user_relate_city ?? ''; + $add = $input['user_relate_add'] ?? $user->user_relate_add ?? ''; + $zip = ($zip1 && $zip2) ? $zip1.'-'.$zip2 : (($zip1 || $zip2) ? $zip1.$zip2 : ''); + @endphp + {{ $zip }}{{ $pre }}{{ $city }}{{ $add }} +

diff --git a/resources/views/user/edit.blade.php b/resources/views/user/edit.blade.php index a99ea55..8bf73ef 100644 --- a/resources/views/user/edit.blade.php +++ b/resources/views/user/edit.blade.php @@ -155,14 +155,14 @@
{{-- メールアドレス --}}
- +
{{-- メールアドレス確認 --}}
- +
@@ -196,18 +196,18 @@
- +
{{-- 学校名(学生のみ表示) --}}
- +
{{-- 卒業予定(学生のみ表示) --}}
- +
@@ -269,8 +269,8 @@ - - + +
{{-- 本人確認書類 --}}