diff --git a/.gitignore b/.gitignore index b3d5a23..eca3901 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ /vendor /storage tests/_output/* -composer.lock \ No newline at end of file +composer.lock diff --git a/.htaccess b/.htaccess index 9c37e78..9b12d6f 100755 --- a/.htaccess +++ b/.htaccess @@ -12,7 +12,7 @@ AddDefaultCharset utf-8 RewriteBase / # deal with admin first - RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT] + RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT] RewriteCond %{REQUEST_URI} ^/(admin) diff --git a/backend/.gitignore b/backend/.gitignore index 11cf485..e85fbbc 100755 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ /temp +/tmp /uploads /runtime \ No newline at end of file diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index e1435fd..083b6d4 100755 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -7,6 +7,7 @@ use common\components\exceptions\PriceParsingException; use common\components\exceptions\RgParsingException; use common\components\ModelArrayValidator; use common\components\parsers\MailParser; +use common\components\parsers\Parser; use Yii; use yii\data\ActiveDataProvider; use yii\filters\AccessControl; @@ -186,11 +187,14 @@ class ParserController extends BaseController public function actionServerFiles () { $arr_id_files = []; + $arr_supported_extension = Parser::supportedExtension(); // получим список файлов которые ожидают к загрузке - foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv' ) as $server_file ) { - $file_id = basename($server_file,".csv"); - $arr_id_files[] = (int) $file_id; + foreach ($arr_supported_extension as $ext) { + foreach ( glob( Yii::getAlias('@temp_upload') . '/*.' . $ext ) as $server_file ) { + $file_id = basename($server_file, ".{$ext}"); + $arr_id_files[] = (int)$file_id; + } } $query = ImportersFiles::find()->where(['in', 'id', $arr_id_files])->orderBy( ['upload_time' => SORT_DESC] ); @@ -215,7 +219,13 @@ class ParserController extends BaseController $id = Yii::$app->request->post()['id']; try { $files_model->delete($id); - unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.csv' ); + if (file_exists( Yii::getAlias('@temp_upload') . '/' . $id . '.csv' )) { + unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.csv' ); + } + if (file_exists( Yii::getAlias('@temp_upload') . '/' . $id . '.xlsx' )) { + unlink(Yii::getAlias('@temp_upload') . '/' . $id . '.xlsx' ); + } + // сообщим скрипту что все ОК echo 1; } catch (ErrorException $e) { @@ -230,22 +240,24 @@ class ParserController extends BaseController public function actionLaunchCroneUploads () { - foreach (glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file) { + $arr_supported_extension = Parser::supportedExtension(); + // получим список файлов которые ожидают к загрузке + foreach ($arr_supported_extension as $ext) { + foreach ( glob( Yii::getAlias('@temp_upload') . '/*.' . $ext ) as $server_file ) { - $file_name = basename($server_file,".csv"); - copy( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' ); + $file_name = basename($server_file, ".{$ext}"); + copy($server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . ".{$ext}"); + } } - $controller = new \console\controllers\ParserController( 'parse-prices', $this->module ); - $controller->actionSaveMailAttachments(); + //$controller->actionSaveMailAttachments(); $controller->actionParsePrices(); Yii::$app->session->setFlash( 'server-files', 'Файл успешно загружен' ); $this->redirect('server-files'); } - /** * сохраняет файл на диск и регистрирует в ImportersFiles * @param $model - модель с настройками diff --git a/backend/views/brands/_form.php b/backend/views/brands/_form.php index a3bf3cb..c0449e3 100755 --- a/backend/views/brands/_form.php +++ b/backend/views/brands/_form.php @@ -10,26 +10,20 @@ use yii\widgets\ActiveForm;
- + ['enctype' => 'multipart/form-data']]); ?> - field($model, 'BRAND')->textInput(['maxlength' => true]) ?> - - field($model, 'if_tecdoc')->textInput() ?> - - field($model, 'tecdoc_logo')->textInput(['maxlength' => true]) ?> - - field($model, 'if_oem')->textInput() ?> - - field($model, 'if_checked')->textInput() ?> + isNewRecord) + echo $form->field($model, 'BRAND')->textInput(['maxlength' => true])->label('Название') + ?> field($model, 'CONTENT')->textarea(['rows' => 6]) ?> + field($model, 'if_oem')->checkbox() ?> + field($model, 'IMG')->fileInput() ?> - field($model, 'IMG')->textInput(['maxlength' => true]) ?> - - field($model, 'timestamp')->textInput() ?>
- isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? 'Добавить' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/brands/index.php b/backend/views/brands/index.php index ebf4186..e0b638f 100755 --- a/backend/views/brands/index.php +++ b/backend/views/brands/index.php @@ -9,6 +9,8 @@ use yii\grid\GridView; $this->title = 'Бренды'; $this->params['breadcrumbs'][] = $this->title; +$img0 = '/storage/checkbox0.gif'; +$img1 = '/storage/checkbox1.gif'; ?>
@@ -27,15 +29,34 @@ $this->params['breadcrumbs'][] = $this->title; 'ID', 'BRAND', - 'if_tecdoc', - 'tecdoc_logo', - 'if_oem', - // 'if_checked', - // 'CONTENT:ntext', - // 'IMG', - // 'timestamp', - - ['class' => 'yii\grid\ActionColumn'], + ['attribute' => 'if_tecdoc', + 'format' => 'raw', + 'value' => function ( $model ) use ($img0, $img1) { + if ($model->if_tecdoc == '1') { + $info = " "; + } + else { + $info = " "; + } + return $info; + }, + ], + + ['label' => 'ОРИГИНАЛ?', + 'attribute' => 'if_oem', + 'format' => 'raw', + 'value' => function ( $model ) use ($img0, $img1) { + if ($model->if_oem == '1') { + $info = " "; + } + else { + $info = " "; + } + return $info; + }, + ], + ['class' => 'yii\grid\ActionColumn', + 'template' => '{update}'], ], ]); ?> diff --git a/backend/views/brands/update.php b/backend/views/brands/update.php index cf15f04..503268e 100755 --- a/backend/views/brands/update.php +++ b/backend/views/brands/update.php @@ -5,7 +5,7 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Brands */ -$this->title = 'Update Brands: ' . ' ' . $model->BRAND; +$this->title = 'Редактирование бренда: ' . ' ' . $model->BRAND; $this->params['breadcrumbs'][] = ['label' => 'Brands', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->BRAND, 'url' => ['view', 'id' => $model->BRAND]]; $this->params['breadcrumbs'][] = 'Update'; diff --git a/backend/views/margins/create.php b/backend/views/margins/create.php index 17a6a6e..5101048 100755 --- a/backend/views/margins/create.php +++ b/backend/views/margins/create.php @@ -6,7 +6,7 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Margins */ -$this->title = 'Добавить Margins'; +$this->title = 'Добавить тип цен'; $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> @@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = $this->title; 'model' => $model, ]) ?> + 'btn btn-primary']) ?> +
diff --git a/backend/views/margins/index.php b/backend/views/margins/index.php index daf8f43..7e24f90 100755 --- a/backend/views/margins/index.php +++ b/backend/views/margins/index.php @@ -7,7 +7,7 @@ use yii\grid\GridView; /* @var $searchModel common\models\MarginsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ -$this->title = 'Margins'; +$this->title = 'Типы цен'; $this->params['breadcrumbs'][] = $this->title; ?>
@@ -16,19 +16,17 @@ $this->params['breadcrumbs'][] = $this->title; render('_search', ['model' => $searchModel]); ?>

- 'btn btn-success']) ?> + 'btn btn-success']) ?>

$dataProvider, - 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - 'name', 'koef', - - ['class' => 'yii\grid\ActionColumn'], + ['class' => 'yii\grid\ActionColumn', + 'template' => '{update}{delete}'], ], ]); ?> diff --git a/backend/views/margins/update.php b/backend/views/margins/update.php index 9f15648..5ab799e 100755 --- a/backend/views/margins/update.php +++ b/backend/views/margins/update.php @@ -5,10 +5,10 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Margins */ -$this->title = 'Update Margins: ' . ' ' . $model->name; +$this->title = 'Редактировать тип цен: ' . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update'; +$this->params['breadcrumbs'][] = 'Обновить'; ?>
@@ -18,4 +18,6 @@ $this->params['breadcrumbs'][] = 'Update'; 'model' => $model, ]) ?> + 'btn btn-primary']) ?> +
diff --git a/common/components/parsers/Parser.php b/common/components/parsers/Parser.php index ee9c62e..fd31215 100644 --- a/common/components/parsers/Parser.php +++ b/common/components/parsers/Parser.php @@ -92,6 +92,11 @@ abstract class Parser } + public final static function supportedExtension() + { + return ['csv','xml','xlsx']; + } + protected function cleanUp( ) { diff --git a/common/components/parsers/XlsxParser.php b/common/components/parsers/XlsxParser.php index 1f1d47f..da11671 100644 --- a/common/components/parsers/XlsxParser.php +++ b/common/components/parsers/XlsxParser.php @@ -37,7 +37,7 @@ class XlsxParser extends TableParser protected $current_sheet; // глубина округления для флоата - // @todo - перенести вродительский класс и применить в дочерних классах + // @todo - перенести в родительский класс и применить в дочерних классах protected $float_precision = 6; public function setup() diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php index f277f51..3c24344 100755 --- a/common/components/parsers/config.php +++ b/common/components/parsers/config.php @@ -88,6 +88,23 @@ 'configuration' => ["string" => []], ] ], + 'console' => + ['class' => 'common\components\parsers\XlsxParser', + 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/xlsx/', + 'auto_detect_first_line' => true, + 'active_sheet' => 1, + 'converter_conf' => [ + 'class' => ' common\components\parsers\CustomConverter', + 'configuration' => ["encode" => 'DESCR', + "string" => 'DESCR', + "float" => 'PRICE', + "brand" => 'BRAND', + "integer" => ['BOX','ADD_BOX'], + "multiply" => [], + "article" => [], + "details" => [] + ] + ],], ] ]; diff --git a/common/models/Brands.php b/common/models/Brands.php index 547fee2..e45794c 100755 --- a/common/models/Brands.php +++ b/common/models/Brands.php @@ -49,14 +49,14 @@ class Brands extends \yii\db\ActiveRecord public function attributeLabels() { return [ - 'ID' => 'ID', - 'BRAND' => 'Brand', - 'if_tecdoc' => 'If Tecdoc', + 'ID' => 'Номер', + 'BRAND' => 'Название', + 'if_tecdoc' => 'ТЕКДОК?', 'tecdoc_logo' => 'Tecdoc Logo', - 'if_oem' => 'If Oem', + 'if_oem' => 'Оргигинал', 'if_checked' => 'If Checked', - 'CONTENT' => 'Content', - 'IMG' => 'Img', + 'CONTENT' => 'Описание', + 'IMG' => 'Изображение', 'timestamp' => 'Timestamp', ]; } diff --git a/common/models/BrandsSearch.php b/common/models/BrandsSearch.php index b2a4c5f..2b84872 100755 --- a/common/models/BrandsSearch.php +++ b/common/models/BrandsSearch.php @@ -18,8 +18,8 @@ class BrandsSearch extends Brands public function rules() { return [ - [['ID', 'if_tecdoc', 'if_oem', 'if_checked'], 'integer'], - [['BRAND', 'tecdoc_logo', 'CONTENT', 'IMG', 'timestamp'], 'safe'], + [['ID'], 'integer'], + [['BRAND'], 'safe'], ]; } @@ -57,16 +57,9 @@ class BrandsSearch extends Brands $query->andFilterWhere([ 'ID' => $this->ID, - 'if_tecdoc' => $this->if_tecdoc, - 'if_oem' => $this->if_oem, - 'if_checked' => $this->if_checked, - 'timestamp' => $this->timestamp, + 'BRAND' => $this->BRAND, ]); - $query->andFilterWhere(['like', 'BRAND', $this->BRAND]) - ->andFilterWhere(['like', 'tecdoc_logo', $this->tecdoc_logo]) - ->andFilterWhere(['like', 'CONTENT', $this->CONTENT]) - ->andFilterWhere(['like', 'IMG', $this->IMG]); return $dataProvider; } diff --git a/common/models/Currency.php b/common/models/Currency.php index 5e2723c..e8c997c 100755 --- a/common/models/Currency.php +++ b/common/models/Currency.php @@ -56,7 +56,7 @@ class Currency extends \yii\db\ActiveRecord public function beforeSave($insert) { - if (parent::beforeSave($insert)) { + if ( parent::beforeSave($insert) ) { $this->timestamp = date("Y-m-d H:i:s"); return true; } else { diff --git a/common/models/Margins.php b/common/models/Margins.php index 209853e..550d832 100755 --- a/common/models/Margins.php +++ b/common/models/Margins.php @@ -28,7 +28,7 @@ class Margins extends \yii\db\ActiveRecord { return [ [['name', 'koef'], 'required'], - [['koef'], 'number'], + ['koef', \common\components\CommaNumberValidator::className()], [['name'], 'string', 'max' => 100], [['name'], 'unique'] ]; diff --git a/common/models/MarginsSearch.php b/common/models/MarginsSearch.php index 6b272a7..6470b24 100755 --- a/common/models/MarginsSearch.php +++ b/common/models/MarginsSearch.php @@ -19,8 +19,8 @@ class MarginsSearch extends Margins { return [ [['id'], 'integer'], - [['name'], 'safe'], - [['koef'], 'number'], +// [['name'], 'safe'], +// [['koef'], 'number'], ]; } @@ -56,12 +56,12 @@ class MarginsSearch extends Margins return $dataProvider; } - $query->andFilterWhere([ - 'id' => $this->id, - 'koef' => $this->koef, - ]); - - $query->andFilterWhere(['like', 'name', $this->name]); +// $query->andFilterWhere([ +// 'id' => $this->id, +// 'koef' => $this->koef, +// ]); +// +// $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; } diff --git a/composer.json b/composer.json index d54ca29..4df532f 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "kartik-v/yii2-datecontrol": "dev-master", "codeception/codeception": "*", "2amigos/yii2-ckeditor-widget": "~1.0", - "mihaildev/yii2-ckeditor": "*", + "mihaildev/yii2-ckeditor": "^1.0", "kartik-v/yii2-widget-fileinput": "@dev", "phpmailer/phpmailer": "^5.2", "mihaildev/yii2-elfinder": "*" diff --git a/composer.lock b/composer.lock index 62c7bad..a4cc919 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f6d5550f22108e48d542a099d5e9a3ea", - "content-hash": "bc7f313c8871095badc7533a53ff3d53", + "hash": "9ddc6cc1d58d87c992e53caaffe27119", + "content-hash": "cfa3f3c9f04cb6b28af05c11197eb35b", "packages": [ { "name": "2amigos/yii2-ckeditor-widget", diff --git a/console/controllers/ParserController.php b/console/controllers/ParserController.php index 5e376d1..69491d8 100755 --- a/console/controllers/ParserController.php +++ b/console/controllers/ParserController.php @@ -6,6 +6,7 @@ use common\components\archives\ArchiveCreator; use common\components\CustomVarDamp; use common\components\mail\ImapMailReader; use common\components\mail\MailAttachmentsSaver; +use common\components\parsers\Parser; use yii\console\Controller; use yii\helpers\Console; use common\components\PriceWriter; @@ -27,8 +28,11 @@ class ParserController extends Controller ['mode' => 2, 'path' => \Yii::getAlias('@mail_upload')], ]; - $this->parseCsvFiles($path_arr); - $this->parseXmlFiles($path_arr); + $arr_supported_extension = Parser::supportedExtension(); + foreach ($arr_supported_extension as $ext) { + + $this->parseFilesByExtension( $ext , $path_arr ); + } } @@ -73,36 +77,18 @@ class ParserController extends Controller } - protected function parseCsvFiles($path_arr) + protected function parseFilesByExtension( $ext, $path_arr ) { - \Yii::info('Начало загрузки файлов прайсов csv', 'parser'); + \Yii::info("Начало загрузки файлов прайсов {$ext}", 'parser'); foreach ($path_arr as $path_config) { - foreach (glob($path_config['path'] . '/*.csv') as $file_path) { - $file_name = basename($file_path, ".csv"); - \Yii::info("Обработка файла - $file_path", 'parser'); - $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id; - $current_importer = Importers::findOne(['id' => $importer_id]); - $keys = $current_importer->keys; - $mult_array = $current_importer->multiply; - - // получим настройки ценообразования и передадим их отдельно в конвертер - $sign = ''; - $multiplier = ''; - extract($mult_array); - - $config = [ - 'record_id' => $file_name, - 'importer_id' => $importer_id, - 'mode' => $path_config['mode'], - 'parser_config' => ['keys' => $keys, - 'converter_conf' => - ['sign' => $sign, - 'multiplier' => $multiplier], - 'mode' => 'console'] - ]; + foreach ( glob( $path_config['path'] . "/*.{$ext}" ) as $file_path ) { + $file_name = basename( $file_path, ".{$ext}" ); + \Yii::info( "Обработка файла - $file_path", 'parser' ); + + $config = $this->getParsingConfiguration( $file_name, $path_config['mode'], $ext ); if ($this->parseFile($file_path, $config)) { - $temp_file = \Yii::getAlias('@temp_upload') . '/' . $file_name . '.csv'; + $temp_file = \Yii::getAlias('@temp_upload') . '/' . $file_name . ".{$ext}"; if( file_exists( $temp_file ) ) unlink($temp_file); @@ -111,55 +97,13 @@ class ParserController extends Controller \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); } //при любом завершении скрипта файл с очереди автозагрузки нужно удалить - $auto_file = $path_config['path'] . '/' . $file_name . '.csv'; + $auto_file = $path_config['path'] . '/' . $file_name . ".{$ext}"; if( file_exists( $auto_file ) ) unlink($auto_file); } } } - protected function parseXmlFiles($path_arr) - { - \Yii::info('Начало загрузки файлов прайсов xml', 'parser'); - foreach ($path_arr as $path_config) { - foreach (glob($path_config['path'] . '/*.xml') as $file_path) { - $file_name = basename($file_path, ".xml"); - \Yii::info("Обработка файла - $file_path", 'parser'); - - $files_model = new ImportersFiles(); - // id поставщика всегда = 1 - Склад - $files_model->importer_id = 1; - try { - $files_model->save(); - } catch (ErrorException $e) { - throw $e; - } - // получим id только что записанной записи - $record_id = $files_model->find() - ->where(['importer_id' => $files_model->importer_id]) - ->orderBy(['id' => SORT_DESC]) - ->one() - ->id; - - $config = ['record_id' => $record_id, - 'importer_id' => 1, - 'mode' => $path_config['mode'], - 'parser_config' => [ - 'mode' => 'console'] - ]; - - if ($this->parseFile($file_path, $config)) { - \Yii::info("Загрузка файла - $file_path успешно завершена", 'parser'); - } else { - \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); - } - - $auto_file = $path_config['path'] . '/' . $file_name . '.xml'; - if( file_exists( $auto_file ) ) - unlink($auto_file); - } - } - } protected function parseFile($file_path, $configuration) { @@ -193,9 +137,9 @@ class ParserController extends Controller $writer->setData($data); $writer->writePriceToDB(); - $error = $writer->hasValidationError(); + $has_error = $writer->hasValidationError(); $log_msg = strip_tags( $writer->getValidatedMsg() ); - if ( $error ) { + if ( $has_error ) { \Yii::error($log_msg, 'parser'); } else { \Yii::info($log_msg, 'parser'); @@ -205,16 +149,12 @@ class ParserController extends Controller } } } - - $log_model->error = (int) $error; + $log_model->error = (int) $has_error; $log_model->log_msg = $log_msg; // запишем данные в лог $log_model->save(); - - return true; - } private function getMailAttachments($mail_reader, $importer_id_prefix = '') @@ -313,4 +253,53 @@ class ParserController extends Controller } } } + + protected function getParsingConfiguration( $file_name, $mode, $ext ){ + + if ($ext === 'xml') { + $files_model = new ImportersFiles(); + // id поставщика всегда = 1 - Склад + $files_model->importer_id = 1; + try { + $files_model->save(); + } catch (ErrorException $e) { + throw $e; + } + // получим id только что записанной записи + $record_id = $files_model->find() + ->where(['importer_id' => $files_model->importer_id]) + ->orderBy(['id' => SORT_DESC]) + ->one() + ->id; + + $config = ['record_id' => $record_id, + 'importer_id' => 1, + 'mode' => $mode, + 'parser_config' => [ + 'mode' => 'console'] + ]; + } else { + $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id; + $current_importer = Importers::findOne(['id' => $importer_id]); + $keys = $current_importer->keys; + $mult_array = $current_importer->multiply; + + // получим настройки ценообразования и передадим их отдельно в конвертер + $sign = ''; + $multiplier = ''; + extract($mult_array); + + $config = [ + 'record_id' => $file_name, + 'importer_id' => $importer_id, + 'mode' => $mode, + 'parser_config' => ['keys' => $keys, + 'converter_conf' => + ['sign' => $sign, + 'multiplier' => $multiplier], + 'mode' => 'console'] + ]; + } + return $config; +} } \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..36445e5 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1 @@ +/temp diff --git a/frontend/tmp/sess_dg8vgf1i7kpjvc9npptd9pnc83 b/frontend/tmp/sess_dg8vgf1i7kpjvc9npptd9pnc83 new file mode 100644 index 0000000..c4589d3 --- /dev/null +++ b/frontend/tmp/sess_dg8vgf1i7kpjvc9npptd9pnc83 @@ -0,0 +1 @@ +__flash|a:0:{}__captcha/site/captcha|s:7:"uiyvkur";__captcha/site/captchacount|i:1; \ No newline at end of file -- libgit2 0.21.4