$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'];
}
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', 'Данные успешно сохранены');
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]),
isset($data['matrix_type_id']) ? (int)$data['matrix_type_id'] : null
);
- $this->processFiles();
+ $this->processFiles($data);
// Проверяем, передаётся ли id букета
if (!empty($data)) {
/**
* Обрабатывает загрузку файлов (фото и видео).
*/
- public function processFiles(): void
+ public function processFiles(array $data): void
{
$fileTypes = [
'photo_bouquet' => [self::PHOTO_TYPE, self::PHOTO_BOUQUET],
}
}
}
+
+ 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);
+ }
+ }
+ }
+ }
}
/**
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 () {