9/12 マージ #18

Merged
y.watanabe merged 1 commits from main_watanabe into main 2025-09-12 18:44:44 +09:00
Showing only changes of commit 9c3aaaeee7 - Show all commits

View File

@ -12,10 +12,86 @@ class ParkingSearchController extends Controller
// 初期表示 // 初期表示
public function index() public function index()
{ {
// 検索仕様
// 駐輪場マスタの全件(条件を絞った場合はその条件に一致するもの)を取得。
// 併せて各マスタから追加情報を取得するが、その際のレコードは全て1対1で結びつく想定で暫定実装する
// ※設計書に詳細な記載なし。DBの定義上は1対多の可能性もあるが、その場合現在の画面イメージと矛盾するため、実態として無い想定で進める
// 駐輪場情報検索 // 駐輪場情報検索
$park = \DB::table('park')->get(); $park = \DB::table('park as p')
->select(
'p.park_name',
'p.update_grace_period_start_date',
'p.update_grace_period_start_time',
'p.update_grace_period_end_date',
'p.update_grace_period_end_time',
'c.city_name',
's.station_neighbor_station',
'z.psection_id'
)
->leftJoin('city as c', 'p.city_id', '=', 'c.city_id')
->leftJoin(\DB::raw(
'(SELECT park_id, station_neighbor_station FROM station WHERE station_id IN (SELECT MAX(station_id) FROM station GROUP BY park_id)) as s'
),'p.park_id','=','s.park_id')
->leftJoin('zone as z', 'p.park_id', '=', 'z.park_id')
//->where('p.park_name', 'a')
//->where('c.city_name', 'b')
//->where('s.station_neighbor_station', 'c')
->orderBy('p.park_ruby')
->get();
// 各マスタから追加情報を取得し、各ボタンの表示有無を判定する
$result = [];
$now = date('Y-m-d H:i:s');
foreach ($park as $row) {
// ゾーンマスタの情報から空き台数を取得する
$vacantInfo = \DB::table('zone')
->selectRaw('SUM(zone_tolerance) - SUM(zone_number) as vacant')
->where('psection_id', $row->psection_id)
->groupBy('psection_id')
->first();
// 定期予約マスタから予約中の台数を取得する
$reservedCount = \DB::table('reserve')
->where('psection_id', $row->psection_id)
->where('valid_flag', 1)
->count();
// 空き台数を計算
$vacant = ($vacantInfo ? $vacantInfo->vacant : 0) - $reservedCount;
// 更新期間内判定
$update_start = $row->update_grace_period_start_date . ' ' . $row->update_grace_period_start_time;
$update_end = $row->update_grace_period_end_date . ' ' . $row->update_grace_period_end_time;
$is_update_period = ($now >= $update_start && $now <= $update_end);
// ボタン表示有無判定
if ($vacant > 0 && $is_update_period) { // 定期契約ボタン (空き台数が1台以上かつ更新期間内)
$status = 1;
} elseif ($vacant <= 0 && $is_update_period) { // 当日予約ボタン (空き台数が0台以下かつ更新期間内)
$status = 2;
} elseif ($vacant <= 0 && !$is_update_period) { // 販売期間外ボタン (空き台数が0台以下かつ更新期間外)
$status = 3;
} else {
$status = null;
}
// 画面返却用データに追加
$result[] = [
'park_name' => $row->park_name,
'city_name' => $row->city_name,
'station_neighbor_station' => $row->station_neighbor_station,
'status' => $status
];
}
// 検索用プルダウン取得
$cities = \DB::table('city')->select('city_name')->orderBy('city_ruby')->get();
$stations = \DB::table('station')->select('station_neighbor_station')->distinct()->orderBy('station_neighbor_station')->get();
$parkings = ['全て', 'あ行', 'か行', 'さ行', 'た行', 'な行', 'は行', 'ま行', 'や行', 'ら行', 'わ行'];
// 検索結果返却 // 検索結果返却
return view('general.swo5_1',['form_data' => $result ]); return view('general.swo5_1',['form_data' => $result, 'cities' => $cities, 'stations' => $stations, 'parkings' => $parkings]);
} }
} }