]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Проверка на задачи крона если еще в очереди - status = 0 не добавляем задачу origin/feature_fomichev_erp-483_add_microseconds_to_exchange_id origin/feature_fomichev_erp-485_check_api_cron_task_status_before_add
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 16 Oct 2025 08:19:54 +0000 (11:19 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 16 Oct 2025 08:19:54 +0000 (11:19 +0300)
erp24/commands/CronController.php

index 8773c46cb47023e9dfeb4b819881eeba2ab5df0b..c391ee2ce16bf3cc64d704e106bf9db9c9454175 100644 (file)
@@ -23,6 +23,7 @@ use yii_app\helpers\HtmlHelper;
 use yii_app\records\Admin;
 use yii_app\records\AdminGroup;
 use yii_app\records\AdminPayroll;
+use yii_app\records\ApiCron;
 use yii_app\records\Autoplannogramma;
 use yii_app\records\BonusLevels;
 use yii_app\records\CityStore;
@@ -91,10 +92,14 @@ class CronController extends Controller
     public function actionOneC()
     {
         $req_id = time();
-        $json_post = '{"request_id": "' . $req_id . '" ,"incomings":{"start_time":"' . date("Y-m-d", time() - 86400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},"checks":{"start_time":"' . date("Y-m-d", time() - 24400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},
-"write_offs":{"start_time":"' . date("Y-m-d", time() - 86400 * 7) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
+        $jsonString = '", "incomings":{"start_time":"' . date("Y-m-d", time() - 86400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},';
+        $jsonString .= ' "checks":{"start_time":"' . date("Y-m-d", time() - 24400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},';
+        $jsonString .= ' "write_offs":{"start_time":"' . date("Y-m-d", time() - 86400 * 7) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
 
-        $this->setApiCron($req_id, $json_post);
+        if(!CronController::checkApiCronTask($jsonString)) {
+            $json_post = '{"request_id": "' . $req_id . $jsonString;
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -168,9 +173,12 @@ class CronController extends Controller
     public function actionOneCSellers()
     {
         $req_id = time();
-        $json_post = '{"request_id": "' . $req_id . '","nomenclature":true,"sellers":true, "balances":true, "payment_types":true}';
+        $jsonString = '", "nomenclature":true, "sellers":true, "balances":true, "payment_types":true}';
 
-        $this->setApiCron($req_id, $json_post);
+        if(!CronController::checkApiCronTask($jsonString)) {
+            $json_post = '{"request_id": "' . $req_id . $jsonString;
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -179,9 +187,12 @@ class CronController extends Controller
     public function actionOneCPrice()
     {
         $req_id = time();
-        $json_post = '{"request_id": "' . $req_id . '","nomenclature":true,"sellers":true, "prices":{"type_price":"Розничная Маг на Московск"}, "balances":true,  "payment_types":true}';
+        $jsonString = '", "nomenclature":true, "sellers":true, "prices":{"type_price":"Розничная Маг на Московск"}, "balances":true, "payment_types":true}';
 
-        $this->setApiCron($req_id, $json_post);
+        if (!CronController::checkApiCronTask($jsonString)) {
+            $json_post = '{"request_id": "' . $req_id . $jsonString;
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -190,9 +201,12 @@ class CronController extends Controller
     public function actionOneCBalances()
     {
         $req_id = time();
-        $json_post = '{"request_id": "' . $req_id . '","balances":true}';
+        $jsonString = '", "balances":true}';
 
-        $this->setApiCron($req_id, $json_post);
+        if (!CronController::checkApiCronTask($jsonString)) {
+            $json_post = '{"request_id": "' . $req_id . $jsonString;
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -214,11 +228,13 @@ class CronController extends Controller
     public function actionMarketplaceOrdersOneCCron()
     {
         $req_id = time();
+        $jsonString = '"marketplace_orders":{"start_time":"' . date("Y-m-d", time() - 86400 * 2) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}';
 
-        //заказы за 2 дня назад прогружаем
-        $json_post = '{"request_id": "' . $req_id . '", "marketplace_orders":{"start_time":"' . date("Y-m-d", time() - 86400 * 2) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
-
-        $this->setApiCron($req_id, $json_post);
+        if (!CronController::checkApiCronTask($jsonString)) {
+            //заказы за 2 дня назад прогружаем
+            $json_post = '{"request_id": "' . $req_id . '", ' . $jsonString . '}';
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -240,11 +256,13 @@ class CronController extends Controller
     public function actionOneCCronAnalysts()
     {
         $req_id = time();
+        $jsonString = '", "analysts_business_operations": true}';
 
-        //Аналитика хозяйственных операций
-        $json_post = '{"request_id": "' . $req_id . '", "analysts_business_operations": true}';
-
-        $this->setApiCron($req_id, $json_post);
+        if (!CronController::checkApiCronTask($jsonString)) {
+            //Аналитика хозяйственных операций
+            $json_post = '{"request_id": "' . $req_id . $jsonString;
+            $this->setApiCron($req_id, $json_post);
+        }
 
         return 'ok';
     }
@@ -2057,4 +2075,14 @@ class CronController extends Controller
         return $today < $target;
     }
 
+    public static function checkApiCronTask(string $jsonString) {
+        $apiCron = ApiCron::find()
+            ->where(['status' => 0])
+            ->andWhere(['ilike', 'json_post', $jsonString])
+            ->orderBy(['date' => SORT_ASC])
+            ->exists();
+
+        return $apiCron;
+    }
+
 }