]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
add cron/balances-history during moving api1 to yii
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 27 Dec 2023 15:18:33 +0000 (18:18 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 27 Dec 2023 15:18:33 +0000 (18:18 +0300)
erp24/api1/actions/cron/BalanceHistoryAction.php [new file with mode: 0644]
erp24/api1/controllers/CronController.php

diff --git a/erp24/api1/actions/cron/BalanceHistoryAction.php b/erp24/api1/actions/cron/BalanceHistoryAction.php
new file mode 100644 (file)
index 0000000..a46f1a3
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace app\actions\cron;
+
+use Yii;
+use yii\base\Action;
+use yii\db\Expression;
+
+class BalanceHistoryAction extends Action
+{
+    public function run() {
+
+        include_once(dirname(__DIR__, 3) . "/startup.php");
+        include_once(dirname(__DIR__, 3) . "/inc/db.php");
+
+        // https://api.bazacvetov24.ru/cron/balances_history.php?token_cloud=iC04295J9HyD2H3GJF3btky
+        if($_GET["token_cloud"]!="iC04295J9HyD2H3GJF3btky") exit();
+
+        $data = Yii::$app->db->createCommand("SELECT * FROM balances")->queryAll();
+
+        $command = Yii::$app->db->createCommand()->batchInsert('balances_history',
+            ['date', 'store_id', 'product_id', 'quantity', 'reserv'],
+            [
+                ...array_map(fn($x) => [
+                    new Expression('NOW()'),
+                    $x["store_id"],
+                    $x["product_id"],
+                    $x["quantity"],
+                    $x["reserv"]
+                ], $data)
+            ]
+        );
+        $sql = $command->getRawSql();
+        $sql .= " ON DUPLICATE KEY UPDATE store_id=store_id";
+        $command->setRawSql($sql);
+        $command->execute();
+
+        return $this->controller->asJson(['response' => true]);
+    }
+}
\ No newline at end of file
index 0eb2d201c3d5587c5fb940dcc217d2fadf2fa65d..90d09de10e455cbcdce865907055ddeea1f30cbc 100644 (file)
@@ -15,6 +15,7 @@ class CronController extends BaseController
             'domru-cams' => \app\actions\cron\DomRuCamsAction::class,
             '1c-sellers' => \app\actions\cron\OneCSellersAction::class,
             'custom-1c-cron' => \app\actions\cron\Custom1cCronAction::class,
+            'balances-history' => \app\actions\cron\BalanceHistoryAction::class,
         ];
     }
 }