Commit 357649218a3560716538ab1893dd415b2064fba3
1 parent
0b2baee3
add action and view for server-files
Showing
5 changed files
with
102 additions
and
3 deletions
Show diff stats
backend/controllers/CheckPriceController.php
backend/controllers/ParserController.php
| @@ -36,7 +36,6 @@ class ParserController extends BaseController | @@ -36,7 +36,6 @@ class ParserController extends BaseController | ||
| 36 | 'class' => AccessControl::className(), | 36 | 'class' => AccessControl::className(), |
| 37 | 'rules' => [ | 37 | 'rules' => [ |
| 38 | [ | 38 | [ |
| 39 | - 'actions' => ['index', 'results', 'write', 'check_price'], | ||
| 40 | 'allow' => true, | 39 | 'allow' => true, |
| 41 | 'roles' => ['@'], | 40 | 'roles' => ['@'], |
| 42 | ], | 41 | ], |
| @@ -255,7 +254,6 @@ class ParserController extends BaseController | @@ -255,7 +254,6 @@ class ParserController extends BaseController | ||
| 255 | 254 | ||
| 256 | public function actionAutoUpload() | 255 | public function actionAutoUpload() |
| 257 | { | 256 | { |
| 258 | - //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); | ||
| 259 | $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); | 257 | $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); |
| 260 | 258 | ||
| 261 | $provider = new ActiveDataProvider([ | 259 | $provider = new ActiveDataProvider([ |
| @@ -268,4 +266,47 @@ class ParserController extends BaseController | @@ -268,4 +266,47 @@ class ParserController extends BaseController | ||
| 268 | [ | 266 | [ |
| 269 | 'dataProvider' => $provider]); | 267 | 'dataProvider' => $provider]); |
| 270 | } | 268 | } |
| 269 | + | ||
| 270 | + public function actionServerFiles () | ||
| 271 | + { | ||
| 272 | + $arr_id = []; | ||
| 273 | + // получим список файлов которые ожидают к загрузке | ||
| 274 | + foreach (glob(Yii::getAlias('@auto_upload') . '/*') as $server_file) { | ||
| 275 | + $file_id = basename($server_file,".csv"); | ||
| 276 | + $arr_id[] = (int) $file_id; | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + $query = ImporterFiles::find()->where(['in', 'id', $arr_id])->orderBy(['upload_time' => SORT_DESC]); | ||
| 280 | + | ||
| 281 | + $provider = new ActiveDataProvider([ | ||
| 282 | + 'query' => $query, | ||
| 283 | + 'pagination' => [ | ||
| 284 | + 'pageSize' => 10, | ||
| 285 | + ], | ||
| 286 | + ]); | ||
| 287 | + return $this->render('server-files', | ||
| 288 | + [ | ||
| 289 | + 'dataProvider' => $provider]); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + public function actionDelete ($id) | ||
| 293 | + { | ||
| 294 | + if(Yii::$app->request->isAjax){ | ||
| 295 | + CustomVarDamp::dumpAndDie(1); | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + $files_model = new ImporterFiles(); | ||
| 299 | + try { | ||
| 300 | + | ||
| 301 | + $files_model->delete($id); | ||
| 302 | + unlink(Yii::getAlias('@auto_upload') . '/' . $id . '.csv' ); | ||
| 303 | + | ||
| 304 | + } catch (ErrorException $e) { | ||
| 305 | + | ||
| 306 | + CustomVarDamp::dump($e->getMessage()); | ||
| 307 | + | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + $this->redirect('server-files'); | ||
| 311 | + } | ||
| 271 | } | 312 | } |
backend/models/ImporterFiles.php
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace backend\models; | 3 | namespace backend\models; |
| 4 | 4 | ||
| 5 | +use common\components\CustomVarDamp; | ||
| 5 | use Yii; | 6 | use Yii; |
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| @@ -37,8 +38,9 @@ class ImporterFiles extends \yii\db\ActiveRecord | @@ -37,8 +38,9 @@ class ImporterFiles extends \yii\db\ActiveRecord | ||
| 37 | 38 | ||
| 38 | public function getImporter () | 39 | public function getImporter () |
| 39 | { | 40 | { |
| 40 | - return $this->hasOne(Importer::className(), ['id' => 'importer_id'])->name; | 41 | + return $this->hasOne(Importer::className(), ['id' => 'importer_id'])->one()->name; |
| 41 | } | 42 | } |
| 43 | + | ||
| 42 | /** | 44 | /** |
| 43 | * @inheritdoc | 45 | * @inheritdoc |
| 44 | */ | 46 | */ |
backend/views/layouts/column.php
| @@ -283,6 +283,7 @@ $this->beginContent('@app/views/layouts/main.php'); | @@ -283,6 +283,7 @@ $this->beginContent('@app/views/layouts/main.php'); | ||
| 283 | 'options' => ['class' => 'sidebar-menu'], | 283 | 'options' => ['class' => 'sidebar-menu'], |
| 284 | 'items' => [ | 284 | 'items' => [ |
| 285 | ['label' => "Загрузка файлов", 'url' => ['#'], 'items' => [ | 285 | ['label' => "Загрузка файлов", 'url' => ['#'], 'items' => [ |
| 286 | + ['label' => 'Файлы на сервере', 'url' => ['parser/server-files']], | ||
| 286 | ['label' => 'Загрузить файл на сервер', 'url' => ['parser/index', 'mode' => 1]], | 287 | ['label' => 'Загрузить файл на сервер', 'url' => ['parser/index', 'mode' => 1]], |
| 287 | ['label' => 'Ручная загрузка', 'url' => ['parser/index']], | 288 | ['label' => 'Ручная загрузка', 'url' => ['parser/index']], |
| 288 | ['label' => 'Проверка прайс файлов', 'url' => ['check-price/index']], | 289 | ['label' => 'Проверка прайс файлов', 'url' => ['check-price/index']], |
| 1 | +<?php | ||
| 2 | +use yii\helpers\Html; | ||
| 3 | +use yii\grid\GridView; | ||
| 4 | +use yii\grid\SerialColumn; | ||
| 5 | +use yii\grid\ActionColumn; | ||
| 6 | +use yii\widgets\Pjax; | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +/* @var $this yii\web\View */ | ||
| 10 | +/* @var $searchModel backend\models\CatalogSearch */ | ||
| 11 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | ||
| 12 | + | ||
| 13 | +$this->title = 'Проверка прайсов'; | ||
| 14 | +$this->params['breadcrumbs'][] = $this->title; | ||
| 15 | +Pjax::begin(); | ||
| 16 | + | ||
| 17 | +?> | ||
| 18 | + <div class="catalog-index"> | ||
| 19 | + | ||
| 20 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 21 | + | ||
| 22 | + <?= GridView::widget( ['dataProvider' => $dataProvider, | ||
| 23 | + 'columns' => [['class' => SerialColumn::className()], | ||
| 24 | + [ | ||
| 25 | + 'label' =>'Поставщик', | ||
| 26 | + 'value' => function ($data) { | ||
| 27 | + return $data->importer; | ||
| 28 | + }, | ||
| 29 | + ], | ||
| 30 | + ['label' =>'Дата загрузки', | ||
| 31 | + 'attribute' => 'upload_time' ], | ||
| 32 | + | ||
| 33 | + ['class' => ActionColumn::className(), | ||
| 34 | + 'template'=>'{delete}', | ||
| 35 | + 'buttons' => [ | ||
| 36 | + 'delete' => function ($url, $model, $key) { | ||
| 37 | + return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, [ | ||
| 38 | + 'title' => Yii::t('yii', 'Удалить файл'), | ||
| 39 | + 'data-confirm' => 'Вы уверены что хотите удалить этот файл?', | ||
| 40 | + 'data-method' => 'post', | ||
| 41 | + 'data-pjax' => '1', | ||
| 42 | + ]); | ||
| 43 | + }, | ||
| 44 | + ], | ||
| 45 | + ] | ||
| 46 | + | ||
| 47 | + ]] );?> | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + </div> | ||
| 52 | +<?php | ||
| 53 | +Pjax::end(); | ||
| 54 | +?> | ||
| 0 | \ No newline at end of file | 55 | \ No newline at end of file |