Commit 78fd710070ccab5de4bb5b23888aeb2250e62ae8
1 parent
9009e1b5
add XlsxParser
Showing
7 changed files
with
16 additions
and
29 deletions
Show diff stats
backend/controllers/ParserController.php
| @@ -52,8 +52,6 @@ class ParserController extends BaseController | @@ -52,8 +52,6 @@ class ParserController extends BaseController | ||
| 52 | 52 | ||
| 53 | public function actionIndex($mode = 0) | 53 | public function actionIndex($mode = 0) |
| 54 | { | 54 | { |
| 55 | -// $path = 'common\components\parsers\CustomConverter'; | ||
| 56 | -// CustomVarDamp::dumpAndDie(new $path()); | ||
| 57 | $model = new UploadFileParsingForm(); | 55 | $model = new UploadFileParsingForm(); |
| 58 | // установим режим, 0 - ручная загрузка, 1 - автозагрузка | 56 | // установим режим, 0 - ручная загрузка, 1 - автозагрузка |
| 59 | $model->mode = $mode; | 57 | $model->mode = $mode; |
backend/models/UploadFileParsingForm.php
| @@ -48,7 +48,7 @@ class UploadFileParsingForm extends Model | @@ -48,7 +48,7 @@ class UploadFileParsingForm extends Model | ||
| 48 | return [ | 48 | return [ |
| 49 | ['importer_id', 'required', 'message' => 'Не указан поставщик!' ], | 49 | ['importer_id', 'required', 'message' => 'Не указан поставщик!' ], |
| 50 | ['file', 'required', 'message' => 'Не выбран файл!' ], | 50 | ['file', 'required', 'message' => 'Не выбран файл!' ], |
| 51 | - [['file'], 'file', 'extensions' => ['csv', 'xml'], 'checkExtensionByMimeType'=>false ], | 51 | + [['file'], 'file', 'extensions' => ['csv', 'xlsx'], 'checkExtensionByMimeType'=>false ], |
| 52 | ['importer_id', 'integer','max' => 999999, 'min' => 0 ], | 52 | ['importer_id', 'integer','max' => 999999, 'min' => 0 ], |
| 53 | [['action','delete_prefix', 'delete_price', 'success'], 'boolean', 'except' => 'auto' ], // только для ручной загрузки | 53 | [['action','delete_prefix', 'delete_price', 'success'], 'boolean', 'except' => 'auto' ], // только для ручной загрузки |
| 54 | ['delimiter', 'string', 'max' => 1], | 54 | ['delimiter', 'string', 'max' => 1], |
| @@ -71,7 +71,6 @@ class UploadFileParsingForm extends Model | @@ -71,7 +71,6 @@ class UploadFileParsingForm extends Model | ||
| 71 | public function readFile( $options = [] ){ | 71 | public function readFile( $options = [] ){ |
| 72 | 72 | ||
| 73 | $data = Yii::$app->multiparser->parse( $this->file_path, $options ); | 73 | $data = Yii::$app->multiparser->parse( $this->file_path, $options ); |
| 74 | - CustomVarDamp::dumpAndDie($data); | ||
| 75 | if( !is_array( $data ) || count($data) == 0 ){ | 74 | if( !is_array( $data ) || count($data) == 0 ){ |
| 76 | throw new ErrorException("Ошибка чтения из файла прайса {$this->file_path}"); | 75 | throw new ErrorException("Ошибка чтения из файла прайса {$this->file_path}"); |
| 77 | } | 76 | } |
common/components/PriceWriter.php
| @@ -91,7 +91,7 @@ class PriceWriter | @@ -91,7 +91,7 @@ class PriceWriter | ||
| 91 | try { | 91 | try { |
| 92 | //@todo add transaction | 92 | //@todo add transaction |
| 93 | 93 | ||
| 94 | - if ((int)$this->configuration['delete_price']) { | 94 | + if ( isset($this->configuration['delete_price']) && (int)$this->configuration['delete_price'] ) { |
| 95 | $details_model->delete_price = true; | 95 | $details_model->delete_price = true; |
| 96 | } | 96 | } |
| 97 | //2. попытаемся вставить данные в БД с апдейтом по ключам | 97 | //2. попытаемся вставить данные в БД с апдейтом по ключам |
common/components/parsers/config.php
| @@ -68,25 +68,15 @@ | @@ -68,25 +68,15 @@ | ||
| 68 | 'configuration' => ["details" => [] | 68 | 'configuration' => ["details" => [] |
| 69 | ],], | 69 | ],], |
| 70 | ], | 70 | ], |
| 71 | - 'web' => | ||
| 72 | - ['class' => 'yii\multiparser\XmlParser', | ||
| 73 | - 'node' => 'Товар', | ||
| 74 | - 'hasHeaderRow' => true, | ||
| 75 | - 'keys' => [ | ||
| 76 | - "BRAND" => 'Производитель', | ||
| 77 | - "ARTICLE"=> 'Код', | ||
| 78 | - "PRICE" => 'Розница', | ||
| 79 | - "DESCR" => 'Наименование', | ||
| 80 | - "BOX" => 'Колво', | ||
| 81 | - "ADD_BOX"=> 'Ожидаемое', | ||
| 82 | - "GROUP" => 'Группа' | ||
| 83 | - ], | ||
| 84 | - 'converter_conf' => [ | ||
| 85 | - 'class' => 'common\components\parsers\CustomConverter', | ||
| 86 | - 'configuration' => ["details" => [] | ||
| 87 | - ],], | ||
| 88 | - ], | ||
| 89 | ], | 71 | ], |
| 90 | - | 72 | + 'xlsx' => |
| 73 | + ['web' => | ||
| 74 | + ['class' => 'yii\multiparser\XlsxParser', | ||
| 75 | + 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/', | ||
| 76 | + 'converter_conf' => [ | ||
| 77 | + 'class' => 'common\components\parsers\CustomConverter', | ||
| 78 | + 'configuration' => ["encode" => 'DESCR'],] | ||
| 79 | + ], | ||
| 80 | + ] | ||
| 91 | ]; | 81 | ]; |
| 92 | 82 |
console/.gitignore
console/controllers/ParserController.php
| @@ -59,8 +59,7 @@ class ParserController extends Controller | @@ -59,8 +59,7 @@ class ParserController extends Controller | ||
| 59 | } | 59 | } |
| 60 | $data = \Yii::$app->multiparser->parse( $file_path, $parser_config ); | 60 | $data = \Yii::$app->multiparser->parse( $file_path, $parser_config ); |
| 61 | if ( ! $data ) { | 61 | if ( ! $data ) { |
| 62 | - // @todo переделать, что бы ошибка автоматически останавливала сценарий | ||
| 63 | - return false; | 62 | + throw new ErrorException("Ошибка обработки файла прайса!"); |
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | $writer = new PriceWriter(); | 65 | $writer = new PriceWriter(); |
| @@ -105,7 +104,7 @@ class ParserController extends Controller | @@ -105,7 +104,7 @@ class ParserController extends Controller | ||
| 105 | ]; | 104 | ]; |
| 106 | 105 | ||
| 107 | if ($this->parseFileConsole($file_path, $config)) { | 106 | if ($this->parseFileConsole($file_path, $config)) { |
| 108 | - unlink(\Yii::getAlias('@auto_upload') . '/' . $file_name . '.xml'); | 107 | + //unlink(\Yii::getAlias('@auto_upload') . '/' . $file_name . '.xml'); |
| 109 | \Yii::info("Загрузка файла - $file_path успешно завершена", 'parser'); | 108 | \Yii::info("Загрузка файла - $file_path успешно завершена", 'parser'); |
| 110 | } else { | 109 | } else { |
| 111 | \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); | 110 | \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); |
console/runtime/.gitignore