main_watanabe #65

Merged
y.watanabe merged 3 commits from main_watanabe into main 2026-02-03 15:42:09 +09:00
8 changed files with 102 additions and 46 deletions
Showing only changes of commit 73ebe11e77 - Show all commits

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Http\Controllers;
use App\Http\Traits\AuthenticatesUser;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
@ -14,6 +15,8 @@ use function base_path;
class ReceiptController extends Controller
{
use AuthenticatesUser;
/**
* 領収書宛名入力画面を表示する。
* 契約IDに基づき、領収書宛名入力フォームを表示する。
@ -24,13 +27,12 @@ class ReceiptController extends Controller
*/
public function input(string $management_code, string $contract_id): mixed
{
$user_id = session('user_id');
if (!$user_id) {
// 未認証アクセスセッション切れを追跡するため、INFOログで記録
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書宛名入力画面アクセス");
return redirect()->guest('/login');
if ($redirect = $this->handleSessionExpired('領収書宛名入力', false)) {
return $redirect;
}
// ヘッダー表示のためユーザー名取得
$user_id = session('user_id');
$user_name = DB::table('user')->where('user_id', $user_id)->value('user_name');
$management = session('management');
@ -70,13 +72,12 @@ class ReceiptController extends Controller
*/
public function issue(Request $request, string $management_code, string $contract_id): mixed
{
$user_id = session('user_id');
if (!$user_id) {
// 未認証アクセスセッション切れを追跡するため、INFOログで記録
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書発行");
return redirect('/login');
if ($redirect = $this->handleSessionExpired('領収書宛名入力', false)) {
return $redirect;
}
$user_id = session('user_id');
// 既存レコードがある場合、再発行を促す
$exists = DB::table('inv_publish')->where('contract_id', $contract_id)->exists();
if ($exists) {
@ -148,12 +149,11 @@ class ReceiptController extends Controller
public function download(string $management_code, string $contract_id, bool $is_reissue = true): mixed
{
try {
$user_id = session('user_id');
if (!$user_id) {
// 未認証アクセスセッション切れを追跡するため、INFOログで記録
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書ダウンロード");
return redirect('/login');
if ($redirect = $this->handleSessionExpired('領収書ダウンロード', false)) {
return $redirect;
}
$user_id = session('user_id');
$management = session('management');
$management_id = $management->management_id;
@ -179,24 +179,23 @@ class ReceiptController extends Controller
->where('management_id', $management_id)
->first();
$krgmStoragePath = config('app.krgm_storage_path');
$linkPath = public_path('other-storage');
if (!file_exists($krgmStoragePath)) {
\Log::error('KRGM path not found: ' . $krgmStoragePath);
abort(404, '画像パスが見つかりません。');
}
if (!file_exists($linkPath)) {
$result = symlink($krgmStoragePath, $linkPath);
\Log::info('Symlink result: ' . ($result ? 'success' : 'failed'));
if (!$result) {
\Log::error('Symlink failed');
abort(500, 'リンク作成失敗');
// 社員側の社判画像を参照するため、シンボリックリンクを作成 (company_image_path が存在する場合のみ)
if (!empty($inv_setting->company_image_path)) {
$krgmStoragePath = config('app.krgm_storage_path');
$linkPath = public_path('other-storage');
if (!file_exists($krgmStoragePath)) {
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " 社判画像保存フォルダ発見不可: " . $krgmStoragePath . ", user_id=" . $user_id . ", contract_id=" . $contract_id);
throw new \Exception();
}
if (!file_exists($linkPath)) {
$result = symlink($krgmStoragePath, $linkPath);
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 社判画像参照リンク作成。結果: " . ($result ? '成功' : '失敗') . ", user_id=" . $user_id . ", contract_id=" . $contract_id);
if (!$result) {
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " 社判画像参照リンク作成失敗。user_id=" . $user_id . ", contract_id=" . $contract_id);
throw new \Exception();
}
}
}
if (!file_exists($linkPath)) {
symlink($krgmStoragePath, $linkPath);
}
// ダウンロード回数をカウントアップ
DB::table('inv_publish')
@ -244,7 +243,7 @@ class ReceiptController extends Controller
->header('Content-Disposition', 'attachment; filename="receipt_' . $contract_id . '.pdf"');
} catch (\Exception $e) {
// PDF生成エラーを記録
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " PDFダウンロードエラー: user_id=" . $user_id . ", contract_id=" . $contract_id . ", error=" . $e->getMessage());
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " 領収書PDFダウンロードエラー: user_id=" . $user_id . ", contract_id=" . $contract_id . ", error=" . $e->getMessage());
abort(500, '領収書ダウンロードに失敗しました。');
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Http\Controllers;
use App\Http\Traits\AuthenticatesUser;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@ -12,6 +13,7 @@ use Carbon\Carbon;
class RegularContractController extends Controller
{
use AuthenticatesUser;
public function showInfo(Request $request)
{
$user_id = session('user_id');
@ -89,13 +91,12 @@ class RegularContractController extends Controller
* @param Request $request 受信したHTTPリクエスト
* @return mixed ビュー応答またはリダイレクト
*/
$user_id = session('user_id');
if (!$user_id) {
// 未認証アクセスセッション切れを追跡するため、INFOログで記録
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 定期契約履歴確認画面アクセス");
return redirect()->guest('/login');
if ($redirect = $this->handleSessionExpired('定期契約履歴確認')) {
return $redirect;
}
// ヘッダー表示のためユーザー名取得
$user_id = session('user_id');
$user_name = DB::table('user')->where('user_id', $user_id)->value('user_name');
// マルチテナント対応のため、運営元コード、IDを取得

View File

@ -6,8 +6,6 @@ use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Response;
use Illuminate\Http\RedirectResponse;
class ManagementMiddleware
{
@ -17,10 +15,10 @@ class ManagementMiddleware
*
* @param Request $request 受信したHTTPリクエスト
* @param Closure $next 次のミドルウェア処理
* @return Response 次の処理のレスポンス
* @return mixed 次の処理のレスポンス
* @throws \Symfony\Component\HttpKernel\Exception\HttpException 運営元コードが見つからない場合
*/
public function handle(Request $request, Closure $next): Response|RedirectResponse
public function handle(Request $request, Closure $next): mixed
{
// マルチテナント対応のため、URLの最初のセグメントを運営元コードとして扱う
$path = $request->getPathInfo(); // パス全体を取得

View File

@ -0,0 +1,48 @@
<?php
namespace App\Http\Traits;
trait AuthenticatesUser
{
/**
* セッション切れ時のログインリダイレクト(マルチテナント対応)
*
* @param string|null $screenName ログに記録する画面名
* @param bool $saveIntended ログイン後に元のURLに戻るかtrue: 戻る, false: マイページ)
* @return \Illuminate\Http\RedirectResponse|null
*/
protected function handleSessionExpired(?string $screenName = null, bool $saveIntended = true)
{
$userId = session('user_id');
if ($userId) {
return null; // 認証済み
}
// 運営元コード取得
$management = session('management');
$managementCode = $management->management_code ?? request()->segment(1);
if (!$managementCode) {
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " 運営元取得失敗 url=" . request()->fullUrl());
abort(404);
}
// ログ記録
$logMessage = "[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーアクセス(セッション切れ)";
if ($screenName) {
$logMessage .= " {$screenName}画面";
}
$logMessage .= " management_code=" . $managementCode;
\Log::info($logMessage);
if ($saveIntended) {
// ログイン後に元の画面に戻る
return redirect()->guest(route('swo8_1', ['management_code' => $managementCode]));
} else {
// ログイン後はマイページトップへ
session()->forget('url.intended');
return redirect()->route('swo8_1', ['management_code' => $managementCode]);
}
}
}

View File

@ -123,6 +123,16 @@ return [
'store' => env('APP_MAINTENANCE_STORE', 'database'),
],
/*
|--------------------------------------------------------------------------
| KRGM Storage Path
|--------------------------------------------------------------------------
|
| This value is the path to the KRGM storage directory for accessing images
| from the other project via symbolic link.
|
*/
'krgm_storage_path' => env('KRGM_STORAGE_PATH'),
];

View File

@ -40,7 +40,7 @@
@yield('content')
</main>
{{-- フッター --}}
@include('partials.footer')
@include('partials.general_footer')
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="{{ asset('assets/js/vendor/popper.min.js') }}"></script>

View File

@ -25,7 +25,7 @@ $management_code = $management ? $management->management_code : '';
<li class="nav-item {{ $active_menu == 'SWC-8-1' ? 'active' : '' }}"><a class="nav-link" href="{{ route('regular_contract.create', ['management_code' => $management_code]) }}">新規定期契約</a></li>
<li class="nav-item {{ $active_menu == 'SWC-11-1' ? 'active' : '' }}"><a class="nav-link" href="{{ route('park_waitlist.index', ['management_code' => $management_code]) }}">空き待ち状況確認</a></li>
<li class="nav-item {{ $active_menu == 'SWC-10-1' ? 'active' : '' }}"><a class="nav-link" href="{{ route('park_search', ['management_code' => $management_code]) }}">駐輪場検索</a></li>
<li class="nav-item"><a class="nav-link" href="{{ route('swo16_1') }}" target="_blank">このページの使い方</a></li>
<li class="nav-item"><a class="nav-link" href="{{ route('swo16_1', ['management_code' => $management_code]) }}" target="_blank">このページの使い方</a></li>
</ul>
</div>
</nav>

View File

@ -122,9 +122,9 @@
<td>
<div class="company">
<span style="font-size:20px; font-weight:bold;">{{ $inv_setting->t_name ?? '' }}</span><br>
{{ $inv_setting->zipcode ?? '' }}<br>
{{ $inv_setting->adrs ?? '' }}<br>
適格事業者番号:{{ $inv_setting->t_number ?? '' }}<br>
{{ $inv_setting->zipcode }}<br>
{{ $inv_setting->adrs }}@if(!empty($inv_setting->bldg)){{ $inv_setting->bldg }}@endif
<br>適格事業者番号:{{ $inv_setting->t_number ?? '' }}<br>
@if(!empty($inv_setting->tel_num))
TEL:{{ $inv_setting->tel_num}}<br>
@endif