fix bugs
parent
8dd012d79d
commit
77ed10609d
|
|
@ -9,6 +9,7 @@ use App\Services\Filters\FiltersService;
|
|||
use App\Services\Forms\FormsService;
|
||||
use App\Transformers\Objects\ObjectTransformer;
|
||||
use App\Transformers\Objects\ObjectTypeTransformer;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -54,6 +55,13 @@ class FormsController extends Controller {
|
|||
return FormsService::getService('feedback-form-support')->save($request->all());
|
||||
}
|
||||
|
||||
public function getQrCodeForm(Request $request, $target, $type = null, $id = null){
|
||||
if ($target === 'model') {
|
||||
$service = FormsService::getService($type);
|
||||
return $service->form($id, json_decode($request->get('extra_props'), true) ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveQrCodeForm(Request $request): ?JsonResponse {
|
||||
return FormsService::getService('QrCode')->save($request->all());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ namespace App\Models\QrCodes;
|
|||
|
||||
class ColorType
|
||||
{
|
||||
public const EPS = 'solid';
|
||||
public const SVG = 'gradient';
|
||||
public const SOLID = 'solid';
|
||||
public const GRADIENT = 'gradient';
|
||||
|
||||
public const TITLES = [
|
||||
self::EPS => 'Сплошной',
|
||||
self::SVG => 'Градиент'
|
||||
self::SOLID => 'Сплошной',
|
||||
self::GRADIENT => 'Градиент'
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\QrCodes;
|
||||
|
||||
class GradientType
|
||||
{
|
||||
public const VERTICAL = 'vertical';
|
||||
public const HORIZONTAL = 'horizontal';
|
||||
public const DIAGONAL = 'diagonal';
|
||||
public const INVERSE_DIAGONAL = 'inverse_diagonal';
|
||||
public const RADIAL = 'radial';
|
||||
|
||||
public const TITLES = [
|
||||
self::VERTICAL => 'Вертикальный',
|
||||
self::HORIZONTAL => 'Горизонтальный',
|
||||
self::DIAGONAL => 'Диагональ сверху вниз',
|
||||
self::INVERSE_DIAGONAL => 'Диагональ снизу вверх',
|
||||
self::RADIAL => 'Крулый'
|
||||
];
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Services\Forms\QrCode;
|
|||
use App\Models\Asset;
|
||||
use App\Models\Objects\FieldType;
|
||||
use App\Models\QrCodes\ColorType;
|
||||
use App\Models\QrCodes\GradientType;
|
||||
use App\Models\QrCodes\QrCode;
|
||||
use App\Models\QrCodes\QrCodeFormat;
|
||||
use App\Services\Forms\FormsService;
|
||||
|
|
@ -22,83 +23,72 @@ class QrCodeForms extends FormsService
|
|||
public function form(?string $id = null, array $data = []): array {
|
||||
$model = QrCode::byUuid($id)->first();
|
||||
$groups = [
|
||||
['name' => 'common', 'fields' => $this->commonGroupFields($model)]
|
||||
[
|
||||
'name' => 'common', 'fields' => $this->commonGroupFields($model),
|
||||
'dynamic' => [
|
||||
['field' => 'color_type', 'show' => ['red', 'green', 'blue'], 'hide' => ['start_red', 'start_green', 'start_blue', 'end_red', 'end_green', 'end_blue', 'gradient_type']],
|
||||
['field' => 'color_type', 'value' => ColorType::GRADIENT ,'show' => ['start_red', 'start_green', 'start_blue', 'end_red', 'end_green', 'end_blue', 'gradient_type'], 'hide' => ['red', 'green', 'blue']],
|
||||
['field' => 'color_type', 'value' => ColorType::GRADIENT ,'show' => ['start_red', 'start_green', 'start_blue', 'end_red', 'end_green', 'end_blue', 'gradient_type'], 'hide' => ['red', 'green', 'blue']],
|
||||
['field' => 'custom_eye_color', 'hide' => ['inner_red', 'inner_green', 'inner_blue', 'outside_red', 'outside_green', 'outside_blue']],
|
||||
['field' => 'custom_eye_color', 'value' => true, 'show' => ['inner_red', 'inner_green', 'inner_blue', 'outside_red', 'outside_green', 'outside_blue']],
|
||||
]
|
||||
],
|
||||
|
||||
];
|
||||
return ['title' => $this->formTitle($model), 'data' => $groups];
|
||||
}
|
||||
|
||||
public function commonGroupFields(?QrCode $model): array {
|
||||
$fields = [
|
||||
[
|
||||
'name' => 'format',
|
||||
'title' => 'Формат документа',
|
||||
'type' => FieldType::RELATION,
|
||||
'appearance' => 'radio',
|
||||
'options' => $this->getRelationItems(QrCodeFormat::TITLES),
|
||||
],
|
||||
[
|
||||
'name' => 'color_type',
|
||||
'title' => 'Тип заливки',
|
||||
'type' => FieldType::RELATION,
|
||||
'appearance' => 'radio',
|
||||
'options' => $this->getRelationItems(ColorType::TITLES),
|
||||
],
|
||||
[
|
||||
'name' => 'custom_eye_color',
|
||||
'title' => 'Цвет меток',
|
||||
'type' => FieldType::BOOLEAN,
|
||||
],
|
||||
[
|
||||
'name' => 'text',
|
||||
'title' => 'Текст',
|
||||
'type' => FieldType::TEXT,
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'format',
|
||||
'title' => 'Формат документа',
|
||||
'type' => FieldType::RELATION,
|
||||
'appearance' => 'radio',
|
||||
'options' => $this->getRelationItems(QrCodeFormat::TITLES),
|
||||
'value' => $this->getRelationValue(QrCodeFormat::TITLES, $model->format ?? QrCodeFormat::PNG)
|
||||
],
|
||||
[
|
||||
'name' => 'size',
|
||||
'title' => 'Размер',
|
||||
'type' => FieldType::INTEGER,
|
||||
],
|
||||
[
|
||||
'name' => 'red',
|
||||
'title' => 'Красный',
|
||||
'type' => FieldType::INTEGER,
|
||||
], [
|
||||
'name' => 'green',
|
||||
'title' => 'Зеленый',
|
||||
'type' => FieldType::INTEGER,
|
||||
], [
|
||||
'name' => 'blue',
|
||||
'title' => 'Синий',
|
||||
'type' => FieldType::INTEGER,
|
||||
],
|
||||
[
|
||||
'name' => 'bg_red',
|
||||
'title' => 'Фон красный',
|
||||
'type' => FieldType::INTEGER,
|
||||
],
|
||||
[
|
||||
'name' => 'bg_green',
|
||||
'title' => 'Фон зеленый',
|
||||
'type' => FieldType::INTEGER,
|
||||
], [
|
||||
'name' => 'bg_blue',
|
||||
'title' => 'Фон синий',
|
||||
'type' => FieldType::INTEGER,
|
||||
],
|
||||
[
|
||||
'name' => 'margin',
|
||||
'title' => 'Отступы',
|
||||
'type' => FieldType::INTEGER,
|
||||
'value' => $model->margin ?? null
|
||||
],
|
||||
// [
|
||||
// 'name' => 'margin',
|
||||
// 'title' => 'Отступы',
|
||||
// 'type' => FieldType::INTEGER,
|
||||
// ],
|
||||
[
|
||||
'name' => 'image',
|
||||
'title' => 'Изображение',
|
||||
'type' => FieldType::IMAGE,
|
||||
'value' => ($model->image ?? null) ? fractal($model->image, new AssetTransformer()) : null
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'color-type',
|
||||
'title' => 'Тип заливки',
|
||||
'type' => FieldType::RELATION,
|
||||
'appearance' => 'radio',
|
||||
'options' => $this->getRelationItems(ColorType::TITLES),
|
||||
'value' => $this->getRelationValue(ColorType::TITLES, $model->color ?? ColorType::SOLID)
|
||||
],
|
||||
[
|
||||
'name' => 'custom-eye-color',
|
||||
'title' => 'Цвет меток',
|
||||
'type' => FieldType::BOOLEAN,
|
||||
],
|
||||
[
|
||||
'name' => 'gradient-type',
|
||||
'title' => 'Тип градиента',
|
||||
'type' => FieldType::RELATION,
|
||||
'options' => $this->getRelationItems(GradientType::TITLES),
|
||||
]
|
||||
];
|
||||
return ['data' => $fields];
|
||||
}
|
||||
|
|
@ -106,35 +96,117 @@ class QrCodeForms extends FormsService
|
|||
public function store(array $data): JsonResponse {
|
||||
$model = QrCode::create();
|
||||
$this->updateData($model, $data);
|
||||
// $this->decode();
|
||||
return fractal($model, new QrCodeTransformer())->respond(201);
|
||||
}
|
||||
|
||||
public function updateData(QrCode $model, $data) {
|
||||
$model->update(collect($data)->only('text', 'format', 'size', 'color', 'bg_color', 'margin')->all());
|
||||
$data['document'] = $this->generate($data);
|
||||
$model->setImage($data['image'] ?? null);
|
||||
$data['document'] = $this->generate($model, $data);
|
||||
$model->setDocument($data['document'] ?? null);
|
||||
}
|
||||
|
||||
public function generate($data){
|
||||
function hexToRgb($hex, $return_string = false)
|
||||
{
|
||||
$hex = trim($hex, ' #');
|
||||
|
||||
$size = strlen($hex);
|
||||
if ($size == 3 || $size == 4) {
|
||||
$parts = str_split($hex, 1);
|
||||
$hex = '';
|
||||
foreach ($parts as $row) {
|
||||
$hex .= $row . $row;
|
||||
}
|
||||
}
|
||||
|
||||
$dec = hexdec($hex);
|
||||
$rgb = array();
|
||||
if ($size == 3 || $size == 6) {
|
||||
$rgb['red'] = 0xFF & ($dec >> 0x10);
|
||||
$rgb['green'] = 0xFF & ($dec >> 0x8);
|
||||
$rgb['blue'] = 0xFF & $dec;
|
||||
|
||||
if ($return_string) {
|
||||
return 'rgb(' . implode(',', $rgb) . ')';
|
||||
}
|
||||
} elseif ($size == 4 || $size == 8) {
|
||||
$rgb['red'] = 0xFF & ($dec >> 0x16);
|
||||
$rgb['green'] = 0xFF & ($dec >> 0x10);
|
||||
$rgb['blue'] = 0xFF & ($dec >> 0x8);
|
||||
$rgb['alpha'] = 0xFF & $dec;
|
||||
|
||||
if ($return_string) {
|
||||
$rgb['alpha'] = round(($rgb['alpha'] / (255 / 100)) / 100, 2);
|
||||
return 'rgba(' . implode(',', $rgb) . ')';
|
||||
} else {
|
||||
$rgb['alpha'] = 127 - ($rgb['alpha'] >> 1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $rgb;
|
||||
}
|
||||
|
||||
public function generate(QrCode $model, $data){
|
||||
$path = Storage::path((new QrCodeService)->makeFilePath($data['format']));
|
||||
$QrCode = QR::errorCorrection('H')->format($data['format'])->size($data['size'])->backgroundColor($data['bg_red'], $data['bg_green'], $data['bg_blue']);
|
||||
if ($data['image'] != null) $QrCode->merge(Storage::path($data['image']->path), .27, true);
|
||||
if ($data['color_type'] == 'gradient'){
|
||||
$QrCode->gradient($data['red'], $data['green'], $data['blue'], 255,255,255, 'vertical');
|
||||
|
||||
$QrCode = QR::errorCorrection('H')->format($data['format'] ?? 'png')->size($data['size'] ?? 200)->backgroundColor(
|
||||
$this->hexToRgb($data['background-color'])['red'],
|
||||
$this->hexToRgb($data['background-color'])['green'],
|
||||
$this->hexToRgb($data['background-color'])['blue']);
|
||||
if ($model->image != null) {
|
||||
$QrCode->merge(Storage::path(Asset::byUuid($data['image'])->first()->path), .27, true);
|
||||
}
|
||||
if ($data['color_type'] == 'gradient'){
|
||||
$QrCode->gradient($data['red'], $data['green'], $data['blue'], 255,255,255, 'vertical');
|
||||
if ($data['color-type'] == 'gradient'){
|
||||
$QrCode->gradient(
|
||||
$this->hexToRgb($data['gradient-start'])['red'],
|
||||
$this->hexToRgb($data['gradient-start'])['green'],
|
||||
$this->hexToRgb($data['gradient-start'])['blue'],
|
||||
$this->hexToRgb($data['gradient-end'])['red'],
|
||||
$this->hexToRgb($data['gradient-end'])['green'],
|
||||
$this->hexToRgb($data['gradient-end'])['blue'],
|
||||
$data['gradient-type']);
|
||||
}
|
||||
else $QrCode->color($data['red'],$data['green'],$data['blue']);
|
||||
if ($data['custom_eye_color']) {
|
||||
$QrCode->eyeColor(0, $data['red'], $data['green'], $data['blue'], $data['red'], $data['green'], $data['blue']);
|
||||
$QrCode->eyeColor(1, $data['red'], $data['green'], $data['blue'], $data['red'], $data['green'], $data['blue']);
|
||||
$QrCode->eyeColor(2, $data['red'], $data['green'], $data['blue'], $data['red'], $data['green'], $data['blue']);
|
||||
else $QrCode->color(
|
||||
$this->hexToRgb($data['foreground-color'])['red'],
|
||||
$this->hexToRgb($data['foreground-color'])['green'],
|
||||
$this->hexToRgb($data['foreground-color'])['blue']);
|
||||
if ($data['custom-eye-color']) {
|
||||
$QrCode->eyeColor(0,
|
||||
$this->hexToRgb($data['inner-eye-color'])['red'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['green'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['blue'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['red'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['green'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['blue']);
|
||||
$QrCode->eyeColor(1,
|
||||
$this->hexToRgb($data['inner-eye-color'])['red'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['green'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['blue'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['red'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['green'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['blue']);
|
||||
$QrCode->eyeColor(2,
|
||||
$this->hexToRgb($data['inner-eye-color'])['red'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['green'],
|
||||
$this->hexToRgb($data['inner-eye-color'])['blue'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['red'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['green'],
|
||||
$this->hexToRgb($data['outside-eye-color'])['blue']);
|
||||
}
|
||||
$QrCode->style('square');
|
||||
$QrCode->eye('square');
|
||||
$QrCode->style('round');
|
||||
$QrCode->eye('circle');
|
||||
// $data['text'] = $this->decode();
|
||||
$QrCode->generate($data['text'],$path);
|
||||
return (new QrCodeService)->makeAsset($path,null);
|
||||
return (new QrCodeService)->makeAsset($path,null)->id;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$QRCodeReader = new \Libern\QRCodeReader\QRCodeReader();
|
||||
$qrcode_text = $QRCodeReader->decode(Storage::path('documents\generated\8\8u4fwrybtgb06kf9.svg'));
|
||||
var_dump($qrcode_text);
|
||||
return $qrcode_text;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ class QrCodeTransformer extends TransformerAbstract{
|
|||
'size' => $model->size,
|
||||
'color' => $model->color,
|
||||
'bg_color' => $model->bg_color,
|
||||
'margin' => $model->phone
|
||||
'margin' => $model->margin
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,15 +32,16 @@
|
|||
"laravel/passport": "^10.0",
|
||||
"laravel/socialite": "^5.1",
|
||||
"laravel/tinker": "^2.0",
|
||||
"libern/qr-code-reader": "^1.0",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"movemoveapp/laravel-dadata": "^1.0",
|
||||
"phpoffice/phpword": "^1.0",
|
||||
"rtippin/messenger": "^1.19",
|
||||
"seyyedam7/laravel-html-parser": "^3.1",
|
||||
"simplesoftwareio/simple-qrcode": "~4",
|
||||
"spatie/laravel-fractal": "^5.8",
|
||||
"spatie/laravel-permission": "^3.17",
|
||||
"tomlerendu/laravel-convert-case-middleware": "^1.1",
|
||||
"simplesoftwareio/simple-qrcode": "~4"
|
||||
"tomlerendu/laravel-convert-case-middleware": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^6.2",
|
||||
|
|
|
|||
Loading…
Reference in New Issue