From 57726d715d6d2891bdec12e6eaaf438d278a9b23 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Thu, 8 Aug 2024 11:39:34 +0300 Subject: [PATCH] =?utf8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MotivationService.php | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 544348ea..4510c792 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -336,25 +336,37 @@ class MotivationService $monthStart = date("Y-m-d 00:00:00", strtotime($year . '-' . $month . '-1')); $monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1')); + // Ищем каталог-гуиды категории services + $productsClass = ProductsClass::find()->select(['category_id', 'tip']) + ->where(['tip' => 'services']) + ->indexBy('category_id') + ->asArray()->all(); + + // Ищем продуктовые гуиды по каталог-гуидам категории service + $products1c = Products1c::find()->select(['id', 'parent_id', 'name']) + ->where(['parent_id' => array_keys($productsClass), 'tip' => 'products']) + ->indexBy(['id']) + ->asArray()->all(); + + // Ищем каталог-гуиды категории services_delivery + $productsClassDelivery = ProductsClass::find()->select(['category_id', 'tip']) + ->where(['tip' => 'services_delivery']) + ->indexBy('category_id') + ->asArray()->all(); + + // Ищем продуктовые гуиды по каталог-гуидам категории service_delivery + $products1cDelivery = Products1c::find()->select(['id', 'parent_id', 'name']) + ->where(['parent_id' => array_keys($productsClassDelivery), 'tip' => 'products']) + ->indexBy(['id']) + ->asArray()->all(); + foreach (range(1, 5) as $ind) { $weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($monthStart))); - $weekEnd = date("Y-m-d 23:50:50", strtotime("+" . ($ind * 7 - 1) . ' days', strtotime($monthStart))); + $weekEnd = date("Y-m-d 23:59:59", strtotime("+" . ($ind * 7 - 1) . ' days', strtotime($monthStart))); if ($weekEnd > $monthEnd) { $weekEnd = $monthEnd; } - // Ищем каталог-гуиды категории services - $productsClass = ProductsClass::find()->select(['category_id', 'tip']) - ->where(['tip' => 'services']) - ->indexBy('category_id') - ->asArray()->all(); - - // Ищем продуктовые гуиды по каталог-гуидам категории service - $products1c = Products1c::find()->select(['id', 'parent_id', 'name']) - ->where(['parent_id' => array_keys($productsClass), 'tip' => 'products']) - ->indexBy(['id']) - ->asArray()->all(); - // Ищем продажи по продуктовым гуидам по каталог-гуидам категории service $sales = Sales::find()->alias('s') ->leftJoin('sales_products p', 'p.check_id = s.id') @@ -400,23 +412,11 @@ class MotivationService } } - // Ищем каталог-гуиды категории services_delivery - $productsClass = ProductsClass::find()->select(['category_id', 'tip']) - ->where(['tip' => 'services_delivery']) - ->indexBy('category_id') - ->asArray()->all(); - - // Ищем продуктовые гуиды по каталог-гуидам категории service_delivery - $products1c = Products1c::find()->select(['id', 'parent_id', 'name']) - ->where(['parent_id' => array_keys($productsClass), 'tip' => 'products']) - ->indexBy(['id']) - ->asArray()->all(); - // Ищем продажи по продуктовым гуидам по каталог-гуидам категории service_delivery $sales = Sales::find()->alias('s') ->leftJoin('sales_products p', 'p.check_id = s.id') ->where(['between', 's.date', $weekStart, $weekEnd]) - ->andWhere(['p.product_id' => array_keys($products1c)]) + ->andWhere(['p.product_id' => array_keys($products1cDelivery)]) ->andWhere(['s.store_id' => $store_id]) ->andWhere(['s.operation' => Sales::OPERATION_SALE]) ->asArray()->all(); -- 2.39.5