From aa6f8eae501665405d2351c11d2620e6a11a4790 Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 27 Mar 2025 09:45:30 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=20=D0=B8=20=D0=BE?= =?utf8?q?=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/BouquetController.php | 10 ++++++---- erp24/records/BouquetComposition.php | 13 ++++++++++--- erp24/services/FileService.php | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index a3c31f76..cab7a973 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,7 +126,9 @@ 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 4b9ba74f..7ff5510d 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -231,9 +231,16 @@ class BouquetComposition extends ActiveRecord public function getFiles(): array { return [ - 'photo' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::PHOTO_TYPE, 'entity' => self::PHOTO_BOUQUET])->all(), - 'video' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_PRESENTATION])->all(), - 'process' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_BUILD_PROCESS])->all(), + 'photo' => Files::find() + ->where(['entity_id' => $this->id, 'file_type' => self::PHOTO_TYPE, 'entity' => self::PHOTO_BOUQUET]) + ->orderBy(['created_at' => SORT_ASC]) + ->all(), + 'video' => Files::find() + ->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_PRESENTATION]) + ->all(), + 'process' => Files::find() + ->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_BUILD_PROCESS]) + ->all(), ]; } diff --git a/erp24/services/FileService.php b/erp24/services/FileService.php index 31bee4fd..ab3b8d77 100755 --- a/erp24/services/FileService.php +++ b/erp24/services/FileService.php @@ -128,6 +128,7 @@ class FileService mkdir($filePath, 0777, true); } $targetFile = $uploads . $target_dir. "/" . $file->baseName . '.' . $file->extension; + Yii::warning('Saved file: ' . json_encode($targetFile, JSON_UNESCAPED_UNICODE)); $file->saveAs($targetFile); $type = 'image'; @@ -142,7 +143,7 @@ class FileService } $fileRecord = new Files; - $fileRecord->created_at = date("Y-m-d H:i:s"); + $fileRecord->created_at = date("Y-m-d H:i:s", time() + 1); $fileRecord->entity_id = $entity_id; $fileRecord->entity = $entity; $fileRecord->file_type = $type; -- 2.39.5