Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SyncCommand extends CConsoleCommand
- {
- private $ftp_url = '195.2.87.59';
- private $ftp_user = 'roz';
- private $ftp_pass = 'werdxcv1';
- /**
- * Обновленте цен (Через FTP):
- */
- public function actionPriceUpdate()
- {
- $ftp = new Ftp($this->ftp_url, $this->ftp_user, $this->ftp_pass);
- $file_local = ROOT_PATH . '/mod-tmp/sync/nomenclature.csv';
- $file_remote = '/Trade/InetMag/Nom_B.spr';
- $ftp->getFile($file_local, $file_remote);
- $tf = new TextFile();
- $data = $tf->nomRead($file_local);
- $table = ItemVariants::model()->tableName();
- $values = [];
- foreach ($data as $row) {
- if (!empty($row['Art_No'])) {
- $iv = ItemVariants::model()->findByAttributes(['articul' => $row['Art_No']]);
- if ($iv) {
- $old_price = (int)$row['Price'];
- $new_price = (int)$row['New_Price'];
- $price2 = (int)$row['Price2'];
- $values[] = "({$iv->id},{$old_price},{$new_price},{$price2})";
- }
- }
- }
- echo count($values) . " записей обновится \n";
- $values = implode(',', $values);
- $sql =
- "INSERT INTO
- {$table} (`id`,`old_price`, `new_price`, `price2`)
- VALUES
- {$values}
- ON DUPLICATE KEY UPDATE
- `old_price` = VALUES(`old_price`),
- `new_price` = VALUES(`new_price`),
- `price2` = VALUES(`price2`)";
- $connection=Yii::app()->db;
- $command=$connection->createCommand($sql);
- $rowCount = $command->execute();
- print_r($rowCount);
- echo "\n";
- }
- /**
- * Обновление статусов товаров (через FTP)
- */
- public function actionNomStatusUpdate()
- {
- $ftp = new Ftp($this->ftp_url, $this->ftp_user, $this->ftp_pass);
- $file_local = ROOT_PATH . '/mod-tmp/sync/nomenclature-stats.csv';
- $file_remote = $ftp->getFiles('/Trade/SklFab');
- if ($file_remote) {
- $ftp->getFile($file_local, $file_remote);
- $tf = new TextFile();
- $data = $tf->nomStatusRead($file_local);
- $table = ItemVariants::model()->tableName();
- $values = [];
- foreach ($data as $row) {
- if (!empty($row['articul'])) {
- $iv = ItemVariants::model()->findByAttributes(['articul' => $row['articul']]);
- if ($iv and $row['stock']) {
- $values[] = "({$iv->id},'{$row['stock']}')";
- }
- }
- }
- echo count($values) . " записей обновится \n";
- $values = implode(',', $values);
- $sql =
- "INSERT INTO
- {$table} (`id`,`status`)
- VALUES
- {$values}
- ON DUPLICATE KEY UPDATE
- `status` = VALUES(`status`)";
- $connection=Yii::app()->db;
- $command=$connection->createCommand($sql);
- $rowCount = $command->execute();
- print_r($rowCount);
- echo "\n";
- } else {
- echo "файл не найден \n";
- }
- }
- public function actionOrdersUpdate()
- {
- $ftp = new Ftp($this->ftp_url, $this->ftp_user, $this->ftp_pass);
- $file_local = ROOT_PATH . '/mod-tmp/sync/orders-stats.csv';
- $file_remote = '/Trade/Zakaz/Zakaz.ord';
- $ftp->getFile($file_local, $file_remote);
- $tf = new TextFile();
- $data = $tf->ordersRead($file_local);
- $table = ItemVariants::model()->tableName();
- $values = [];
- foreach ($data as $row) {
- if (!empty($row['Art_No'])) {
- $iv = ItemVariants::model()->findByAttributes(['articul' => $row['Art_No']]);
- if ($iv) {
- $old_price = (int)$row['Price'];
- $new_price = (int)$row['New_Price'];
- $price2 = (int)$row['Price2'];
- $values[] = "({$iv->id},{$old_price},{$new_price},{$price2})";
- }
- }
- }
- echo count($values) . " записей обновится \n";
- $values = implode(',', $values);
- $sql =
- "INSERT INTO
- {$table} (`id`,`old_price`, `new_price`, `price2`)
- VALUES
- {$values}
- ON DUPLICATE KEY UPDATE
- `old_price` = VALUES(`old_price`),
- `new_price` = VALUES(`new_price`),
- `price2` = VALUES(`price2`)";
- $connection=Yii::app()->db;
- $command=$connection->createCommand($sql);
- $rowCount = $command->execute();
- print_r($data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement