-
+ ['enctype' => 'multipart/form-data']]); ?>
- = $form->field($model, 'BRAND')->textInput(['maxlength' => true]) ?>
-
- = $form->field($model, 'if_tecdoc')->textInput() ?>
-
- = $form->field($model, 'tecdoc_logo')->textInput(['maxlength' => true]) ?>
-
- = $form->field($model, 'if_oem')->textInput() ?>
-
- = $form->field($model, 'if_checked')->textInput() ?>
+ isNewRecord)
+ echo $form->field($model, 'BRAND')->textInput(['maxlength' => true])->label('Название')
+ ?>
= $form->field($model, 'CONTENT')->textarea(['rows' => 6]) ?>
+ = $form->field($model, 'if_oem')->checkbox() ?>
+ = $form->field($model, 'IMG')->fileInput() ?>
- = $form->field($model, 'IMG')->textInput(['maxlength' => true]) ?>
-
- = $form->field($model, 'timestamp')->textInput() ?>
- = Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
+ = Html::submitButton($model->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,
]) ?>
+ = Html::a('Вернуться', ['index'], ['class' => '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]); ?>
- = Html::a('Добавить Margins', ['create'], ['class' => 'btn btn-success']) ?>
+ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
= GridView::widget([
'dataProvider' => $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,
]) ?>
+ = Html::a('Вернуться', ['index'], ['class' => '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