From 1fcff93ff9949a46c39f4743df4fadbbdd96937f Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 1 Jul 2025 09:53:42 +0300 Subject: [PATCH] =?utf8?q?ERP-433=20=D0=9E=D1=82=D1=87=D0=B5=D1=82=20?= =?utf8?q?=D0=BF=D0=BE=20=D0=BE=D1=81=D1=82=D0=B0=D1=82=D0=BA=D0=B0=D0=BC?= =?utf8?q?=20=D0=B1=D1=83=D0=BA=D0=B5=D1=82=D0=BE=D0=B2=20=D0=B4=D0=BB?= =?utf8?q?=D1=8F=20=D0=9C=D0=9F=20=D0=B8=20=D0=BF=D1=80=D0=B8=D1=87=D0=B8?= =?utf8?q?=D0=BD=D0=B0=D0=BC,=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BB=D0=BE?= =?utf8?q?=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE?= =?utf8?q?=D1=85=D0=BE=D0=B4=D0=B8=D1=82.=20=D0=92=D0=BE=D0=B7=D0=BC=D0=BE?= =?utf8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=80=D1=83=D1=87=D0=BD?= =?utf8?q?=D0=BE=D0=B9=20=D0=B2=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= =?utf8?q?=20=D0=B8=D0=B7=20ERP=20=D0=B2=20Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/actions/marketplace/ReportAction.php | 57 +++++++++++++++++++ erp24/config/env.php | 6 +- erp24/controllers/MarketplaceController.php | 1 + erp24/services/MarketplaceService.php | 61 ++++++++++----------- erp24/views/marketplace/report.php | 26 +++++++++ 5 files changed, 117 insertions(+), 34 deletions(-) create mode 100644 erp24/actions/marketplace/ReportAction.php create mode 100644 erp24/views/marketplace/report.php diff --git a/erp24/actions/marketplace/ReportAction.php b/erp24/actions/marketplace/ReportAction.php new file mode 100644 index 00000000..de35039c --- /dev/null +++ b/erp24/actions/marketplace/ReportAction.php @@ -0,0 +1,57 @@ +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 diff --git a/erp24/config/env.php b/erp24/config/env.php index cd418591..d54d378f 100644 --- a/erp24/config/env.php +++ b/erp24/config/env.php @@ -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"); diff --git a/erp24/controllers/MarketplaceController.php b/erp24/controllers/MarketplaceController.php index 671474e1..85549b82 100644 --- a/erp24/controllers/MarketplaceController.php +++ b/erp24/controllers/MarketplaceController.php @@ -12,6 +12,7 @@ class MarketplaceController extends Controller { return [ 'priority' => \yii_app\actions\marketplace\PriorityAction::class, + 'report' => \yii_app\actions\marketplace\ReportAction::class, ]; } /** diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index 65324a76..a7d5b795 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -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 index 00000000..2d2b6adf --- /dev/null +++ b/erp24/views/marketplace/report.php @@ -0,0 +1,26 @@ +title = 'Список продуктов, которые не попадают в фиды'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'name', + 'articule', + 'id', + 'checkResult' + ], + ]); ?> +
\ No newline at end of file -- 2.39.5