]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Загрузка фото и просмотр feature_fomichev_erp-322_add_foto_to_marketplace_order origin/feature_fomichev_erp-322_add_foto_to_marketplace_order
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 21 May 2025 14:34:23 +0000 (17:34 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 21 May 2025 14:34:23 +0000 (17:34 +0300)
erp24/media/controllers/MarketplaceController.php
erp24/media/views/marketplace/upload.php
erp24/views/marketplace-orders/view.php

index 998e587e255e67db2f0d2acc008749c6a9639c7b..56fc004a271743aff6f7197015d67f8e63f60676 100644 (file)
@@ -77,30 +77,30 @@ class MarketplaceController extends Controller
             throw new \yii\web\NotFoundHttpException("Заказ не найден.");
         }
         if (Yii::$app->request->isPost) {
-            $files = UploadedFile::getInstancesByName('files');
+            $file = UploadedFile::getInstanceByName('file');
+            //var_dump($file);
             Files::deleteAll(['entity_id' => $order->id, 'entity' => $entity]);
             $uploads = Yii::getAlias("@uploads");
             $target_dir = '/' . $order->id . '/' . date("Y") . "/" . date("m") . "/" . date("d") . "/";
 
-            foreach ($files as $file) {
-                $filePath = $uploads . $target_dir;
-                if (!is_dir($filePath)) {
-                    Yii::error('Создание папки' );
-                    mkdir($filePath, 0777, true);
-                }
-                $targetFile = $filePath . $file->baseName . '.' . $file->extension;
-                $file->saveAs($targetFile);
+            $filePath = $uploads . $target_dir;
+            if (!is_dir($filePath)) {
+                Yii::error('Создание папки');
+                mkdir($filePath, 0777, true);
+            }
+            $targetFile = $filePath . $file->baseName . '.' . $file->extension;
+            $file->saveAs($targetFile);
 
-                $fileRecord = new Files();
-                $fileRecord->created_at = date("Y-m-d H:i:s");
-                $fileRecord->entity_id = $order->id;
-                $fileRecord->entity = $entity;
-                $fileRecord->file_type = $file->type;
-                $fileRecord->url = '/uploads' . $target_dir . $file->baseName . '.' . $file->extension;
-                if (!$fileRecord->save()) {
-                    Yii::error('Ошибка сохранения файла: ' . json_encode($fileRecord->getErrors(), JSON_UNESCAPED_UNICODE));
-                }
+            $fileRecord = new Files();
+            $fileRecord->created_at = date("Y-m-d H:i:s");
+            $fileRecord->entity_id = $order->id;
+            $fileRecord->entity = $entity;
+            $fileRecord->file_type = $file->type;
+            $fileRecord->url = '/uploads' . $target_dir . $file->baseName . '.' . $file->extension;
+            if (!$fileRecord->save()) {
+                Yii::error('Ошибка сохранения файла: ' . json_encode($fileRecord->getErrors(), JSON_UNESCAPED_UNICODE));
             }
+
             $photos = $order->getFiles();
             if (count($photos) > 0 && isset($photos[0]->url)) {
                 $order->order_photo = $photos[0]->url;
index 82f6159eaa668c669cfff0fbd09ebce4b82c2aaa..6b8e8f5c905816c13b5fbf02419a09daee6fd94f 100644 (file)
@@ -6,7 +6,7 @@ use yii\helpers\Html;
 /** @var $this yii\web\View */
 /** @var string $guid */
 $order = \yii_app\records\MarketplaceOrders::find()->where(['guid' => $guid])->one();
-$this->title = $guid ? 'Загрузка фотографий заказа c ' . $order->marketplace_name . ' (Заказ: ' . $order->marketplace_order_id . ')' :
+$this->title = $guid ? 'Загрузка фото заказа c ' . $order->marketplace_name . ' (Заказ: ' . $order->marketplace_order_id . ')' :
     'Загрузка недоступна';
 ?>
 
@@ -30,8 +30,8 @@ $this->title = $guid ? 'Загрузка фотографий заказа c ' .
                     <input type="hidden" name="guid" value="<?= $guid ?>">
 
                     <div class="form-group">
-                        <label for="files">Выберите файлы</label>
-                        <input type="file" name="files[]" id="files" multiple>
+                        <label for="file">Выберите файл</label>
+                        <input type="file" name="file" id="file">
                     </div>
 
                     <button type="submit">Загрузить</button>
index 43b3599219d654455a01877e8f018e887eeea8a2..1f6b6719d09d4852528660d4ab61b8b03ca115e2 100644 (file)
@@ -5,10 +5,13 @@ use yii\widgets\DetailView;
 use yii_app\records\MarketplaceOrderItems;
 use yii_app\records\MarketplaceOrders;
 use yii_app\records\WriteOffsErp;
+use yii\web\View;
 
 /** @var yii\web\View $this */
 /** @var yii_app\records\MarketplaceOrders $model */
-
+$this->registerCssFile('@web/css/fancybox.css');
+$this->registerJsFile('@web/js/fancybox.umd.js', ['position' => View::POS_END]);
+$this->registerJsFile('/js/bouquet/bouquet.js', ['position' => View::POS_END]);
 $this->title = 'Заказ магазина ' . $model->store->name . ' от ' . $model->creation_date;
 $this->params['breadcrumbs'][] = ['label' => 'Marketplace Orders', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
@@ -89,7 +92,11 @@ $this->params['breadcrumbs'][] = $this->title;
                 'format' => 'raw',
                 'value'  => function ($model) {
 
-                    return Html::img($model->order_photo, ['width' => '100px']);
+                    return Html::a(
+                        Html::img($model->order_photo, ['width' => '100px']),
+                        $model->order_photo,
+                        ['data-fancybox' => 'gallery']
+                    );
                 }
             ],
             [