From: Alexander Smirnov Date: Wed, 27 Dec 2023 15:18:33 +0000 (+0300) Subject: add cron/balances-history during moving api1 to yii X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=97f097efa213b0716461c17f574658667c571c14;p=yii-erp24%2F.git add cron/balances-history during moving api1 to yii --- diff --git a/erp24/api1/actions/cron/BalanceHistoryAction.php b/erp24/api1/actions/cron/BalanceHistoryAction.php new file mode 100644 index 0000000..a46f1a3 --- /dev/null +++ b/erp24/api1/actions/cron/BalanceHistoryAction.php @@ -0,0 +1,40 @@ +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 diff --git a/erp24/api1/controllers/CronController.php b/erp24/api1/controllers/CronController.php index 0eb2d20..90d09de 100644 --- a/erp24/api1/controllers/CronController.php +++ b/erp24/api1/controllers/CronController.php @@ -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, ]; } }