--- /dev/null
+<?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
'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,
];
}
}