diff --git a/app/Http/Controllers/Admin/PriceListController.php b/app/Http/Controllers/Admin/PriceListController.php index 9c180de..c49a8f3 100644 --- a/app/Http/Controllers/Admin/PriceListController.php +++ b/app/Http/Controllers/Admin/PriceListController.php @@ -32,16 +32,26 @@ class PriceListController extends Controller ]; if ($parkId) { - // parkとprice_aをJOIN + // price_a に必要なマスタを JOIN $aRows = \DB::table('price_a') ->join('park', 'park.park_id', '=', 'price_a.park_id') + ->leftJoin('ptype', 'price_a.ptype_id', '=', 'ptype.ptype_id') + ->leftJoin('usertype', 'price_a.user_categoryid', '=', 'usertype.user_categoryid') + ->leftJoin('pplace', 'price_a.pplace_id', '=', 'pplace.pplace_id') ->where('price_a.park_id', $parkId) - ->select('price_a.*') // 必要ならpark.*も + ->select([ + 'price_a.*', + 'ptype.ptype_subject', + 'usertype.usertype_subject1', + 'usertype.usertype_subject2', + 'usertype.usertype_subject3', + 'pplace.pplace_number' + ]) ->get(); $aGrouped = $this->groupPriceRows($aRows); - $masterList[0]['groups'] = $aGrouped; + // マスターBも同様に取得・整形する場合はここに追加 } @@ -60,85 +70,103 @@ class PriceListController extends Controller $result = []; foreach ($rows as $row) { // グループキーは分類ID+ユーザ分類ID+駐輪場ID - $key = $row->price_ptypeid . '-' . $row->user_categoryid . '-' . $row->park_id; + $key = $row->ptype_id . '-' . $row->user_categoryid . '-' . $row->park_id; if (!isset($result[$key])) { $result[$key] = [ 'id' => $row->price_parkplaceid, - 'classification' => $row->price_ptypeid, - 'room_number' => '', // 必要ならpplace_id等をセット - 'category1' => $row->prine_name ?? '', - 'category2' => '', - 'category3' => '', - 'bike_1m' => '', - 'bike_2m' => '', - 'bike_3m' => '', - 'bike_6m' => '', - 'bike_12m' => '', - // 必要なら原付・自動二輪も同様に追加 + 'classification' => $row->ptype_subject ?? '', + 'room_number' => $row->pplace_number ?? '', + 'category1' => $row->usertype_subject1 ?? '', + 'category2' => $row->usertype_subject2 ?? '', + 'category3' => $row->usertype_subject3 ?? '', + 'bike_1m' => '', 'bike_2m' => '', 'bike_3m' => '', 'bike_6m' => '', 'bike_12m' => '', + 'moped_1m' => '', 'moped_2m' => '', 'moped_3m' => '', 'moped_6m' => '', 'moped_12m' => '', + 'motorcycle_1m' => '', 'motorcycle_2m' => '', 'motorcycle_3m' => '', 'motorcycle_6m' => '', 'motorcycle_12m' => '', + 'car_1m' => '', 'car_2m' => '', 'car_3m' => '', 'car_6m' => '', 'car_12m' => '', ]; } - // 月数ごとに金額をセット - if ($row->price_month == 1) { - $result[$key]['bike_1m'] = $row->price; - } elseif ($row->price_month == 2) { - $result[$key]['bike_2m'] = $row->price; - } elseif ($row->price_month == 3) { - $result[$key]['bike_3m'] = $row->price; - } elseif ($row->price_month == 6) { - $result[$key]['bike_6m'] = $row->price; - } elseif ($row->price_month == 12) { - $result[$key]['bike_12m'] = $row->price; + $month = $row->price_month; + $price = $row->price; + switch ($row->psection_id) { + case 1: + $result[$key]["bike_{$month}m"] = $price; + break; + case 2: + $result[$key]["moped_{$month}m"] = $price; + break; + case 3: + $result[$key]["motorcycle_{$month}m"] = $price; + break; + case 4: + $result[$key]["car_{$month}m"] = $price; + break; } } return array_values($result); } - public function update(Request $request) - { - foreach ($request->input('rows', []) as $row) { - $id = $row['id'] ?? null; - if (!$id) continue; +public function update(Request $request) +{ + foreach ($request->input('rows', []) as $row) { + $id = $row['id'] ?? null; + if (!$id) continue; - // 更新対象の月リスト - $months = [ - 'bike_1m' => 1, - 'bike_2m' => 2, - 'bike_3m' => 3, - 'bike_6m' => 6, - 'bike_12m' => 12, - ]; + $vehicleTypes = [ + 'bike' => 1, + 'moped' => 2, + 'motorcycle' => 3, + 'car' => 4, + ]; - foreach ($months as $field => $month) { + $months = [1, 2, 3, 6, 12]; + + foreach ($vehicleTypes as $prefix => $psectionId) { + foreach ($months as $month) { + $field = "{$prefix}_{$month}m"; if (isset($row[$field])) { - // price_aから該当レコードを取得 - $item = \App\Models\PriceA::where('price_parkplaceid', $id) + $value = $row[$field]; + + // バリデーション:空欄はスキップ + if (!ctype_digit((string)$value)) { + return back()->withErrors([ + "{$field}" => "金額は整数で入力してください。" + ]); + } + + // バリデーション:最大値を超えないこと + if ((int)$value > 9999999999) { + return back()->withErrors([ + "{$field}" => "金額は最大 9,999,999,999 までです。" + ]); + } + + $item = PriceA::where('price_parkplaceid', $id) ->where('price_month', $month) + ->where('psection_id', $psectionId) ->first(); if ($item) { - $item->price = $row[$field]; + $item->price = $value; $item->save(); } } } - // 原付・自動二輪も同様に必要なら追加 } - return back()->with('success', '金額を更新しました'); } + return back()->with('success', '金額を更新しました'); +} public function insert(Request $request) { - // 例:bike_2m(2ヶ月)だけ新規追加する場合 if ($request->filled('bike_2m')) { - $row = new \App\Models\PriceA(); - $row->park_id = $request->input('park_id'); // 必要に応じて + $row = new PriceA(); + $row->park_id = $request->input('park_id'); $row->price = $request->input('bike_2m'); $row->price_month = 2; - // 他の必要なカラムもセット + $row->psection_id = 1; // 自転車 $row->save(); } - // 他の月も同様に必要なら追加 return back()->with('success', '金額を追加しました'); } -} +} \ No newline at end of file diff --git a/resources/views/admin/PriceList/list.blade.php b/resources/views/admin/PriceList/list.blade.php index 18afd61..c6f063f 100644 --- a/resources/views/admin/PriceList/list.blade.php +++ b/resources/views/admin/PriceList/list.blade.php @@ -1,129 +1,177 @@ @extends('layouts.app') @section('content') -