From: fomichev Date: Fri, 28 Mar 2025 07:34:07 +0000 (+0300) Subject: Изменение порядка X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=55b39678005d5d8001a4df9dcd4b848d27500dc2;p=erp24_rep%2Fyii-erp24%2F.git Изменение порядка --- diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index cab7a973..a3c31f76 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -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]), diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 7ff5510d..85bf9248 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -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); + } + } + } + } } /** diff --git a/erp24/views/bouquet/_form.php b/erp24/views/bouquet/_form.php index 9531f347..f522bbf8 100644 --- a/erp24/views/bouquet/_form.php +++ b/erp24/views/bouquet/_form.php @@ -157,6 +157,7 @@ $form = ActiveForm::begin([ ], ], ])->label(false) ?> + 'photo-order']) ?>
diff --git a/erp24/web/js/bouquet/bouquet.js b/erp24/web/js/bouquet/bouquet.js index 4d74d0ac..d79e0b91 100644 --- a/erp24/web/js/bouquet/bouquet.js +++ b/erp24/web/js/bouquet/bouquet.js @@ -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 () {