From 09e746ba1a7169fa0984f2d224bf8097fd4cea4d Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 16 Oct 2025 11:19:54 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BA?= =?utf8?q?=D1=80=D0=BE=D0=BD=D0=B0=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=B5?= =?utf8?q?=D1=89=D0=B5=20=D0=B2=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5=D0=B4?= =?utf8?q?=D0=B8=20-=20status=20=3D=200=20=D0=BD=D0=B5=20=D0=B4=D0=BE?= =?utf8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20=D0=B7=D0=B0=D0=B4?= =?utf8?q?=D0=B0=D1=87=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 62 ++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 17 deletions(-) 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; + } + } -- 2.39.5