| @@ -0,0 +1,55 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\Customer; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use App\Kintone\Models\Customer; | |||||
| use App\Util\DateUtil; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class UploadOtherLicenseImagesController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "その他証明証画像アップロード"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "その他証明証画像をアップロードする"; | |||||
| } | |||||
| public function __construct(protected UploadOtherLicenseImagesParam $param) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| $param = $this->param; | |||||
| $customer = Customer::getSelf(); | |||||
| $access = Customer::getAccess(); | |||||
| $data = []; | |||||
| foreach ($param->images as $index => $file) { | |||||
| $data[] = [ | |||||
| 'fileKey' => $access->filePut($file), | |||||
| 'name' => sprintf("image_%d.%s", $index, $file->extension()), | |||||
| 'contentType' => $file->getClientMimeType(), | |||||
| ]; | |||||
| } | |||||
| $customer->set(Customer::FIELD_OTHER_LICENSE_IMAGES, $data); | |||||
| $customer->set(Customer::FIELD_OTHER_LICENSE_IMAGES_UPLOAD_DATETIME, DateUtil::now()); | |||||
| $access->update($customer); | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\Customer; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| use Illuminate\Http\UploadedFile; | |||||
| /** | |||||
| * @property UploadedFile[] $images | |||||
| */ | |||||
| class UploadOtherLicenseImagesParam extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return $this->images('images'); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,55 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\Customer; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use App\Kintone\Models\Customer; | |||||
| use App\Util\DateUtil; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class UploadStudentLicenseImagesController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "学生証画像アップロード"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "学生証画像をアップロードする"; | |||||
| } | |||||
| public function __construct(protected UploadStudentLicenseImagesParam $param) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| $param = $this->param; | |||||
| $customer = Customer::getSelf(); | |||||
| $access = Customer::getAccess(); | |||||
| $data = []; | |||||
| foreach ($param->images as $index => $file) { | |||||
| $data[] = [ | |||||
| 'fileKey' => $access->filePut($file), | |||||
| 'name' => sprintf("image_%d.%s", $index, $file->extension()), | |||||
| 'contentType' => $file->getClientMimeType(), | |||||
| ]; | |||||
| } | |||||
| $customer->set(Customer::FIELD_STUDENT_LICENSE_IMAGES, $data); | |||||
| $customer->set(Customer::FIELD_STUDENT_LICENSE_IMAGES_UPLOAD_DATETIME, DateUtil::now()); | |||||
| $access->update($customer); | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\Customer; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| use Illuminate\Http\UploadedFile; | |||||
| /** | |||||
| * @property UploadedFile[] $images | |||||
| */ | |||||
| class UploadStudentLicenseImagesParam extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return $this->images('images'); | |||||
| } | |||||
| } | |||||
| @@ -171,14 +171,16 @@ class KintoneAccess | |||||
| */ | */ | ||||
| public function update(KintoneModel &$model) | public function update(KintoneModel &$model) | ||||
| { | { | ||||
| $response = Http::withHeaders([ | |||||
| "X-Cybozu-API-Token" => $this->apiToken, | |||||
| ])->put($this->getRecordUrl(), [ | |||||
| $sendData = [ | |||||
| "app" => $this->appId, | "app" => $this->appId, | ||||
| "id" => $model->getRecordId(), | "id" => $model->getRecordId(), | ||||
| "record" => $model->getApiLayout(), | "record" => $model->getApiLayout(), | ||||
| "revision" => $model->getRevision(), | "revision" => $model->getRevision(), | ||||
| ]); | |||||
| ]; | |||||
| $response = Http::withHeaders([ | |||||
| "X-Cybozu-API-Token" => $this->apiToken, | |||||
| ])->put($this->getRecordUrl(), $sendData); | |||||
| if ($response->failed()) { | if ($response->failed()) { | ||||
| $e = $response->toException(); | $e = $response->toException(); | ||||
| @@ -387,15 +389,18 @@ class KintoneAccess | |||||
| */ | */ | ||||
| public function filePut(UploadedFile $file): string | public function filePut(UploadedFile $file): string | ||||
| { | { | ||||
| $content = file_get_contents($file); | |||||
| $response = Http::withHeaders([ | $response = Http::withHeaders([ | ||||
| "X-Cybozu-API-Token" => $this->apiToken, | "X-Cybozu-API-Token" => $this->apiToken, | ||||
| "Content-Type" => "multipart/form-data", | |||||
| ])->post($this->getFileUrl(), $file); | |||||
| ]) | |||||
| ->attach("file", $content, sprintf("file.%s", $file->extension())) | |||||
| ->post($this->getFileUrl()); | |||||
| if ($response->failed()) { | if ($response->failed()) { | ||||
| $e = $response->toException(); | $e = $response->toException(); | ||||
| if ($e instanceof Exception) { | if ($e instanceof Exception) { | ||||
| Log::error($e->getMessage()); | Log::error($e->getMessage()); | ||||
| Log::error($response->body()); | |||||
| throw $e; | throw $e; | ||||
| } | } | ||||
| } | } | ||||
| @@ -17,6 +17,9 @@ class Customer extends KintoneModel | |||||
| const FIELD_EMAIL = "メールアドレス"; | const FIELD_EMAIL = "メールアドレス"; | ||||
| const FIELD_PHONE_NUMBER = "電話番号"; | const FIELD_PHONE_NUMBER = "電話番号"; | ||||
| const FIELD_STUDENT_LICENSE_IMAGES = "学生証画像"; | const FIELD_STUDENT_LICENSE_IMAGES = "学生証画像"; | ||||
| const FIELD_OTHER_LICENSE_IMAGES = "その他証明証画像"; | |||||
| const FIELD_STUDENT_LICENSE_IMAGES_UPLOAD_DATETIME = "学生証画像更新日時"; | |||||
| const FIELD_OTHER_LICENSE_IMAGES_UPLOAD_DATETIME = "その他証明証画像更新日時"; | |||||
| protected const FIELDS = [ | protected const FIELDS = [ | ||||
| ...parent::FIELDS, | ...parent::FIELDS, | ||||
| @@ -26,12 +29,17 @@ class Customer extends KintoneModel | |||||
| self::FIELD_EMAIL => FieldType::LINK, | self::FIELD_EMAIL => FieldType::LINK, | ||||
| self::FIELD_PHONE_NUMBER => FieldType::LINK, | self::FIELD_PHONE_NUMBER => FieldType::LINK, | ||||
| self::FIELD_STUDENT_LICENSE_IMAGES => FieldType::FILE, | self::FIELD_STUDENT_LICENSE_IMAGES => FieldType::FILE, | ||||
| self::FIELD_OTHER_LICENSE_IMAGES => FieldType::FILE, | |||||
| self::FIELD_STUDENT_LICENSE_IMAGES_UPLOAD_DATETIME => FieldType::DATETIME, | |||||
| self::FIELD_OTHER_LICENSE_IMAGES_UPLOAD_DATETIME => FieldType::DATETIME, | |||||
| ]; | ]; | ||||
| protected const FIELD_NAMES = [ | protected const FIELD_NAMES = [ | ||||
| ...parent::FIELD_NAMES, | ...parent::FIELD_NAMES, | ||||
| self::FIELD_CUSTOMER_NAME => 'customer_name', | self::FIELD_CUSTOMER_NAME => 'customer_name', | ||||
| self::FIELD_EMAIL => 'email', | self::FIELD_EMAIL => 'email', | ||||
| self::FIELD_STUDENT_LICENSE_IMAGES_UPLOAD_DATETIME => 'student_license_images_upload_datetime', | |||||
| self::FIELD_OTHER_LICENSE_IMAGES_UPLOAD_DATETIME => 'other_license_images_upload_datetime', | |||||
| ]; | ]; | ||||
| public static function getSelf(): static | public static function getSelf(): static | ||||
| @@ -29,3 +29,4 @@ RouteHelper::get('/faq', App\Http\Controllers\Web\FAQ\FAQsController::class); | |||||
| RouteHelper::get('/faq/genres', App\Http\Controllers\Web\FAQ\FAQGenresController::class); | RouteHelper::get('/faq/genres', App\Http\Controllers\Web\FAQ\FAQGenresController::class); | ||||
| RouteHelper::post('/ask', App\Http\Controllers\Web\FAQ\AskController::class); | RouteHelper::post('/ask', App\Http\Controllers\Web\FAQ\AskController::class); | ||||
| RouteHelper::post('/upload/student-license-images', App\Http\Controllers\Web\Customer\UploadStudentLicenseImagesController::class); | RouteHelper::post('/upload/student-license-images', App\Http\Controllers\Web\Customer\UploadStudentLicenseImagesController::class); | ||||
| RouteHelper::post('/upload/other-license-images', App\Http\Controllers\Web\Customer\UploadOtherLicenseImagesController::class); | |||||