You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2KB

  1. <?php
  2. namespace App\Http\Controllers\Web\SeasonTicketContract;
  3. use App\Exceptions\GeneralErrorMessageException;
  4. use App\Http\Controllers\Web\FromKintoneController;
  5. use App\Transmissions\HTICWeb\Sender;
  6. use Illuminate\Http\JsonResponse;
  7. use Illuminate\Http\Request;
  8. class BeforeUpdateController extends FromKintoneController
  9. {
  10. public function name(): string
  11. {
  12. return "IC定期用 契約更新確認";
  13. }
  14. public function description(): string
  15. {
  16. return "IC定期用 契約更新確認";
  17. }
  18. use Sender;
  19. public function __construct(protected BeforeUpdateParam $param)
  20. {
  21. parent::__construct();
  22. }
  23. protected function run(Request $request): JsonResponse
  24. {
  25. $param = $this->param;
  26. // 名称からコード値へ変換
  27. $res = $this->getSeasonTicketContractParams($param->toArray());
  28. $contractorType = $this->getKey($res->json("data.contractor_type"), $param->contractorTypeName);
  29. $parkingUseType = $this->getKey($res->json("data.parking_use_type"), $param->parkingUseTypeName);
  30. $vehicleType = $this->getKey($res->json("data.vehicle_type"), $param->vehicleTypeName);
  31. if ($contractorType === null) {
  32. throw new GeneralErrorMessageException("契約者タイプ不正");
  33. }
  34. if ($parkingUseType === null) {
  35. throw new GeneralErrorMessageException("駐車場利用方法不正");
  36. }
  37. if ($vehicleType === null) {
  38. throw new GeneralErrorMessageException("車両タイプ不正");
  39. }
  40. $res = $this->sendSeasonTicketContractUpdate(
  41. [
  42. ...$param->toArray(),
  43. 'contractor_type_line_no' => $contractorType,
  44. 'vehicle_type' => $vehicleType,
  45. 'parking_use_type' => $parkingUseType,
  46. ]
  47. );
  48. return $this->successResponse($res->json("data"));
  49. }
  50. private function getKey(array $list, string $targetName)
  51. {
  52. foreach ($list as $ele) {
  53. $key = array_key_first($ele);
  54. $val = $ele[$key];
  55. if ($val === $targetName) {
  56. return $key;
  57. }
  58. }
  59. return null;
  60. }
  61. }