From: Vladimir Fomichev Date: Thu, 16 Oct 2025 08:19:54 +0000 (+0300) Subject: Проверка на задачи крона если еще в очереди - status = 0 не добавляем задачу X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=09e746ba1a7169fa0984f2d224bf8097fd4cea4d;p=erp24_rep%2Fyii-erp24%2F.git Проверка на задачи крона если еще в очереди - status = 0 не добавляем задачу --- diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 8773c46c..c391ee2c 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -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; + } + }