]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-433 Отчет по остаткам букетов для МП и причинам, если логика не проходит. Возможн...
authormarina <m.zozirova@gmail.com>
Tue, 1 Jul 2025 06:53:42 +0000 (09:53 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 1 Jul 2025 06:53:42 +0000 (09:53 +0300)
erp24/actions/marketplace/ReportAction.php [new file with mode: 0644]
erp24/config/env.php
erp24/controllers/MarketplaceController.php
erp24/services/MarketplaceService.php
erp24/views/marketplace/report.php [new file with mode: 0644]

diff --git a/erp24/actions/marketplace/ReportAction.php b/erp24/actions/marketplace/ReportAction.php
new file mode 100644 (file)
index 0000000..de35039
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+namespace yii_app\actions\marketplace;
+
+use Yii;
+use yii\base\Action;
+use yii\data\ActiveDataProvider;
+use yii\data\ArrayDataProvider;
+use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
+use yii_app\records\ProductsClass;
+use yii_app\services\MarketplaceService;
+
+class ReportAction extends Action
+{
+    public function run()
+    {
+        $subQuery = Products1c::find()
+            ->alias('p1n')
+            ->leftJoin('products_class pc', 'p1n.id = pc.category_id')
+            ->where(['or',
+                ['pc.tip' => ProductsClass::HINT_MARKETPLACE],
+                ['pc.tip' => ProductsClass::HINT_MARKETPLACE_ADDITIONAL]
+            ])
+            ->select('p1n.id');
+
+        $productsRaw = Products1c::find()
+            ->where(['in', 'parent_id', $subQuery])
+            ->limit(10)
+            ->all();
+
+        $marketplaceService = new MarketplaceService();
+
+        $products = [];
+
+        foreach ($productsRaw as $product) {
+            $check = $marketplaceService->checkProducts($product);
+            $products[] = [
+                'id' => $product->id,
+                'name' => $product->name,
+                'articule' => $product->articule,
+                'checkResult' => $check !== false ? 'true' : 'false',
+            ];
+        }
+
+
+        $dataProvider = new ArrayDataProvider([
+            'allModels' => $products,
+            'pagination' => ['pageSize' => 20],
+        ]);
+
+
+        return $this->controller->render('report', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+}
\ No newline at end of file
index cd418591c37329dbfe4b962fd34d6dec2ecdc2e0..d54d378f159bbf44651bdad1f5aca4896484dd1c 100644 (file)
@@ -6,7 +6,11 @@ try {
     $dotenv->required(['APP_ENV']);
 
     foreach ($_ENV as $key => $value) {
-        putenv("$key=$value");
+        if (is_scalar($value)) {
+            putenv("$key=$value");
+        } else {
+            Yii::warning("Переменная окружения $key имеет нескалярное значение и не может быть установлена через putenv");
+        }
     }
 } catch (\Dotenv\Exception\InvalidPathException $e) {
     putenv("APP_ENV=development");
index 671474e1116d0a0741447105aaff4986c9a189a4..85549b82c61812adf923ebfb720ccdc9b2ec76a6 100644 (file)
@@ -12,6 +12,7 @@ class MarketplaceController extends Controller
     {
         return [
             'priority' => \yii_app\actions\marketplace\PriorityAction::class,
+            'report' => \yii_app\actions\marketplace\ReportAction::class,
         ];
     }
     /**
index 65324a768a55abcab21ece1dfbc4a42c56c8283c..a7d5b7953506098916b544cff8c2f2b9eb2a427a 100644 (file)
@@ -398,10 +398,8 @@ class MarketplaceService
     }
 
 
-    public static function getProductsInfoForFeed(int $warehouseGuid, array $storeData)
+    public static function getProductsInfoForFeed(int $warehouseGuid, array $storeData): array
     {
-
-
         if (!is_array($storeData)) {
             Yii::error('Invalid data format for storeData; expected array.', __METHOD__);
             return [];
@@ -414,16 +412,13 @@ class MarketplaceService
         }
         $storeGuid = $store->guid;
 
-
         if (!isset($storeData[$storeGuid])) {
             Yii::warning("Не найдено данных store GUID {$storeGuid}", __METHOD__);
             return [];
         }
 
-
         $productQuantities = $storeData[$storeGuid];
 
-
         $products = Products1c::find()
             ->where(['id' => array_keys($productQuantities)])
             ->andWhere(['!=', 'components', ''])
@@ -432,35 +427,13 @@ class MarketplaceService
         $result = [];
 
         foreach ($products as $product) {
-            $properties = MarketplaceService::getProductPropertiesByGuid($product->id);
-            if (!$properties) {
-                $message = "Товар с GUID {$product->id} не имеет свойств в MatrixErpProperty и был исключен из фида.";
-                Yii::error($message, __METHOD__);
-
-                InfoLogService::setInfoLog(
-                    __FILE__,
-                    __LINE__,
-                    $message,
-                    'Missing properties error'
-                );
+            $check = self::checkProducts($product);
+            if ($check === false) {
                 continue;
             }
 
-            $price = MarketplaceService::getProductPrice($product->id);
-
-              if ($price == 0) {
-                $message = "У товара {$product->id} отсутствует цена и он будет исключен из фида.";
-                Yii::error($message, __METHOD__);
-
-
-                InfoLogService::setInfoLog(
-                    __FILE__,
-                    __LINE__,
-                    $message,
-                    'Zero price error'
-                );
-                continue;
-            }
+            $properties = $check['properties'];
+            $price = $check['price'];
 
             $components = json_decode($product->components, true);
             $composition = [];
@@ -476,7 +449,6 @@ class MarketplaceService
                 }
             }
 
-
             $availableQty = $productQuantities[$product->id] ?? 0;
 
             $result[] = [
@@ -502,6 +474,29 @@ class MarketplaceService
         return $result;
     }
 
+    public function checkProducts($product): array|false {
+        $properties = MarketplaceService::getProductPropertiesByGuid($product->id);
+        if (!$properties) {
+            $message = "Товар с GUID {$product->id} не имеет свойств в MatrixErpProperty и был исключен из фида.";
+            Yii::error($message, __METHOD__);
+            InfoLogService::setInfoLog(__FILE__, __LINE__, $message, 'Missing properties error');
+            return false;
+        }
+
+        $price = MarketplaceService::getProductPrice($product->id);
+        if ($price == 0) {
+            $message = "У товара {$product->id} отсутствует цена и он будет исключен из фида.";
+            Yii::error($message, __METHOD__);
+            InfoLogService::setInfoLog(__FILE__, __LINE__, $message, 'Zero price error');
+            return false;
+        }
+
+        return [
+            'properties' => $properties,
+            'price' => $price,
+        ];
+    }
+
     /**
      * Статический метод для создания XML-фида на основе информации о продуктах.
      *
diff --git a/erp24/views/marketplace/report.php b/erp24/views/marketplace/report.php
new file mode 100644 (file)
index 0000000..2d2b6ad
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+use yii\grid\GridView;
+use yii\helpers\Html;
+
+/* @var $this yii\web\View */
+/* @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Список продуктов, которые не попадают в фиды';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="marketplace-report p-5">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+            'name',
+            'articule',
+            'id',
+            'checkResult'
+        ],
+    ]); ?>
+</div>
\ No newline at end of file