All checks were successful
Deploy preview (main_higashide) / deploy (push) Successful in 11s
214 lines
9.8 KiB
PHP
214 lines
9.8 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Http\Request;
|
||
|
||
class RegularContractController extends Controller
|
||
{
|
||
public function showInfo()
|
||
{
|
||
$user_id = session('user_id');
|
||
if (!$user_id) {
|
||
return redirect('/login');
|
||
}
|
||
$user_name = DB::table('user')->where('user_id', $user_id)->value('user_name');
|
||
|
||
$today = date('Y-m-d');
|
||
// 定期契約情報を取得(park/usertype/psection/ptypeテーブルもJOIN)
|
||
$contracts = DB::table('regular_contract')
|
||
->join('park', 'regular_contract.park_id', '=', 'park.park_id')
|
||
->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid')
|
||
->leftJoin('city', 'park.city_id', '=', 'city.city_id')
|
||
->leftJoin('psection', 'regular_contract.psection_id', '=', 'psection.psection_id')
|
||
->leftJoin('ptype', 'regular_contract.ptype_id', '=', 'ptype.ptype_id')
|
||
->where('regular_contract.user_id', $user_id)
|
||
->where('regular_contract.contract_flag', 1)
|
||
->where('regular_contract.contract_cancel_flag', 0)
|
||
->where(function ($query) use ($today) {
|
||
$query->where('regular_contract.contract_periode', '>', $today)
|
||
->orWhere(function ($q) use ($today) {
|
||
$q->where('regular_contract.contract_periode', '<=', $today)
|
||
->whereRaw('DATEDIFF(?, regular_contract.contract_periode) <= 5', [$today]);
|
||
});
|
||
})
|
||
->select(
|
||
'regular_contract.contract_id',
|
||
'park.park_name',
|
||
'usertype.usertype_subject1',
|
||
'regular_contract.contract_periods',
|
||
'regular_contract.contract_periode',
|
||
'regular_contract.enable_months',
|
||
'regular_contract.contract_renewal',
|
||
'regular_contract.park_id',
|
||
'city.update_grace_period_start_date',
|
||
'city.update_grace_period_start_time',
|
||
'city.update_grace_period_end_date',
|
||
'city.update_grace_period_end_time',
|
||
'psection.psection_subject',
|
||
'ptype.ptype_subject',
|
||
'regular_contract.pplace_no'
|
||
)
|
||
->get();
|
||
|
||
\Log::info('契約情報表示画面にアクセス', [
|
||
'user_id' => $user_id,
|
||
]);
|
||
|
||
|
||
return view('regular_contract.info', [
|
||
'active_menu' => 'SWC-3-1', // マイページメニューの選択状態用
|
||
'user_name' => $user_name, // ユーザー名(ヘッダー用)
|
||
'contracts' => $contracts,
|
||
]);
|
||
}
|
||
|
||
public function update($contract_id)
|
||
{
|
||
$user_id = session('user_id');
|
||
if (!$user_id) {
|
||
return redirect('/login');
|
||
}
|
||
|
||
// 元契約データ取得
|
||
$old_contract = DB::table('regular_contract')->where('contract_id', $contract_id)->first();
|
||
|
||
// 新規レコード作成(必要な項目を元契約データから引き継ぐ)
|
||
$new_contract_id = DB::table('regular_contract')->insertGetId([
|
||
'old_contract_id' => $old_contract->contract_id,
|
||
'user_id' => $old_contract->user_id,
|
||
'user_categoryid' => $old_contract->user_categoryid,
|
||
'created_at' => now(),
|
||
'updated_at' => now(),
|
||
'park_id' => $old_contract->park_id,
|
||
'price_parkplaceid' => $old_contract->price_parkplaceid,
|
||
'user_securitynum' => $old_contract->user_securitynum,
|
||
'contract_created_at' => now(),
|
||
'contract_reduction' => $old_contract->contract_reduction,
|
||
'update_flag' => 1,
|
||
'contract_cancel_flag' => 0,
|
||
'800m_flag' => 0,
|
||
'psection_id' => $old_contract->psection_id,
|
||
'zone_id' => $old_contract->zone_id,
|
||
'pplace_no' => $old_contract->pplace_no
|
||
]);
|
||
|
||
// contract_qr_id生成(AES-256-CBC暗号化)
|
||
$key = "LJLASR4FAS34SAADFA72ASDFALLSDRGT";
|
||
$iv = substr(hash('sha256', $key), 0, 16); // IVは16バイト
|
||
$encrypted = openssl_encrypt($new_contract_id, 'AES-256-CBC', $key, 0, $iv);
|
||
|
||
// contract_qr_idを更新
|
||
DB::table('regular_contract')->where('contract_id', $new_contract_id)->update([
|
||
'contract_qr_id' => $encrypted
|
||
]);
|
||
|
||
// 完了後の遷移
|
||
return redirect()->route('regular_contract.confirm_category', ['contract_id' => $new_contract_id]);
|
||
}
|
||
|
||
public function confirmCategory($contract_id)
|
||
{
|
||
$user_id = session('user_id');
|
||
if (!$user_id) {
|
||
return redirect('/login');
|
||
}
|
||
$user = DB::table('user')->where('user_id', $user_id)->first();
|
||
|
||
// regular_contractとparkをJOINしてsecurityreg_display_flagを取得
|
||
$contract = DB::table('regular_contract')
|
||
->join('park', 'regular_contract.park_id', '=', 'park.park_id')
|
||
->where('regular_contract.contract_id', $contract_id)
|
||
->select('regular_contract.*', 'park.securityreg_display_flag')
|
||
->first();
|
||
|
||
return view('regular_contract.confirm_category', [
|
||
'active_menu' => 'SWC-4-3', // マイページメニューの選択状態用
|
||
'user_name' => $user ? $user->user_name : '', // ユーザー名(ヘッダー用)
|
||
'user' => $user,
|
||
'contract' => $contract
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 契約区分確認画面の「確認して進む」ボタン押下時の分岐処理
|
||
* 本人確認書類アップロード画面 or 利用期間選択画面へ遷移
|
||
*
|
||
* 分岐条件は下記の通り:
|
||
* 1. 利用者分類(一般/学生):user.user_categoryid=usertype.user_categoryidのusertype_subject1で判別
|
||
* 2. 利用者分類(減免/減免でない):regular_contract.contract_reduction=1なら減免
|
||
* 3. 駐輪場マスタの設定(減免確認種別):reduction_confirm.reduction_confirm_type(0=確認しない,1=年1回,2=毎更新時)
|
||
* 4. 駐輪場マスタの設定(年度跨ぎ):park.overyear_flag(0/NULL=年跨ぎなし,1=年跨ぎあり)
|
||
* 5. 駐輪場マスタの設定(学生証確認種別):park.student_id_confirm_type(0=確認しない,1=年1回,2=毎更新時)
|
||
* 6. 契約期間に4/1が含まれる場合は年度跨ぎ判定に利用
|
||
* 7. ユーザー区分が「学生」の場合のみ、契約終了日が卒業年月日を超える場合も本人確認書類アップロード画面へ
|
||
*/
|
||
public function confirmCategoryNext($contract_id)
|
||
{
|
||
$user_id = session('user_id');
|
||
if (!$user_id) {
|
||
return redirect('/login');
|
||
}
|
||
// 契約情報取得
|
||
$contract = DB::table('regular_contract')->where('contract_id', $contract_id)->first();
|
||
if (!$contract) {
|
||
return redirect()->back()->with('error', '契約情報が見つかりません');
|
||
}
|
||
// ユーザー情報取得
|
||
$user = DB::table('user')->where('user_id', $user_id)->first();
|
||
// ユーザー区分取得
|
||
$usertype = DB::table('usertype')->where('user_categoryid', $user->user_categoryid)->first();
|
||
// 駐輪場情報取得
|
||
$park = DB::table('park')->where('park_id', $contract->park_id)->first();
|
||
// 減免確認種別取得
|
||
$reduction_confirm = DB::table('reduction_confirm')
|
||
->where('park_id', $contract->park_id)
|
||
->where('user_categoryid', $contract->user_categoryid)
|
||
->first();
|
||
|
||
// 分岐条件
|
||
$reduction_confirm_type = isset($reduction_confirm) ? $reduction_confirm->reduction_confirm_type : 0;
|
||
$student_id_confirm_type = isset($park) ? $park->student_id_confirm_type : 0;
|
||
$overyear_flag = isset($park) ? $park->overyear_flag : 0;
|
||
|
||
// 契約期間に4/1が含まれるか判定
|
||
$contract_start = new \DateTime($contract->contract_periods);
|
||
$contract_end = new \DateTime($contract->contract_periode);
|
||
// 4/1の年は契約開始年
|
||
$april_first = new \DateTime($contract_start->format('Y') . '-04-01');
|
||
// 契約終了日が4/1より前なら翌年の4/1も考慮
|
||
if ($contract_end < $april_first) {
|
||
$april_first->modify('+1 year');
|
||
}
|
||
$includes_april_first = ($contract_start <= $april_first && $contract_end >= $april_first);
|
||
|
||
// ユーザー区分が「学生」の場合のみ卒業年月日判定
|
||
$exceeds_graduation = false;
|
||
if (isset($usertype) && $usertype->usertype_subject1 === '学生') {
|
||
$graduation_date = isset($user) ? $user->user_graduate : null;
|
||
if ($graduation_date) {
|
||
$graduation_dt = new \DateTime($graduation_date);
|
||
$exceeds_graduation = ($contract_end > $graduation_dt);
|
||
}
|
||
}
|
||
|
||
// 本人確認書類アップロード画面へ遷移する条件
|
||
// 1. reduction_confirm_typeが1(年1回)または2(毎更新時)
|
||
// 2. student_id_confirm_typeが1(年1回)または2(毎更新時)
|
||
// 3. 年度跨ぎ(overyear_flag=1以外)かつ契約期間に4/1が含まれる場合
|
||
if (
|
||
in_array($reduction_confirm_type, [1, 2]) ||
|
||
in_array($student_id_confirm_type, [1, 2]) ||
|
||
($overyear_flag != 1 && $includes_april_first) ||
|
||
$exceeds_graduation
|
||
) {
|
||
// 本人確認書類アップロード画面へ
|
||
return redirect()->route('regular_contract.upload_identity', ['contract_id' => $contract_id]);
|
||
} else {
|
||
// 利用期間選択画面へ
|
||
return redirect()->route('regular_contract.select_period', ['contract_id' => $contract_id]);
|
||
}
|
||
}
|
||
}
|