]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Изменение порядка feature_fomichev_erp-387_main_image_matrix_bouquet_correction
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 28 Mar 2025 07:34:07 +0000 (10:34 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 28 Mar 2025 07:34:07 +0000 (10:34 +0300)
erp24/controllers/BouquetController.php
erp24/records/BouquetComposition.php
erp24/views/bouquet/_form.php
erp24/web/js/bouquet/bouquet.js

index cab7a9733b0c6c3befd732b5c8c7dcdca4fcf50d..a3c31f76054ce516e1d225591c72452f07f258ff 100644 (file)
@@ -85,12 +85,12 @@ class BouquetController extends Controller
 
         $data = $request->post();
         $isNew = $model->isNewRecord;
-        Yii::warning('Request: ' . json_encode($data, JSON_UNESCAPED_UNICODE));
+
         if ($isNew) {
             $model->guid = DataHelper::createGuidMy('07');
             $model->status = WriteOffsErp::STATUS_CREATED;
         }
-        Yii::warning('Model: ' . json_encode($model, JSON_UNESCAPED_UNICODE));
+
         if (isset($data['matrix_type_id'])) {
             $model->matrix_type_id = (int) $data['matrix_type_id'];
         }
@@ -100,7 +100,7 @@ class BouquetController extends Controller
             if (!$model->load($data) || !$model->validate() || !$model->save()) {
                 throw new Exception('Ошибка при сохранении букета');
             }
-            Yii::warning('Model 2: ' . json_encode($model, JSON_UNESCAPED_UNICODE));
+
             $model->processRelations($data);
             $transaction->commit();
             Yii::$app->session->setFlash('success', 'Данные успешно сохранены');
@@ -126,9 +126,7 @@ class BouquetController extends Controller
     private function renderView(BouquetComposition $model)
     {
         $files = $model->getFiles();
-       // usort($files['photo'], fn($a, $b) => strtotime($a->created_at) <=> strtotime($b->created_at));
-        Yii::warning('Order files' . json_encode($files['photo'], JSON_UNESCAPED_UNICODE));
-        Yii::warning('Order files url' . json_encode(array_map(fn($file) => Url::to([$file->url], true), $files['photo']), JSON_UNESCAPED_UNICODE));
+
         return $this->render('view', [
             'model' => $model,
             'onlineStoresList' => BouquetForecast::getStoresList($model->id, BouquetForecast::ONLINE_STORES, CityStore::class, ['visible' => CityStore::IS_VISIBLE]),
index 7ff5510dee287c5b33f4a50ce52c28cfae62ee8f..85bf924851992844fd2fe9ffc3942fa7b671fa17 100644 (file)
@@ -189,7 +189,7 @@ class BouquetComposition extends ActiveRecord
             isset($data['matrix_type_id']) ? (int)$data['matrix_type_id'] : null
         );
 
-        $this->processFiles();
+        $this->processFiles($data);
 
         // Проверяем, передаётся ли id букета
         if (!empty($data)) {
@@ -204,7 +204,7 @@ class BouquetComposition extends ActiveRecord
     /**
      * Обрабатывает загрузку файлов (фото и видео).
      */
-    public function processFiles(): void
+    public function processFiles(array $data): void
     {
         $fileTypes = [
             'photo_bouquet' => [self::PHOTO_TYPE, self::PHOTO_BOUQUET],
@@ -221,6 +221,20 @@ class BouquetComposition extends ActiveRecord
                 }
             }
         }
+
+        if (!empty($data['photo_order'])) {
+            $order = json_decode($data['photo_order'], true);
+            if (is_array($order)) {
+                $time = time();
+                foreach ($order as $index => $fileId) {
+                    $fileRecord = Files::findOne($fileId);
+                    if ($fileRecord) {
+                        $fileRecord->created_at = date("Y-m-d H:i:s", $time + $index);
+                        $fileRecord->save(false);
+                    }
+                }
+            }
+        }
     }
 
     /**
index 9531f34708f9f0b8d3a77385461cb59f25e54270..f522bbf86b6d6947a88b255c8d93e6d286aaddb6 100644 (file)
@@ -157,6 +157,7 @@ $form = ActiveForm::begin([
                         ],
                     ],
                 ])->label(false) ?>
+                <?= Html::hiddenInput('photo_order', '', ['id' => 'photo-order']) ?>
             </div>
             <div class="row">
                 <div class="col-md-6 w-100 w-md-75 w-lg-50">
index 4d74d0ac6d16584e4dad978505a0052105cec48d..d79e0b91698c598f72c2fcbcf7798cf84f6f22c4 100644 (file)
@@ -6,6 +6,14 @@ document.addEventListener('DOMContentLoaded', function () {
             this.play();
         });
     });
+
+    $('#bouquet-file-upload').on('filesorted', function(event, params) {
+        var order = params.stack.map(function(file) {
+            return file.key;
+        });
+        //console.log(JSON.stringify(order));
+        $('#photo-order').val(JSON.stringify(order));
+    });
 });
 
 $(document).ready(function () {