|
- <?php
-
- namespace App\Http\Controllers\Web\SeasonTicketContract;
-
- use App\Exceptions\GeneralErrorMessageException;
- use App\Http\Controllers\Web\FromKintoneController;
- use App\Transmissions\HTICWeb\Sender;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
-
- class BeforeUpdateController extends FromKintoneController
- {
-
- public function name(): string
- {
- return "IC定期用 契約更新確認";
- }
-
- public function description(): string
- {
- return "IC定期用 契約更新確認";
- }
-
- use Sender;
-
-
- public function __construct(protected BeforeUpdateParam $param)
- {
- parent::__construct();
- }
-
- protected function run(Request $request): JsonResponse
- {
- $param = $this->param;
-
-
- // 名称からコード値へ変換
- $res = $this->getSeasonTicketContractParams($param->toArray());
-
- $contractorType = $this->getKey($res->json("data.contractor_type"), $param->contractorTypeName);
- $parkingUseType = $this->getKey($res->json("data.parking_use_type"), $param->parkingUseTypeName);
- $vehicleType = $this->getKey($res->json("data.vehicle_type"), $param->vehicleTypeName);
-
- if ($contractorType === null) {
- throw new GeneralErrorMessageException("契約者タイプ不正");
- }
- if ($parkingUseType === null) {
- throw new GeneralErrorMessageException("駐車場利用方法不正");
- }
- if ($vehicleType === null) {
- throw new GeneralErrorMessageException("車両タイプ不正");
- }
-
- $res = $this->sendSeasonTicketContractUpdate(
- [
- ...$param->toArray(),
- 'contractor_type_line_no' => $contractorType,
- 'vehicle_type' => $vehicleType,
- 'parking_use_type' => $parkingUseType,
- ]
- );
- return $this->successResponse($res->json("data"));
- }
-
- private function getKey(array $list, string $targetName)
- {
- foreach ($list as $ele) {
- $key = array_key_first($ele);
- $val = $ele[$key];
- if ($val === $targetName) {
- return $key;
- }
- }
- return null;
- }
- }
|