Преглед на файлове

立て看板のPDF出力対応

develop
sosuke.iwabuchi преди 1 година
родител
ревизия
7b60dae8e5
променени са 11 файла, в които са добавени 729 реда и са изтрити 2 реда
  1. +63
    -0
      app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php
  2. +9
    -0
      app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php
  3. +43
    -0
      app/Http/Controllers/Web/Pdf/TestController.php
  4. +15
    -0
      app/Http/Controllers/Web/Pdf/TestParam.php
  5. +4
    -1
      composer.json
  6. +367
    -1
      composer.lock
  7. +6
    -0
      config/app.php
  8. +52
    -0
      config/snappy.php
  9. +79
    -0
      resources/views/pdf/qr-service/acquisition_announcement.blade.php
  10. +79
    -0
      resources/views/pdf/test.blade.php
  11. +12
    -0
      routes/web.php

+ 63
- 0
app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementController.php Целия файл

@@ -0,0 +1,63 @@
<?php

namespace App\Http\Controllers\Web\Pdf\QRService;

use App\Http\Controllers\Web\WebController;
use App\Models\HtpmsCustomer\Mst\Shop;
use App\Models\HtpmsCustomer\QRService\AcquisitionTicketToken;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use PDF;

class AcquisitionAnnouncementController extends WebController
{

public function name(): string
{
return "QRサービス券取得用ページ取得";
}

public function description(): string
{
return "QRサービス券取得用ページを取得する";
}


public function __construct(protected AcquisitionAnnouncementParam $param)
{
parent::__construct();
}

protected function run(Request $request): Response
{

$shopId = $this->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;
}
}

+ 9
- 0
app/Http/Controllers/Web/Pdf/QRService/AcquisitionAnnouncementParam.php Целия файл

@@ -0,0 +1,9 @@
<?php

namespace App\Http\Controllers\Web\Pdf\QRService;

use App\Http\Controllers\Web\NoneParams;

class AcquisitionAnnouncementParam extends NoneParams
{
}

+ 43
- 0
app/Http/Controllers/Web/Pdf/TestController.php Целия файл

@@ -0,0 +1,43 @@
<?php

namespace App\Http\Controllers\Web\Pdf;

use App\Http\Controllers\Web\WebController;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use PDF;

class TestController extends WebController
{

public function name(): string
{
return "テスト用PDF出力";
}

public function description(): string
{
return "テスト用PDF出力をする";
}


public function __construct(protected TestParam $param)
{
parent::__construct();
}

protected function run(Request $request): Response
{
$pdf = PDF::loadView("pdf/test");

$filename = "test.pdf";

$ret = $pdf->setPaper("A4")
->setOption('encoding', 'utf-8')
->inline()
->header("Content-Disposition", sprintf('inline; filename=%s', $filename));


return $ret;
}
}

+ 15
- 0
app/Http/Controllers/Web/Pdf/TestParam.php Целия файл

@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers\Web\Pdf;

use App\Http\Controllers\Web\BaseParam;

/**
*/
class TestParam extends BaseParam
{
public function rules(): array
{
return [];
}
}

+ 4
- 1
composer.json Целия файл

