From: marina Date: Tue, 28 Jan 2025 12:48:57 +0000 (+0300) Subject: ERP-282 Нужно сделать интерфейс настройки магазина X-Git-Tag: 1.7~35^2~4 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e8fa1fad8e818f3439f7ff7c44e06a77c7b47ab5;p=erp24_rep%2Fyii-erp24%2F.git ERP-282 Нужно сделать интерфейс настройки магазина --- diff --git a/erp24/controllers/CityStoreParamsController.php b/erp24/controllers/CityStoreParamsController.php index 70a9c23e..b06275ed 100644 --- a/erp24/controllers/CityStoreParamsController.php +++ b/erp24/controllers/CityStoreParamsController.php @@ -41,20 +41,6 @@ class CityStoreParamsController extends Controller ]; } - /** - * Просмотр конкретной записи - * @param int $id - * @return mixed - * @throws NotFoundHttpException - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - public function actionIndex() { $flash = 'info'; @@ -71,7 +57,13 @@ class CityStoreParamsController extends Controller $this->updateStoreDynamic($postData['store_id'], 'territorial_manager', $postData['territorial_manager']); } - $model = !empty($postData['id']) ? $this->findModel($postData['id']) : new CityStoreParams(); + + if (!empty($postData['id'])) { + $model = $this->findModel($postData['id']); + } else { + $model = new CityStoreParams(); + } + if ($model->load(Yii::$app->request->post())) { $model->matrix_type = is_array($model->matrix_type) ? implode(',', $model->matrix_type) : $model->matrix_type; @@ -86,6 +78,7 @@ class CityStoreParamsController extends Controller $value = 'Ошибка при сохранении: ' . implode('. ', array_map(fn($error) => is_array($error) ? implode(', ', $error) : $error, $model->getErrors())); } } + return $this->redirect(Yii::$app->request->referrer); } Yii::$app->session->setFlash($flash, $value); @@ -152,11 +145,36 @@ class CityStoreParamsController extends Controller $territorialManager = $data['territorial_manager'] ?? null; $bushChefFlorist = $data['bush_chef_florist'] ?? null; - $query = CityStore::find()->andWhere(['visible' => CityStore::IS_VISIBLE]) - ->andFilterWhere(['city' => $data['address_city']]) - ->andFilterWhere(['region' => $data['address_region']]) - ->andFilterWhere(['district' => $data['address_district']]) - ->andFilterWhere(['type' => $data['store_type']]); + $query = CityStore::find() + ->andWhere(['visible' => CityStore::IS_VISIBLE]); + + if (!empty($data['address_city'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_city' => $data['address_city']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['address_region'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_region' => $data['address_region']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['address_district'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_district' => $data['address_district']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['store_type'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['store_type' => $data['store_type']]) + ->select('store_id') + ->column()]); + } if (!empty($territorialManager)) { $territorialManagerStoreIds = StoreDynamic::find() @@ -176,11 +194,13 @@ class CityStoreParamsController extends Controller $query->andWhere(['in', 'id', $bushChefFloristStoreIds ?: [-1]]); } - $stores = $query->orderBy('id')->all(); + $stores = $query->all(); return [ 'success' => true, - 'data' => ArrayHelper::map($stores, 'id', fn($store) => $store->id . ' ' . $store->name), + 'data' => ArrayHelper::map($stores, 'id', function($store) { + return $store->id . ' ' . $store->name; + }), ]; } diff --git a/erp24/records/CityStoreParams.php b/erp24/records/CityStoreParams.php index 231c26d4..d43d8a0a 100644 --- a/erp24/records/CityStoreParams.php +++ b/erp24/records/CityStoreParams.php @@ -97,24 +97,6 @@ class CityStoreParams extends ActiveRecord ]; } - public function afterSave($insert, $changedAttributes) - { - $fields = [ - 'address_region' => 'region', - 'address_city' => 'city', - 'address_district' => 'district', - 'store_type' => 'type' - ]; - - foreach ($fields as $attribute => $field) { - $value = $insert ? $this->$attribute : ($changedAttributes[$attribute] ?? null); - - if (!empty($value)) { - CityStore::updateAll([$field => $value], ['id' => $this->store_id]); - } - } - } - public function getStore() { return $this->hasOne(CityStore::class, ['id' => 'store_id']); diff --git a/erp24/views/city-store-params/index.php b/erp24/views/city-store-params/index.php index 9aaff382..38a8d59e 100644 --- a/erp24/views/city-store-params/index.php +++ b/erp24/views/city-store-params/index.php @@ -22,7 +22,7 @@ $this->params['breadcrumbs'][] = $this->title; $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' => \yii\web\View::POS_END]); ?> -
+

title) ?>

@@ -144,7 +144,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
-
+
session->hasFlash($flash)): ?> session->getFlash($flash), [ 'class' => 'alert text-center flash-message mb-1 py-1 alert-' . Html::encode($flash), @@ -164,7 +164,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
-
+
Для редактирования необходимо выбрать магазин!
'; + $('.flash-column').html(flashMessage); + setTimeout(() => $('.flash-message').fadeOut(2000), 5000); + +});