Commit 4b12e92e9e693eaf502cdd4a07a330e24c270290
1 parent
5c9840b3
work with margins and brands pages
Showing
23 changed files
with
189 additions
and
153 deletions
Show diff stats
.gitignore
.htaccess
| @@ -12,7 +12,7 @@ AddDefaultCharset utf-8 | @@ -12,7 +12,7 @@ AddDefaultCharset utf-8 | ||
| 12 | 12 | ||
| 13 | RewriteBase / | 13 | RewriteBase / |
| 14 | # deal with admin first | 14 | # deal with admin first |
| 15 | - RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT] | 15 | + RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT] |
| 16 | 16 | ||
| 17 | RewriteCond %{REQUEST_URI} ^/(admin) | 17 | RewriteCond %{REQUEST_URI} ^/(admin) |
| 18 | 18 |
backend/.gitignore
backend/controllers/ParserController.php
| @@ -7,6 +7,7 @@ use common\components\exceptions\PriceParsingException; | @@ -7,6 +7,7 @@ use common\components\exceptions\PriceParsingException; | ||
| 7 | use common\components\exceptions\RgParsingException; | 7 | use common\components\exceptions\RgParsingException; |
| 8 | use common\components\ModelArrayValidator; | 8 | use common\components\ModelArrayValidator; |
| 9 | use common\components\parsers\MailParser; | 9 | use common\components\parsers\MailParser; |
| 10 | +use common\components\parsers\Parser; | ||
| 10 | use Yii; | 11 | use Yii; |
| 11 | use yii\data\ActiveDataProvider; | 12 | use yii\data\ActiveDataProvider; |
| 12 | use yii\filters\AccessControl; | 13 | use yii\filters\AccessControl; |
| @@ -186,11 +187,14 @@ class ParserController extends BaseController | @@ -186,11 +187,14 @@ class ParserController extends BaseController | ||
| 186 | public function actionServerFiles () | 187 | public function actionServerFiles () |
| 187 | { | 188 | { |
| 188 | $arr_id_files = []; | 189 | $arr_id_files = []; |
| 190 | + $arr_supported_extension = Parser::supportedExtension(); | ||
| 189 | 191 | ||
| 190 | // получим список файлов которые ожидают к загрузке | 192 | // получим список файлов которые ожидают к загрузке |
| 191 | - foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv' ) as $server_file ) { | ||
| 192 | - $file_id = basename($server_file,".csv"); | ||
| 193 | - $arr_id_files[] = (int) $file_id; | 193 | + foreach ($arr_supported_extension as $ext) { |
| 194 | + foreach ( glob( Yii::getAlias('@temp_upload') . '/*.' . $ext ) as $server_file ) { | ||
| 195 | + $file_id = basename($server_file, ".{$ext}"); | ||
| 196 | + $arr_id_files[] = (int)$file_id; | ||
| 197 | + } | ||
| 194 | } | 198 | } |
| 195 | 199 | ||
| 196 | $query = ImportersFiles::find()->where(['in', 'id', $arr_id_files])->orderBy( ['upload_time' => SORT_DESC] ); | 200 | $query = ImportersFiles::find()->where(['in', 'id', $arr_id_files])->orderBy( ['upload_time' => SORT_DESC] ); |
| @@ -215,7 +219,13 @@ class ParserController extends BaseController | @@ -215,7 +219,13 @@ class ParserController extends BaseController | ||
| 215 | $id = Yii::$app->request->post()['id']; | 219 | $id = Yii::$app->request->post()['id']; |
| 216 | try { | 220 | try { |
| 217 | $files_model->delete($id); | 221 | $files_model->delete($id); |
| 218 | - unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.csv' ); | 222 | + if (file_exists( Yii::getAlias('@temp_upload') . '/' . $id . '.csv' )) { |
| 223 | + unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.csv' ); | ||
| 224 | + } | ||
| 225 | + if (file_exists( Yii::getAlias('@temp_upload') . '/' . $id . '.xlsx' )) { | ||
| 226 | + unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.xlsx' ); | ||
| 227 | + } | ||
| 228 | + | ||
| 219 | // сообщим скрипту что все ОК | 229 | // сообщим скрипту что все ОК |
| 220 | echo 1; | 230 | echo 1; |
| 221 | } catch (ErrorException $e) { | 231 | } catch (ErrorException $e) { |
| @@ -230,22 +240,24 @@ class ParserController extends BaseController | @@ -230,22 +240,24 @@ class ParserController extends BaseController | ||
| 230 | 240 | ||
| 231 | public function actionLaunchCroneUploads () | 241 | public function actionLaunchCroneUploads () |
| 232 | { | 242 | { |
| 233 | - foreach (glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file) { | 243 | + $arr_supported_extension = Parser::supportedExtension(); |
| 244 | + // получим список файлов которые ожидают к загрузке | ||
| 245 | + foreach ($arr_supported_extension as $ext) { | ||
| 246 | + foreach ( glob( Yii::getAlias('@temp_upload') . '/*.' . $ext ) as $server_file ) { | ||
| 234 | 247 | ||
| 235 | - $file_name = basename($server_file,".csv"); | ||
| 236 | - copy( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' ); | 248 | + $file_name = basename($server_file, ".{$ext}"); |
| 249 | + copy($server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . ".{$ext}"); | ||
| 237 | 250 | ||
| 251 | + } | ||
| 238 | } | 252 | } |
| 239 | - | ||
| 240 | $controller = new \console\controllers\ParserController( 'parse-prices', $this->module ); | 253 | $controller = new \console\controllers\ParserController( 'parse-prices', $this->module ); |
| 241 | - $controller->actionSaveMailAttachments(); | 254 | + //$controller->actionSaveMailAttachments(); |
| 242 | $controller->actionParsePrices(); | 255 | $controller->actionParsePrices(); |
| 243 | 256 | ||
| 244 | Yii::$app->session->setFlash( 'server-files', 'Файл успешно загружен' ); | 257 | Yii::$app->session->setFlash( 'server-files', 'Файл успешно загружен' ); |
| 245 | $this->redirect('server-files'); | 258 | $this->redirect('server-files'); |
| 246 | } | 259 | } |
| 247 | 260 | ||
| 248 | - | ||
| 249 | /** | 261 | /** |
| 250 | * сохраняет файл на диск и регистрирует в ImportersFiles | 262 | * сохраняет файл на диск и регистрирует в ImportersFiles |
| 251 | * @param $model - модель с настройками | 263 | * @param $model - модель с настройками |
backend/views/brands/_form.php
| @@ -10,26 +10,20 @@ use yii\widgets\ActiveForm; | @@ -10,26 +10,20 @@ use yii\widgets\ActiveForm; | ||
| 10 | 10 | ||
| 11 | <div class="brands-form"> | 11 | <div class="brands-form"> |
| 12 | 12 | ||
| 13 | - <?php $form = ActiveForm::begin(); ?> | 13 | + <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> |
| 14 | 14 | ||
| 15 | - <?= $form->field($model, 'BRAND')->textInput(['maxlength' => true]) ?> | ||
| 16 | - | ||
| 17 | - <?= $form->field($model, 'if_tecdoc')->textInput() ?> | ||
| 18 | - | ||
| 19 | - <?= $form->field($model, 'tecdoc_logo')->textInput(['maxlength' => true]) ?> | ||
| 20 | - | ||
| 21 | - <?= $form->field($model, 'if_oem')->textInput() ?> | ||
| 22 | - | ||
| 23 | - <?= $form->field($model, 'if_checked')->textInput() ?> | 15 | + <?php |
| 16 | + if($model->isNewRecord) | ||
| 17 | + echo $form->field($model, 'BRAND')->textInput(['maxlength' => true])->label('Название') | ||
| 18 | + ?> | ||
| 24 | 19 | ||
| 25 | <?= $form->field($model, 'CONTENT')->textarea(['rows' => 6]) ?> | 20 | <?= $form->field($model, 'CONTENT')->textarea(['rows' => 6]) ?> |
| 21 | + <?= $form->field($model, 'if_oem')->checkbox() ?> | ||
| 22 | + <?= $form->field($model, 'IMG')->fileInput() ?> | ||
| 26 | 23 | ||
| 27 | - <?= $form->field($model, 'IMG')->textInput(['maxlength' => true]) ?> | ||
| 28 | - | ||
| 29 | - <?= $form->field($model, 'timestamp')->textInput() ?> | ||
| 30 | 24 | ||
| 31 | <div class="form-group"> | 25 | <div class="form-group"> |
| 32 | - <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 26 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
| 33 | </div> | 27 | </div> |
| 34 | 28 | ||
| 35 | <?php ActiveForm::end(); ?> | 29 | <?php ActiveForm::end(); ?> |
backend/views/brands/index.php
| @@ -9,6 +9,8 @@ use yii\grid\GridView; | @@ -9,6 +9,8 @@ use yii\grid\GridView; | ||
| 9 | 9 | ||
| 10 | $this->title = 'Бренды'; | 10 | $this->title = 'Бренды'; |
| 11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
| 12 | +$img0 = '/storage/checkbox0.gif'; | ||
| 13 | +$img1 = '/storage/checkbox1.gif'; | ||
| 12 | ?> | 14 | ?> |
| 13 | <div class="brands-index"> | 15 | <div class="brands-index"> |
| 14 | 16 | ||
| @@ -27,15 +29,34 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -27,15 +29,34 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 27 | 29 | ||
| 28 | 'ID', | 30 | 'ID', |
| 29 | 'BRAND', | 31 | 'BRAND', |
| 30 | - 'if_tecdoc', | ||
| 31 | - 'tecdoc_logo', | ||
| 32 | - 'if_oem', | ||
| 33 | - // 'if_checked', | ||
| 34 | - // 'CONTENT:ntext', | ||
| 35 | - // 'IMG', | ||
| 36 | - // 'timestamp', | ||
| 37 | - | ||
| 38 | - ['class' => 'yii\grid\ActionColumn'], | 32 | + ['attribute' => 'if_tecdoc', |
| 33 | + 'format' => 'raw', | ||
| 34 | + 'value' => function ( $model ) use ($img0, $img1) { | ||
| 35 | + if ($model->if_tecdoc == '1') { | ||
| 36 | + $info = " <img src=$img1>"; | ||
| 37 | + } | ||
| 38 | + else { | ||
| 39 | + $info = " <img src=$img0>"; | ||
| 40 | + } | ||
| 41 | + return $info; | ||
| 42 | + }, | ||
| 43 | + ], | ||
| 44 | + | ||
| 45 | + ['label' => 'ОРИГИНАЛ?', | ||
| 46 | + 'attribute' => 'if_oem', | ||
| 47 | + 'format' => 'raw', | ||
| 48 | + 'value' => function ( $model ) use ($img0, $img1) { | ||
| 49 | + if ($model->if_oem == '1') { | ||
| 50 | + $info = " <img src=$img1>"; | ||
| 51 | + } | ||
| 52 | + else { | ||
| 53 | + $info = " <img src=$img0>"; | ||
| 54 | + } | ||
| 55 | + return $info; | ||
| 56 | + }, | ||
| 57 | + ], | ||
| 58 | + ['class' => 'yii\grid\ActionColumn', | ||
| 59 | + 'template' => '{update}'], | ||
| 39 | ], | 60 | ], |
| 40 | ]); ?> | 61 | ]); ?> |
| 41 | 62 |
backend/views/brands/update.php
| @@ -5,7 +5,7 @@ use yii\helpers\Html; | @@ -5,7 +5,7 @@ use yii\helpers\Html; | ||
| 5 | /* @var $this yii\web\View */ | 5 | /* @var $this yii\web\View */ |
| 6 | /* @var $model common\models\Brands */ | 6 | /* @var $model common\models\Brands */ |
| 7 | 7 | ||
| 8 | -$this->title = 'Update Brands: ' . ' ' . $model->BRAND; | 8 | +$this->title = 'Редактирование бренда: ' . ' ' . $model->BRAND; |
| 9 | $this->params['breadcrumbs'][] = ['label' => 'Brands', 'url' => ['index']]; | 9 | $this->params['breadcrumbs'][] = ['label' => 'Brands', 'url' => ['index']]; |
| 10 | $this->params['breadcrumbs'][] = ['label' => $model->BRAND, 'url' => ['view', 'id' => $model->BRAND]]; | 10 | $this->params['breadcrumbs'][] = ['label' => $model->BRAND, 'url' => ['view', 'id' => $model->BRAND]]; |
| 11 | $this->params['breadcrumbs'][] = 'Update'; | 11 | $this->params['breadcrumbs'][] = 'Update'; |
backend/views/margins/create.php
| @@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
| 6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
| 7 | /* @var $model common\models\Margins */ | 7 | /* @var $model common\models\Margins */ |
| 8 | 8 | ||
| 9 | -$this->title = 'Добавить Margins'; | 9 | +$this->title = 'Добавить тип цен'; |
| 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; |
| 11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
| 12 | ?> | 12 | ?> |
| @@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 18 | 'model' => $model, | 18 | 'model' => $model, |
| 19 | ]) ?> | 19 | ]) ?> |
| 20 | 20 | ||
| 21 | + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?> | ||
| 22 | + | ||
| 21 | </div> | 23 | </div> |
backend/views/margins/index.php
| @@ -7,7 +7,7 @@ use yii\grid\GridView; | @@ -7,7 +7,7 @@ use yii\grid\GridView; | ||
| 7 | /* @var $searchModel common\models\MarginsSearch */ | 7 | /* @var $searchModel common\models\MarginsSearch */ |
| 8 | /* @var $dataProvider yii\data\ActiveDataProvider */ | 8 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
| 9 | 9 | ||
| 10 | -$this->title = 'Margins'; | 10 | +$this->title = 'Типы цен'; |
| 11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
| 12 | ?> | 12 | ?> |
| 13 | <div class="margins-index"> | 13 | <div class="margins-index"> |
| @@ -16,19 +16,17 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,19 +16,17 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
| 17 | 17 | ||
| 18 | <p> | 18 | <p> |
| 19 | - <?= Html::a('Добавить Margins', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> |
| 20 | </p> | 20 | </p> |
| 21 | 21 | ||
| 22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
| 23 | 'dataProvider' => $dataProvider, | 23 | 'dataProvider' => $dataProvider, |
| 24 | - 'filterModel' => $searchModel, | ||
| 25 | 'columns' => [ | 24 | 'columns' => [ |
| 26 | ['class' => 'yii\grid\SerialColumn'], | 25 | ['class' => 'yii\grid\SerialColumn'], |
| 27 | - | ||
| 28 | 'name', | 26 | 'name', |
| 29 | 'koef', | 27 | 'koef', |
| 30 | - | ||
| 31 | - ['class' => 'yii\grid\ActionColumn'], | 28 | + ['class' => 'yii\grid\ActionColumn', |
| 29 | + 'template' => '{update}{delete}'], | ||
| 32 | ], | 30 | ], |
| 33 | ]); ?> | 31 | ]); ?> |
| 34 | 32 |
backend/views/margins/update.php
| @@ -5,10 +5,10 @@ use yii\helpers\Html; | @@ -5,10 +5,10 @@ use yii\helpers\Html; | ||
| 5 | /* @var $this yii\web\View */ | 5 | /* @var $this yii\web\View */ |
| 6 | /* @var $model common\models\Margins */ | 6 | /* @var $model common\models\Margins */ |
| 7 | 7 | ||
| 8 | -$this->title = 'Update Margins: ' . ' ' . $model->name; | 8 | +$this->title = 'Редактировать тип цен: ' . ' ' . $model->name; |
| 9 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; | 9 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; |
| 10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; | 10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; |
| 11 | -$this->params['breadcrumbs'][] = 'Update'; | 11 | +$this->params['breadcrumbs'][] = 'Обновить'; |
| 12 | ?> | 12 | ?> |
| 13 | <div class="margins-update"> | 13 | <div class="margins-update"> |
| 14 | 14 | ||
| @@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = 'Update'; | @@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = 'Update'; | ||
| 18 | 'model' => $model, | 18 | 'model' => $model, |
| 19 | ]) ?> | 19 | ]) ?> |
| 20 | 20 | ||
| 21 | + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?> | ||
| 22 | + | ||
| 21 | </div> | 23 | </div> |
common/components/parsers/Parser.php
common/components/parsers/XlsxParser.php
| @@ -37,7 +37,7 @@ class XlsxParser extends TableParser | @@ -37,7 +37,7 @@ class XlsxParser extends TableParser | ||
| 37 | protected $current_sheet; | 37 | protected $current_sheet; |
| 38 | 38 | ||
| 39 | // глубина округления для флоата | 39 | // глубина округления для флоата |
| 40 | - // @todo - перенести вродительский класс и применить в дочерних классах | 40 | + // @todo - перенести в родительский класс и применить в дочерних классах |
| 41 | protected $float_precision = 6; | 41 | protected $float_precision = 6; |
| 42 | 42 | ||
| 43 | public function setup() | 43 | public function setup() |
common/components/parsers/config.php
| @@ -88,6 +88,23 @@ | @@ -88,6 +88,23 @@ | ||
| 88 | 'configuration' => ["string" => []], | 88 | 'configuration' => ["string" => []], |
| 89 | ] | 89 | ] |
| 90 | ], | 90 | ], |
| 91 | + 'console' => | ||
| 92 | + ['class' => 'common\components\parsers\XlsxParser', | ||
| 93 | + 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/xlsx/', | ||
| 94 | + 'auto_detect_first_line' => true, | ||
| 95 | + 'active_sheet' => 1, | ||
| 96 | + 'converter_conf' => [ | ||
| 97 | + 'class' => ' common\components\parsers\CustomConverter', | ||
| 98 | + 'configuration' => ["encode" => 'DESCR', | ||
| 99 | + "string" => 'DESCR', | ||
| 100 | + "float" => 'PRICE', | ||
| 101 | + "brand" => 'BRAND', | ||
| 102 | + "integer" => ['BOX','ADD_BOX'], | ||
| 103 | + "multiply" => [], | ||
| 104 | + "article" => [], | ||
| 105 | + "details" => [] | ||
| 106 | + ] | ||
| 107 | + ],], | ||
| 91 | ] | 108 | ] |
| 92 | ]; | 109 | ]; |
| 93 | 110 |
common/models/Brands.php
| @@ -49,14 +49,14 @@ class Brands extends \yii\db\ActiveRecord | @@ -49,14 +49,14 @@ class Brands extends \yii\db\ActiveRecord | ||
| 49 | public function attributeLabels() | 49 | public function attributeLabels() |
| 50 | { | 50 | { |
| 51 | return [ | 51 | return [ |
| 52 | - 'ID' => 'ID', | ||
| 53 | - 'BRAND' => 'Brand', | ||
| 54 | - 'if_tecdoc' => 'If Tecdoc', | 52 | + 'ID' => 'Номер', |
| 53 | + 'BRAND' => 'Название', | ||
| 54 | + 'if_tecdoc' => 'ТЕКДОК?', | ||
| 55 | 'tecdoc_logo' => 'Tecdoc Logo', | 55 | 'tecdoc_logo' => 'Tecdoc Logo', |
| 56 | - 'if_oem' => 'If Oem', | 56 | + 'if_oem' => 'Оргигинал', |
| 57 | 'if_checked' => 'If Checked', | 57 | 'if_checked' => 'If Checked', |
| 58 | - 'CONTENT' => 'Content', | ||
| 59 | - 'IMG' => 'Img', | 58 | + 'CONTENT' => 'Описание', |
| 59 | + 'IMG' => 'Изображение', | ||
| 60 | 'timestamp' => 'Timestamp', | 60 | 'timestamp' => 'Timestamp', |
| 61 | ]; | 61 | ]; |
| 62 | } | 62 | } |
common/models/BrandsSearch.php
| @@ -18,8 +18,8 @@ class BrandsSearch extends Brands | @@ -18,8 +18,8 @@ class BrandsSearch extends Brands | ||
| 18 | public function rules() | 18 | public function rules() |
| 19 | { | 19 | { |
| 20 | return [ | 20 | return [ |
| 21 | - [['ID', 'if_tecdoc', 'if_oem', 'if_checked'], 'integer'], | ||
| 22 | - [['BRAND', 'tecdoc_logo', 'CONTENT', 'IMG', 'timestamp'], 'safe'], | 21 | + [['ID'], 'integer'], |
| 22 | + [['BRAND'], 'safe'], | ||
| 23 | ]; | 23 | ]; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -57,16 +57,9 @@ class BrandsSearch extends Brands | @@ -57,16 +57,9 @@ class BrandsSearch extends Brands | ||
| 57 | 57 | ||
| 58 | $query->andFilterWhere([ | 58 | $query->andFilterWhere([ |
| 59 | 'ID' => $this->ID, | 59 | 'ID' => $this->ID, |
| 60 | - 'if_tecdoc' => $this->if_tecdoc, | ||
| 61 | - 'if_oem' => $this->if_oem, | ||
| 62 | - 'if_checked' => $this->if_checked, | ||
| 63 | - 'timestamp' => $this->timestamp, | 60 | + 'BRAND' => $this->BRAND, |
| 64 | ]); | 61 | ]); |
| 65 | 62 | ||
| 66 | - $query->andFilterWhere(['like', 'BRAND', $this->BRAND]) | ||
| 67 | - ->andFilterWhere(['like', 'tecdoc_logo', $this->tecdoc_logo]) | ||
| 68 | - ->andFilterWhere(['like', 'CONTENT', $this->CONTENT]) | ||
| 69 | - ->andFilterWhere(['like', 'IMG', $this->IMG]); | ||
| 70 | 63 | ||
| 71 | return $dataProvider; | 64 | return $dataProvider; |
| 72 | } | 65 | } |
common/models/Currency.php
| @@ -56,7 +56,7 @@ class Currency extends \yii\db\ActiveRecord | @@ -56,7 +56,7 @@ class Currency extends \yii\db\ActiveRecord | ||
| 56 | 56 | ||
| 57 | public function beforeSave($insert) | 57 | public function beforeSave($insert) |
| 58 | { | 58 | { |
| 59 | - if (parent::beforeSave($insert)) { | 59 | + if ( parent::beforeSave($insert) ) { |
| 60 | $this->timestamp = date("Y-m-d H:i:s"); | 60 | $this->timestamp = date("Y-m-d H:i:s"); |
| 61 | return true; | 61 | return true; |
| 62 | } else { | 62 | } else { |
common/models/Margins.php
| @@ -28,7 +28,7 @@ class Margins extends \yii\db\ActiveRecord | @@ -28,7 +28,7 @@ class Margins extends \yii\db\ActiveRecord | ||
| 28 | { | 28 | { |
| 29 | return [ | 29 | return [ |
| 30 | [['name', 'koef'], 'required'], | 30 | [['name', 'koef'], 'required'], |
| 31 | - [['koef'], 'number'], | 31 | + ['koef', \common\components\CommaNumberValidator::className()], |
| 32 | [['name'], 'string', 'max' => 100], | 32 | [['name'], 'string', 'max' => 100], |
| 33 | [['name'], 'unique'] | 33 | [['name'], 'unique'] |
| 34 | ]; | 34 | ]; |
common/models/MarginsSearch.php
| @@ -19,8 +19,8 @@ class MarginsSearch extends Margins | @@ -19,8 +19,8 @@ class MarginsSearch extends Margins | ||
| 19 | { | 19 | { |
| 20 | return [ | 20 | return [ |
| 21 | [['id'], 'integer'], | 21 | [['id'], 'integer'], |
| 22 | - [['name'], 'safe'], | ||
| 23 | - [['koef'], 'number'], | 22 | +// [['name'], 'safe'], |
| 23 | +// [['koef'], 'number'], | ||
| 24 | ]; | 24 | ]; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| @@ -56,12 +56,12 @@ class MarginsSearch extends Margins | @@ -56,12 +56,12 @@ class MarginsSearch extends Margins | ||
| 56 | return $dataProvider; | 56 | return $dataProvider; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | - $query->andFilterWhere([ | ||
| 60 | - 'id' => $this->id, | ||
| 61 | - 'koef' => $this->koef, | ||
| 62 | - ]); | ||
| 63 | - | ||
| 64 | - $query->andFilterWhere(['like', 'name', $this->name]); | 59 | +// $query->andFilterWhere([ |
| 60 | +// 'id' => $this->id, | ||
| 61 | +// 'koef' => $this->koef, | ||
| 62 | +// ]); | ||
| 63 | +// | ||
| 64 | +// $query->andFilterWhere(['like', 'name', $this->name]); | ||
| 65 | 65 | ||
| 66 | return $dataProvider; | 66 | return $dataProvider; |
| 67 | } | 67 | } |
composer.json
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | "kartik-v/yii2-datecontrol": "dev-master", | 24 | "kartik-v/yii2-datecontrol": "dev-master", |
| 25 | "codeception/codeception": "*", | 25 | "codeception/codeception": "*", |
| 26 | "2amigos/yii2-ckeditor-widget": "~1.0", | 26 | "2amigos/yii2-ckeditor-widget": "~1.0", |
| 27 | - "mihaildev/yii2-ckeditor": "*", | 27 | + "mihaildev/yii2-ckeditor": "^1.0", |
| 28 | "kartik-v/yii2-widget-fileinput": "@dev", | 28 | "kartik-v/yii2-widget-fileinput": "@dev", |
| 29 | "phpmailer/phpmailer": "^5.2", | 29 | "phpmailer/phpmailer": "^5.2", |
| 30 | "mihaildev/yii2-elfinder": "*" | 30 | "mihaildev/yii2-elfinder": "*" |
composer.lock
| @@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
| 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
| 5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
| 6 | ], | 6 | ], |
| 7 | - "hash": "f6d5550f22108e48d542a099d5e9a3ea", | ||
| 8 | - "content-hash": "bc7f313c8871095badc7533a53ff3d53", | 7 | + "hash": "9ddc6cc1d58d87c992e53caaffe27119", |
| 8 | + "content-hash": "cfa3f3c9f04cb6b28af05c11197eb35b", | ||
| 9 | "packages": [ | 9 | "packages": [ |
| 10 | { | 10 | { |
| 11 | "name": "2amigos/yii2-ckeditor-widget", | 11 | "name": "2amigos/yii2-ckeditor-widget", |
console/controllers/ParserController.php
| @@ -6,6 +6,7 @@ use common\components\archives\ArchiveCreator; | @@ -6,6 +6,7 @@ use common\components\archives\ArchiveCreator; | ||
| 6 | use common\components\CustomVarDamp; | 6 | use common\components\CustomVarDamp; |
| 7 | use common\components\mail\ImapMailReader; | 7 | use common\components\mail\ImapMailReader; |
| 8 | use common\components\mail\MailAttachmentsSaver; | 8 | use common\components\mail\MailAttachmentsSaver; |
| 9 | +use common\components\parsers\Parser; | ||
| 9 | use yii\console\Controller; | 10 | use yii\console\Controller; |
| 10 | use yii\helpers\Console; | 11 | use yii\helpers\Console; |
| 11 | use common\components\PriceWriter; | 12 | use common\components\PriceWriter; |
| @@ -27,8 +28,11 @@ class ParserController extends Controller | @@ -27,8 +28,11 @@ class ParserController extends Controller | ||
| 27 | ['mode' => 2, 'path' => \Yii::getAlias('@mail_upload')], | 28 | ['mode' => 2, 'path' => \Yii::getAlias('@mail_upload')], |
| 28 | ]; | 29 | ]; |
| 29 | 30 | ||
| 30 | - $this->parseCsvFiles($path_arr); | ||
| 31 | - $this->parseXmlFiles($path_arr); | 31 | + $arr_supported_extension = Parser::supportedExtension(); |
| 32 | + foreach ($arr_supported_extension as $ext) { | ||
| 33 | + | ||
| 34 | + $this->parseFilesByExtension( $ext , $path_arr ); | ||
| 35 | + } | ||
| 32 | 36 | ||
| 33 | } | 37 | } |
| 34 | 38 | ||
| @@ -73,36 +77,18 @@ class ParserController extends Controller | @@ -73,36 +77,18 @@ class ParserController extends Controller | ||
| 73 | 77 | ||
| 74 | } | 78 | } |
| 75 | 79 | ||
| 76 | - protected function parseCsvFiles($path_arr) | 80 | + protected function parseFilesByExtension( $ext, $path_arr ) |
| 77 | { | 81 | { |
| 78 | - \Yii::info('Начало загрузки файлов прайсов csv', 'parser'); | 82 | + \Yii::info("Начало загрузки файлов прайсов {$ext}", 'parser'); |
| 79 | foreach ($path_arr as $path_config) { | 83 | foreach ($path_arr as $path_config) { |
| 80 | - foreach (glob($path_config['path'] . '/*.csv') as $file_path) { | ||
| 81 | - $file_name = basename($file_path, ".csv"); | ||
| 82 | - \Yii::info("Обработка файла - $file_path", 'parser'); | ||
| 83 | - $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id; | ||
| 84 | - $current_importer = Importers::findOne(['id' => $importer_id]); | ||
| 85 | - $keys = $current_importer->keys; | ||
| 86 | - $mult_array = $current_importer->multiply; | ||
| 87 | - | ||
| 88 | - // получим настройки ценообразования и передадим их отдельно в конвертер | ||
| 89 | - $sign = ''; | ||
| 90 | - $multiplier = ''; | ||
| 91 | - extract($mult_array); | ||
| 92 | - | ||
| 93 | - $config = [ | ||
| 94 | - 'record_id' => $file_name, | ||
| 95 | - 'importer_id' => $importer_id, | ||
| 96 | - 'mode' => $path_config['mode'], | ||
| 97 | - 'parser_config' => ['keys' => $keys, | ||
| 98 | - 'converter_conf' => | ||
| 99 | - ['sign' => $sign, | ||
| 100 | - 'multiplier' => $multiplier], | ||
| 101 | - 'mode' => 'console'] | ||
| 102 | - ]; | 84 | + foreach ( glob( $path_config['path'] . "/*.{$ext}" ) as $file_path ) { |
| 85 | + $file_name = basename( $file_path, ".{$ext}" ); | ||
| 86 | + \Yii::info( "Обработка файла - $file_path", 'parser' ); | ||
| 87 | + | ||
| 88 | + $config = $this->getParsingConfiguration( $file_name, $path_config['mode'], $ext ); | ||
| 103 | 89 | ||
| 104 | if ($this->parseFile($file_path, $config)) { | 90 | if ($this->parseFile($file_path, $config)) { |
| 105 | - $temp_file = \Yii::getAlias('@temp_upload') . '/' . $file_name . '.csv'; | 91 | + $temp_file = \Yii::getAlias('@temp_upload') . '/' . $file_name . ".{$ext}"; |
| 106 | if( file_exists( $temp_file ) ) | 92 | if( file_exists( $temp_file ) ) |
| 107 | unlink($temp_file); | 93 | unlink($temp_file); |
| 108 | 94 | ||
| @@ -111,55 +97,13 @@ class ParserController extends Controller | @@ -111,55 +97,13 @@ class ParserController extends Controller | ||
| 111 | \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); | 97 | \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); |
| 112 | } | 98 | } |
| 113 | //при любом завершении скрипта файл с очереди автозагрузки нужно удалить | 99 | //при любом завершении скрипта файл с очереди автозагрузки нужно удалить |
| 114 | - $auto_file = $path_config['path'] . '/' . $file_name . '.csv'; | 100 | + $auto_file = $path_config['path'] . '/' . $file_name . ".{$ext}"; |
| 115 | if( file_exists( $auto_file ) ) | 101 | if( file_exists( $auto_file ) ) |
| 116 | unlink($auto_file); | 102 | unlink($auto_file); |
| 117 | } | 103 | } |
| 118 | } | 104 | } |
| 119 | } | 105 | } |
| 120 | 106 | ||
| 121 | - protected function parseXmlFiles($path_arr) | ||
| 122 | - { | ||
| 123 | - \Yii::info('Начало загрузки файлов прайсов xml', 'parser'); | ||
| 124 | - foreach ($path_arr as $path_config) { | ||
| 125 | - foreach (glob($path_config['path'] . '/*.xml') as $file_path) { | ||
| 126 | - $file_name = basename($file_path, ".xml"); | ||
| 127 | - \Yii::info("Обработка файла - $file_path", 'parser'); | ||
| 128 | - | ||
| 129 | - $files_model = new ImportersFiles(); | ||
| 130 | - // id поставщика всегда = 1 - Склад | ||
| 131 | - $files_model->importer_id = 1; | ||
| 132 | - try { | ||
| 133 | - $files_model->save(); | ||
| 134 | - } catch (ErrorException $e) { | ||
| 135 | - throw $e; | ||
| 136 | - } | ||
| 137 | - // получим id только что записанной записи | ||
| 138 | - $record_id = $files_model->find() | ||
| 139 | - ->where(['importer_id' => $files_model->importer_id]) | ||
| 140 | - ->orderBy(['id' => SORT_DESC]) | ||
| 141 | - ->one() | ||
| 142 | - ->id; | ||
| 143 | - | ||
| 144 | - $config = ['record_id' => $record_id, | ||
| 145 | - 'importer_id' => 1, | ||
| 146 | - 'mode' => $path_config['mode'], | ||
| 147 | - 'parser_config' => [ | ||
| 148 | - 'mode' => 'console'] | ||
| 149 | - ]; | ||
| 150 | - | ||
| 151 | - if ($this->parseFile($file_path, $config)) { | ||
| 152 | - \Yii::info("Загрузка файла - $file_path успешно завершена", 'parser'); | ||
| 153 | - } else { | ||
| 154 | - \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - $auto_file = $path_config['path'] . '/' . $file_name . '.xml'; | ||
| 158 | - if( file_exists( $auto_file ) ) | ||
| 159 | - unlink($auto_file); | ||
| 160 | - } | ||
| 161 | - } | ||
| 162 | - } | ||
| 163 | 107 | ||
| 164 | protected function parseFile($file_path, $configuration) | 108 | protected function parseFile($file_path, $configuration) |
| 165 | { | 109 | { |
| @@ -193,9 +137,9 @@ class ParserController extends Controller | @@ -193,9 +137,9 @@ class ParserController extends Controller | ||
| 193 | $writer->setData($data); | 137 | $writer->setData($data); |
| 194 | 138 | ||
| 195 | $writer->writePriceToDB(); | 139 | $writer->writePriceToDB(); |
| 196 | - $error = $writer->hasValidationError(); | 140 | + $has_error = $writer->hasValidationError(); |
| 197 | $log_msg = strip_tags( $writer->getValidatedMsg() ); | 141 | $log_msg = strip_tags( $writer->getValidatedMsg() ); |
| 198 | - if ( $error ) { | 142 | + if ( $has_error ) { |
| 199 | \Yii::error($log_msg, 'parser'); | 143 | \Yii::error($log_msg, 'parser'); |
| 200 | } else { | 144 | } else { |
| 201 | \Yii::info($log_msg, 'parser'); | 145 | \Yii::info($log_msg, 'parser'); |
| @@ -205,16 +149,12 @@ class ParserController extends Controller | @@ -205,16 +149,12 @@ class ParserController extends Controller | ||
| 205 | } | 149 | } |
| 206 | } | 150 | } |
| 207 | } | 151 | } |
| 208 | - | ||
| 209 | - $log_model->error = (int) $error; | 152 | + $log_model->error = (int) $has_error; |
| 210 | $log_model->log_msg = $log_msg; | 153 | $log_model->log_msg = $log_msg; |
| 211 | // запишем данные в лог | 154 | // запишем данные в лог |
| 212 | $log_model->save(); | 155 | $log_model->save(); |
| 213 | 156 | ||
| 214 | - | ||
| 215 | - | ||
| 216 | return true; | 157 | return true; |
| 217 | - | ||
| 218 | } | 158 | } |
| 219 | 159 | ||
| 220 | private function getMailAttachments($mail_reader, $importer_id_prefix = '') | 160 | private function getMailAttachments($mail_reader, $importer_id_prefix = '') |
| @@ -313,4 +253,53 @@ class ParserController extends Controller | @@ -313,4 +253,53 @@ class ParserController extends Controller | ||
| 313 | } | 253 | } |
| 314 | } | 254 | } |
| 315 | } | 255 | } |
| 256 | + | ||
| 257 | + protected function getParsingConfiguration( $file_name, $mode, $ext ){ | ||
| 258 | + | ||
| 259 | + if ($ext === 'xml') { | ||
| 260 | + $files_model = new ImportersFiles(); | ||
| 261 | + // id поставщика всегда = 1 - Склад | ||
| 262 | + $files_model->importer_id = 1; | ||
| 263 | + try { | ||
| 264 | + $files_model->save(); | ||
| 265 | + } catch (ErrorException $e) { | ||
| 266 | + throw $e; | ||
| 267 | + } | ||
| 268 | + // получим id только что записанной записи | ||
| 269 | + $record_id = $files_model->find() | ||
| 270 | + ->where(['importer_id' => $files_model->importer_id]) | ||
| 271 | + ->orderBy(['id' => SORT_DESC]) | ||
| 272 | + ->one() | ||
| 273 | + ->id; | ||
| 274 | + | ||
| 275 | + $config = ['record_id' => $record_id, | ||
| 276 | + 'importer_id' => 1, | ||
| 277 | + 'mode' => $mode, | ||
| 278 | + 'parser_config' => [ | ||
| 279 | + 'mode' => 'console'] | ||
| 280 | + ]; | ||
| 281 | + } else { | ||
| 282 | + $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id; | ||
| 283 | + $current_importer = Importers::findOne(['id' => $importer_id]); | ||
| 284 | + $keys = $current_importer->keys; | ||
| 285 | + $mult_array = $current_importer->multiply; | ||
| 286 | + | ||
| 287 | + // получим настройки ценообразования и передадим их отдельно в конвертер | ||
| 288 | + $sign = ''; | ||
| 289 | + $multiplier = ''; | ||
| 290 | + extract($mult_array); | ||
| 291 | + | ||
| 292 | + $config = [ | ||
| 293 | + 'record_id' => $file_name, | ||
| 294 | + 'importer_id' => $importer_id, | ||
| 295 | + 'mode' => $mode, | ||
| 296 | + 'parser_config' => ['keys' => $keys, | ||
| 297 | + 'converter_conf' => | ||
| 298 | + ['sign' => $sign, | ||
| 299 | + 'multiplier' => $multiplier], | ||
| 300 | + 'mode' => 'console'] | ||
| 301 | + ]; | ||
| 302 | + } | ||
| 303 | + return $config; | ||
| 304 | +} | ||
| 316 | } | 305 | } |
| 317 | \ No newline at end of file | 306 | \ No newline at end of file |
| 1 | +/temp |