@@ -6,10 +6,13 @@
"license": "MIT",
"require": {
"php": "^8.1",
"barryvdh/laravel-snappy": "^1.0",
"guzzlehttp/guzzle": "^7.2",
"h4cc/wkhtmltopdf-amd64": "^0.12.4",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8"
"laravel/tinker": "^2.8",
"simplesoftwareio/simple-qrcode": "^4.2"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",


+ 367
- 1
composer.lock Целия файл

@@ -4,8 +4,140 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6f4cd8c4286fcd65009ebc43750ac48f",
"content-hash": "c07666989a4e75c53ad106743daaca21",
"packages": [
{
"name": "bacon/bacon-qr-code",
"version": "2.0.8",
"source": {
"type": "git",
"url": "https://github.com/Bacon/BaconQrCode.git",
"reference": "8674e51bb65af933a5ffaf1c308a660387c35c22"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/8674e51bb65af933a5ffaf1c308a660387c35c22",
"reference": "8674e51bb65af933a5ffaf1c308a660387c35c22",
"shasum": ""
},
"require": {
"dasprid/enum": "^1.0.3",
"ext-iconv": "*",
"php": "^7.1 || ^8.0"
},
"require-dev": {
"phly/keep-a-changelog": "^2.1",
"phpunit/phpunit": "^7 | ^8 | ^9",
"spatie/phpunit-snapshot-assertions": "^4.2.9",
"squizlabs/php_codesniffer": "^3.4"
},
"suggest": {
"ext-imagick": "to generate QR code images"
},
"type": "library",
"autoload": {
"psr-4": {
"BaconQrCode\\": "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": "BaconQrCode is a QR code generator for PHP.",
"homepage": "https://github.com/Bacon/BaconQrCode",
"support": {
"issues": "https://github.com/Bacon/BaconQrCode/issues",
"source": "https://github.com/Bacon/BaconQrCode/tree/2.0.8"
},
"time": "2022-12-07T17:46:57+00:00"
},
{
"name": "barryvdh/laravel-snappy",
"version": "v1.0.3",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-snappy.git",
"reference": "716dcb6db24de4ce8e6ae5941cfab152af337ea0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/716dcb6db24de4ce8e6ae5941cfab152af337ea0",
"reference": "716dcb6db24de4ce8e6ae5941cfab152af337ea0",
"shasum": ""
},
"require": {
"illuminate/filesystem": "^9|^10|^11.0",
"illuminate/support": "^9|^10|^11.0",
"knplabs/knp-snappy": "^1.4.4",
"php": ">=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",


+ 6
- 0
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(),

];

+ 52
- 0
config/snappy.php Целия файл

@@ -0,0 +1,52 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Snappy PDF / Image Configuration
|--------------------------------------------------------------------------
|
| This option contains settings for PDF generation.
|
| Enabled:
|
| Whether to load PDF / Image generation.
|
| Binary:
|
| The file path of the wkhtmltopdf / wkhtmltoimage executable.
|
| Timeout:
|
| The amount of time to wait (in seconds) before PDF / Image generation is stopped.
| Setting this to false disables the timeout (unlimited processing time).
|
| Options:
|
| The wkhtmltopdf command options. These are passed directly to wkhtmltopdf.
| See https://wkhtmltopdf.org/usage/wkhtmltopdf.txt for all options.
|
| Env:
|
| The environment variables to set while running the wkhtmltopdf process.
|
*/

'pdf' => [
'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' => [],
],

];

+ 79
- 0
resources/views/pdf/qr-service/acquisition_announcement.blade.php Целия файл

@@ -0,0 +1,79 @@
<html>
<style>
main {
width: 100%;
}

.main-container {
width: 500px;
margin: 0 auto;
}

.title {
font-size: 30px;
background-color: #0070c0;
color: white;
height: 100px;
text-align: center;
letter-spacing: 5px;
}

.title div {
top: 30px;
position: relative;

}

.center {
margin: 0 auto;
}

.qr-container {
margin-top: 100px;
background-color: #0070c0;
padding: 10px;
width: 210;
}

.qr {
width: 200px;
}

.description {
margin-top: 50px;
}

.shop-name {
margin-top: 20px;
font-size: 20px;
font-weight: bold;
}
</style>

<body>
<div class="main-container">

<div class="title center">
<div>
駐車料金割引券発行QR
</div>
</div>
<div class="qr-container center">

<div class="center qr">
{!! QrCode::size(200)->generate($url) !!}
</div>
</div>

<div class="description">
<div>※バーコード読み取り後、お手持ちのスマートフォンに割引QR(URL)</div>
<div>&nbsp;&nbsp;が表示されます。出庫時に精算機にかざして使用して下さい。</div>
</div>

<div class="shop-name">
&lt;{{ $shopName }}&gt;
</div>
</div>
</body>

</html>

+ 79
- 0
resources/views/pdf/test.blade.php Целия файл

@@ -0,0 +1,79 @@
<html>
<style>
main {
width: 100%;
}

.main-container {
width: 500px;
margin: 0 auto;
}

.title {
font-size: 30px;
background-color: #0070c0;
color: white;
height: 100px;
text-align: center;
letter-spacing: 5px;
}

.title div {
top: 30px;
position: relative;

}

.center {
margin: 0 auto;
}

.qr-container {
margin-top: 100px;
background-color: #0070c0;
padding: 10px;
width: 210;
}

.qr {
width: 200px;
}

.description {
margin-top: 50px;
}

.shop-name {
margin-top: 20px;
font-size: 20px;
font-weight: bold;
}
</style>

<body>
<div class="main-container">

<div class="title center">
<div>
駐車料金割引券発行QR
</div>
</div>
<div class="qr-container center">

<div class="center qr">
{!! QrCode::size(200)->generate(" http://yahoo.co.jp") !!}
</div>
</div>

<div class="description">
<div>※バーコード読み取り後、お手持ちのスマートフォンに割引QR(URL)</div>
<div>&nbsp;&nbsp;が表示されます。出庫時に精算機にかざして使用して下さい。</div>
</div>

<div class="shop-name">
&lt;ビックボーイ 田無店&gt;
</div>
</div>
</body>

</html>

+ 12
- 0
routes/web.php Целия файл

@@ -1,6 +1,8 @@
<?php

use App\Codes\UserRole;
use App\Util\RouteHelper;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
@@ -13,4 +15,14 @@ use App\Util\RouteHelper;
|
*/

Route::prefix("pdf")->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', '.*');

Loading…
Отказ
Запис