From 7b60dae8e5e933820a2187e181f32118aaa77841 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Tue, 2 Apr 2024 18:55:47 +0900 Subject: [PATCH] =?UTF-8?q?=E7=AB=8B=E3=81=A6=E7=9C=8B=E6=9D=BF=E3=81=AEPD?= =?UTF-8?q?F=E5=87=BA=E5=8A=9B=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AcquisitionAnnouncementController.php | 63 +++ .../AcquisitionAnnouncementParam.php | 9 + .../Controllers/Web/Pdf/TestController.php | 43 ++ app/Http/Controllers/Web/Pdf/TestParam.php | 15 + composer.json | 5 +- composer.lock | 368 +++++++++++++++++- config/app.php | 6 + config/snappy.php | 52 +++ .../acquisition_announcement.blade.php | 79 ++++ resources/views/pdf/test.blade.php | 79 ++++ routes/web.php | 12 + 11 files changed, 729 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php create mode 100644 app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php create mode 100644 app/Http/Controllers/Web/Pdf/TestController.php create mode 100644 app/Http/Controllers/Web/Pdf/TestParam.php create mode 100644 config/snappy.php create mode 100644 resources/views/pdf/qr-service/acquisition_announcement.blade.php create mode 100644 resources/views/pdf/test.blade.php diff --git a/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php b/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php new file mode 100644 index 0000000..c18a02b --- /dev/null +++ b/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php @@ -0,0 +1,63 @@ +sessionUser->shopId(); + + $shop = Shop::findOrFail($shopId); + + $token = AcquisitionTicketToken::whereShopId($shopId) + ->firstOrFail(); + + $url = implode("/", [ + config('app.url'), + "qr-service", + "acquisition", + $token->token, + ]); + + $pdf = PDF::loadView("pdf/qr-service/acquisition_announcement", [ + "url" => $url, + "shopName" => $shop->name, + ]); + + $filename = "acquisition_announcement.pdf"; + + $ret = $pdf->setPaper("A4") + ->setOption('encoding', 'utf-8') + ->inline() + ->header("Content-Disposition", sprintf('inline; filename=%s', $filename)); + + + return $ret; + } +} diff --git a/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php b/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php new file mode 100644 index 0000000..4fbee1f --- /dev/null +++ b/app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php @@ -0,0 +1,9 @@ +setPaper("A4") + ->setOption('encoding', 'utf-8') + ->inline() + ->header("Content-Disposition", sprintf('inline; filename=%s', $filename)); + + + return $ret; + } +} diff --git a/app/Http/Controllers/Web/Pdf/TestParam.php b/app/Http/Controllers/Web/Pdf/TestParam.php new file mode 100644 index 0000000..ba3be38 --- /dev/null +++ b/app/Http/Controllers/Web/Pdf/TestParam.php @@ -0,0 +1,15 @@ +=7.2" + }, + "require-dev": { + "orchestra/testbench": "^7|^8|^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Snappy\\ServiceProvider" + ], + "aliases": { + "PDF": "Barryvdh\\Snappy\\Facades\\SnappyPdf", + "SnappyImage": "Barryvdh\\Snappy\\Facades\\SnappyImage" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\Snappy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Snappy PDF/Image for Laravel", + "keywords": [ + "image", + "laravel", + "pdf", + "snappy", + "wkhtmltoimage", + "wkhtmltopdf" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-snappy/issues", + "source": "https://github.com/barryvdh/laravel-snappy/tree/v1.0.3" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2024-03-09T19:20:39+00:00" + }, { "name": "brick/math", "version": "0.11.0", @@ -130,6 +262,56 @@ ], "time": "2023-12-11T17:09:12+00:00" }, + { + "name": "dasprid/enum", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/6faf451159fb8ba4126b925ed2d78acfce0dc016", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016", + "shasum": "" + }, + "require": { + "php": ">=7.1 <9.0" + }, + "require-dev": { + "phpunit/phpunit": "^7 | ^8 | ^9", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "support": { + "issues": "https://github.com/DASPRiD/Enum/issues", + "source": "https://github.com/DASPRiD/Enum/tree/1.0.5" + }, + "time": "2023-08-25T16:18:39+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -1045,6 +1227,122 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "h4cc/wkhtmltopdf-amd64", + "version": "0.12.4", + "source": { + "type": "git", + "url": "https://github.com/h4cc/wkhtmltopdf-amd64.git", + "reference": "4e2ab2d032a5d7fbe2a741de8b10b8989523c95b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/h4cc/wkhtmltopdf-amd64/zipball/4e2ab2d032a5d7fbe2a741de8b10b8989523c95b", + "reference": "4e2ab2d032a5d7fbe2a741de8b10b8989523c95b", + "shasum": "" + }, + "bin": [ + "bin/wkhtmltopdf-amd64" + ], + "type": "library", + "autoload": { + "psr-4": { + "h4cc\\WKHTMLToPDF\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL Version 3" + ], + "authors": [ + { + "name": "Julius Beckmann", + "email": "github@h4cc.de" + } + ], + "description": "Convert html to pdf using webkit (qtwebkit). Static linked linux binary for amd64 systems.", + "homepage": "http://wkhtmltopdf.org/", + "keywords": [ + "binary", + "convert", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "support": { + "issues": "https://github.com/h4cc/wkhtmltopdf-amd64/issues", + "source": "https://github.com/h4cc/wkhtmltopdf-amd64/tree/master" + }, + "time": "2018-01-15T06:57:33+00:00" + }, + { + "name": "knplabs/knp-snappy", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/snappy.git", + "reference": "98468898b50c09f26d56d905b79b0f52a2215da6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/98468898b50c09f26d56d905b79b0f52a2215da6", + "reference": "98468898b50c09f26d56d905b79b0f52a2215da6", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^2.0||^3.0", + "symfony/process": "^5.0||^6.0||^7.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "pedrotroller/php-cs-custom-fixer": "^2.19", + "phpstan/phpstan": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.0.0", + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KNP Labs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "description": "PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "homepage": "http://github.com/KnpLabs/snappy", + "keywords": [ + "knp", + "knplabs", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "support": { + "issues": "https://github.com/KnpLabs/snappy/issues", + "source": "https://github.com/KnpLabs/snappy/tree/v1.5.0" + }, + "time": "2023-12-18T09:12:11+00:00" + }, { "name": "laravel/framework", "version": "v10.48.2", @@ -3186,6 +3484,74 @@ ], "time": "2023-11-08T05:53:05+00:00" }, + { + "name": "simplesoftwareio/simple-qrcode", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://github.com/SimpleSoftwareIO/simple-qrcode.git", + "reference": "916db7948ca6772d54bb617259c768c9cdc8d537" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SimpleSoftwareIO/simple-qrcode/zipball/916db7948ca6772d54bb617259c768c9cdc8d537", + "reference": "916db7948ca6772d54bb617259c768c9cdc8d537", + "shasum": "" + }, + "require": { + "bacon/bacon-qr-code": "^2.0", + "ext-gd": "*", + "php": ">=7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "~1", + "phpunit/phpunit": "~9" + }, + "suggest": { + "ext-imagick": "Allows the generation of PNG QrCodes.", + "illuminate/support": "Allows for use within Laravel." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "SimpleSoftwareIO\\QrCode\\QrCodeServiceProvider" + ], + "aliases": { + "QrCode": "SimpleSoftwareIO\\QrCode\\Facades\\QrCode" + } + } + }, + "autoload": { + "psr-4": { + "SimpleSoftwareIO\\QrCode\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Simple Software LLC", + "email": "support@simplesoftware.io" + } + ], + "description": "Simple QrCode is a QR code generator made for Laravel.", + "homepage": "https://www.simplesoftware.io/#/docs/simple-qrcode", + "keywords": [ + "Simple", + "generator", + "laravel", + "qrcode", + "wrapper" + ], + "support": { + "issues": "https://github.com/SimpleSoftwareIO/simple-qrcode/issues", + "source": "https://github.com/SimpleSoftwareIO/simple-qrcode/tree/4.2.0" + }, + "time": "2021-02-08T20:43:55+00:00" + }, { "name": "symfony/console", "version": "v6.4.4", diff --git a/config/app.php b/config/app.php index 431682e..aaf338a 100644 --- a/config/app.php +++ b/config/app.php @@ -168,6 +168,10 @@ return [ // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, + + + // ADD + SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class, ])->toArray(), /* @@ -183,6 +187,8 @@ return [ 'aliases' => Facade::defaultAliases()->merge([ // 'Example' => App\Facades\Example::class, + 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class, + 'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, ])->toArray(), ]; diff --git a/config/snappy.php b/config/snappy.php new file mode 100644 index 0000000..7fe62aa --- /dev/null +++ b/config/snappy.php @@ -0,0 +1,52 @@ + [ + 'enabled' => true, + 'binary' => env('WKHTML_PDF_BINARY', base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64')), + 'timeout' => false, + 'options' => [], + 'env' => [], + ], + + 'image' => [ + 'enabled' => true, + 'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'), + 'timeout' => false, + 'options' => [], + 'env' => [], + ], + +]; diff --git a/resources/views/pdf/qr-service/acquisition_announcement.blade.php b/resources/views/pdf/qr-service/acquisition_announcement.blade.php new file mode 100644 index 0000000..e63a952 --- /dev/null +++ b/resources/views/pdf/qr-service/acquisition_announcement.blade.php @@ -0,0 +1,79 @@ + + + + +
+ +
+
+ 駐車料金割引券発行QR +
+
+
+ +
+ {!! QrCode::size(200)->generate($url) !!} +
+
+ +
+
※バーコード読み取り後、お手持ちのスマートフォンに割引QR(URL)
+
  が表示されます。出庫時に精算機にかざして使用して下さい。
+
+ +
+ <{{ $shopName }}> +
+
+ + + \ No newline at end of file diff --git a/resources/views/pdf/test.blade.php b/resources/views/pdf/test.blade.php new file mode 100644 index 0000000..356f328 --- /dev/null +++ b/resources/views/pdf/test.blade.php @@ -0,0 +1,79 @@ + + + + +
+ +
+
+ 駐車料金割引券発行QR +
+
+
+ +
+ {!! QrCode::size(200)->generate(" http://yahoo.co.jp") !!} +
+
+ +
+
※バーコード読み取り後、お手持ちのスマートフォンに割引QR(URL)
+
  が表示されます。出庫時に精算機にかざして使用して下さい。
+
+ +
+ <ビックボーイ 田無店> +
+
+ + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index ac29d70..142d9bb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,8 @@ group(function () { + + Route::middleware('auth:sanctum')->group(function () { + // 店舗ルート + Route::middleware(RouteHelper::role([UserRole::SHOP]))->group(function () { + RouteHelper::get('/qr-service/acquisition/announcement', App\Http\Controllers\Web\Pdf\QRService\AcquisitionAnnouncementController::class); + }); + }); +}); + RouteHelper::get('/{any?}', App\Http\Controllers\Web\IndexController::class)->where('any', '.*');