]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Чистка cluster_id
authorvladfo <fvv2011@gmail.com>
Thu, 17 Oct 2024 14:50:14 +0000 (17:50 +0300)
committervladfo <fvv2011@gmail.com>
Thu, 17 Oct 2024 14:50:14 +0000 (17:50 +0300)
erp24/controllers/StoreController.php
erp24/records/CityStore.php
erp24/views/store/index.php

index 71cfe336a86c07f1eaca24e9b17edb5ea90ad831..b9e8d9009ae68969b2804702f7e6a6c09fbfb3e1 100755 (executable)
@@ -3,8 +3,11 @@
 namespace app\controllers;
 
 use yii\data\ActiveDataProvider;
+use yii\helpers\ArrayHelper;
 use yii\web\Controller;
 use yii_app\records\CityStore;
+use yii_app\records\Cluster;
+use yii_app\records\StoreDynamic;
 
 class StoreController extends Controller
 {
@@ -12,11 +15,41 @@ class StoreController extends Controller
 
     public function actionIndex()
     {
-        // Создаем DataProvider, чтобы получить магазины, у которых visible = 1
+
+        $clusters = Cluster::find()
+            ->select(['id', 'name'])
+            ->indexBy('id')
+            ->asArray()
+            ->all();
+
+
+        $clusterMap = ArrayHelper::map($clusters, 'id', function ($cluster) {
+            return $cluster['name'] . ' (' . $cluster['id'] . ')';
+        });
+
+
+        $storeData = StoreDynamic::find()
+            ->select(['value_int AS cluster_id', "string_agg(store_id::text, ',') AS stores"])
+            ->where(['active' => 1])
+            ->groupBy('value_int')
+            ->asArray()
+            ->all();
+
+
+        $storeClusterMap = [];
+        foreach ($storeData as $storeItem) {
+            $clusterId = $storeItem['cluster_id'];
+            $storeIds = explode(',', $storeItem['stores']);
+            foreach ($storeIds as $storeId) {
+                $storeClusterMap[$storeId] = $clusterId; // Магазин -> Кластер
+            }
+        }
+
+
         $dataProvider = new ActiveDataProvider([
             'query' => CityStore::find()
                 ->where(['visible' => 1])
-                ->with(['city', 'cluster', 'administrator']), // Загружаем связанные данные
+                ->with(['city', 'administrator']),
             'pagination' => [
                 'pageSize' => 20,
             ],
@@ -24,6 +57,8 @@ class StoreController extends Controller
 
         return $this->render('index', [
             'dataProvider' => $dataProvider,
+            'storeClusterMap' => $storeClusterMap,
+            'clusterMap' => $clusterMap,
         ]);
     }
     public function actionItemmatrix() { return $this->render('itemmatrix'); }
index b57b90869971a9994ee3568b4401eb585375496f..34bdb0997f45031b2857f60303ea856d4371f78b 100755 (executable)
@@ -330,7 +330,7 @@ class CityStore extends ActiveRecord
 
     public function getStoreGuid(): ActiveQuery
     {
-        $query = $this->hasOne(ExportImportTable::className(), ['entity_id' => 'id'])->onCondition(['export_id' => 1, 'entity' => 'city_store']);
+        $query = $this->hasOne(ExportImportTable::class, ['entity_id' => 'id'])->onCondition(['export_id' => 1, 'entity' => 'city_store']);
 
         return $query;
     }
@@ -341,7 +341,6 @@ class CityStore extends ActiveRecord
     }
 
 
-
     public function getAdministrator()
     {
         return $this->hasOne(Admin::class, ['id' => 'administrator_id']);
index cc2e939f2021bdcb3dbfee79a783bcbe31b3bd54..b10bbb07e50e9a99bc2945699ca0422cedf3c0a6 100644 (file)
@@ -5,6 +5,8 @@ use yii\grid\GridView;
 
 /** @var yii\web\View $this */
 /** @var yii\data\ActiveDataProvider $dataProvider */
+/* @var $storeClusterMap array */
+/* @var $clusterMap array */
 
 $this->title = 'Список магазинов';
 $this->params['breadcrumbs'][] = $this->title;
@@ -34,10 +36,11 @@ $this->params['breadcrumbs'][] = $this->title;
                 },
             ],
             [
-                'attribute' => 'cluster.name',
-                'label' => 'Куст',
-                'value' => function ($model) {
-                    return $model->cluster ? $model->cluster->name : '(Не указан)';
+                'attribute' => 'id',
+                'label' => 'Кластер',
+                'value' => function ($model) use ($storeClusterMap, $clusterMap) {
+                    $clusterId = $storeClusterMap[$model->id] ?? null; // Получаем cluster_id для магазина
+                    return $clusterId ? ($clusterMap[$clusterId] ?? 'Не назначен') : 'Не назначен';
                 },
             ],
             [