diff --git a/backend/models/UploadFileParsingForm.php b/backend/models/UploadFileParsingForm.php index f9dc936..a1e36d9 100755 --- a/backend/models/UploadFileParsingForm.php +++ b/backend/models/UploadFileParsingForm.php @@ -98,5 +98,4 @@ class UploadFileParsingForm extends Model } - } \ No newline at end of file diff --git a/common/models/GoodsView.php b/common/models/GoodsView.php new file mode 100644 index 0000000..ea7ead4 --- /dev/null +++ b/common/models/GoodsView.php @@ -0,0 +1,99 @@ + 100], + [['importer_name', 'delivery'], 'string', 'max' => 254], + [['description'], 'string', 'max' => 255], + [['article'], 'string', 'max' => 150], + [['image'], 'string', 'max' => 229] + ]; + } + + /** + * @return string + */ + public function getOutputPrice() + { + $price_margin_id = Yii::$app->session->getFlash('price_margin_id',1); + $price_currency_id = Yii::$app->session->getFlash('price_currency_id',1); + + $koef = Margins::getDb()->cache( function ($db) use ($price_margin_id) { + return (float) Margins::findOne($price_margin_id)->koef; + }); + + $rate = Currency::getDb()->cache( function ($db) use ($price_currency_id) { + return (float) Currency::findOne($price_currency_id)->rate; + }); + + if(!$rate) + $rate = 1; // если 0, то 1 + + return round($this->price * ($this->rate/$rate) * $koef, 2); + } + + + public function attributeLabels() + { + return [ + 'name' => 'Name', + 'brand' => 'Brand', + 'box' => 'Box', + 'add_box' => 'Add Box', + 'importer_id' => 'Importer ID', + 'importer_name' => 'Importer Name', + 'rate' => 'Rate', + 'currency_id' => 'Currency ID', + 'delivery' => 'Delivery', + 'description' => 'Description', + 'article' => 'Article', + 'ID' => 'ID', + 'image' => 'Image', + 'tecdoc_id' => 'Tecdoc ID', + 'price' => 'Price', + 'brand_id' => 'Brand ID', + ]; + } +} diff --git a/common/models/GoodsViewSearch.php b/common/models/GoodsViewSearch.php new file mode 100644 index 0000000..5f475e1 --- /dev/null +++ b/common/models/GoodsViewSearch.php @@ -0,0 +1,115 @@ + 20, +// ]; + + + $this->load($params); + + if ( !$this->validate() ) { + $query->where('0=1'); + } + + $query->andFilterWhere([ + 'name' => $this->name, + 'brand' => $this->brand, + ]); + + $query->andWhere(['or', 'box > 0', 'add_box > 0']); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'key' => 'article', + 'sort' => [ + 'attributes' => [ + 'box', + 'delivery', + 'price' + ], + ], + + ]); + + return $dataProvider; + } + public function searchCrosses($params) + { + $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`CROSS_ARTICLE` = `name` and `w_details_crosses`.`CROSS_BRAND` = w_goods_view.`brand`'); + +// $pagination = [ +// 'pageSize' => 20, +// ]; + + + $this->load($params); + + if ( !$this->validate() ) { + $query->where('0=1'); + } + + $query->andFilterWhere([ + 'w_details_crosses.ARTICLE' => $this->name, + 'w_details_crosses.BRAND' => $this->brand, + ]); + + $query->andWhere(['or', 'box > 0', 'add_box > 0']); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'key' => 'article', + 'sort' => [ + 'attributes' => [ + 'box', + 'delivery', + 'price' + ], + ], + + ]); + + return $dataProvider; + } +} diff --git a/console/migrations/m151219_103804_goods_view.php b/console/migrations/m151219_103804_goods_view.php new file mode 100644 index 0000000..d798e3c --- /dev/null +++ b/console/migrations/m151219_103804_goods_view.php @@ -0,0 +1,72 @@ +execute($view); + + } + + public function safeDown() + { + // вернем все как было + $drop_view = 'drop view if exists w_goods_view'; + + $this->execute($drop_view); + + } +} diff --git a/frontend/controllers/GoodsController.php b/frontend/controllers/GoodsController.php index 51d0a50..43b0f8b 100644 --- a/frontend/controllers/GoodsController.php +++ b/frontend/controllers/GoodsController.php @@ -9,8 +9,9 @@ namespace frontend\controllers; use common\components\CustomVarDamp; +use common\models\DetailsCrosses; +use common\models\GoodsViewSearch; use Yii; -use yii\data\SqlDataProvider; use yii\web\Controller; class GoodsController extends Controller { @@ -18,29 +19,40 @@ class GoodsController extends Controller { public function actionIndex($name = '') { - - $query = $this->getQuery(); - - $provider = new SqlDataProvider([ - 'sql' => $query, - 'key' => 'article', - 'pagination' => false, - 'params' => [':article' => '0092S40090', - ':brand' => 'BOSCH', - ':margin_id' => '1', - ':currency_id' => '1'], - 'sort' => [ - 'attributes' => [ - 'box', - 'delivery', - 'price' - ], - ], - ]); + $arr = ['GoodsViewSearch' => ['name' => '0092S40090', + 'brand' => 'BOSCH']]; + + Yii::$app->session->setFlash('price_currency_id', 1); + Yii::$app->session->setFlash('price_margin_id', 1); + + $searchModel = new GoodsViewSearch(); + $goods_provider = $searchModel->searchCrosses($arr); + + +//$cross_arr = DetailsCrosses::find()->select('ARTICLE, BRAND')->where(['CROSS_ARTICLE' => '0092S40090', 'CROSS_BRAND' => 'BOSCH'])->asArray()->all(); +// +// $article_condition = "'" . implode("','", array_column($cross_arr,'ARTICLE')) . "'"; +// $brand_condition = "'" . implode("','", array_column($cross_arr,'BRAND')) . "'"; +// +// $crosses_provider = new SqlDataProvider([ +// 'sql' => $query, +// 'key' => 'article', +// 'pagination' => false, +// 'params' => [':article' => $article_condition, +// ':brand' => $brand_condition], +// 'sort' => [ +// 'attributes' => [ +// 'box', +// 'delivery', +// 'price' +// ], +// ], +// ]); return $this->render('index',[ - 'dataProvider' => $provider + 'goods_data_provider' => $goods_provider, + 'crosses_data_provider' => $goods_provider, ]); } @@ -114,19 +126,19 @@ from `w_details` `w_details_description`.`brand` = `w_details`.`BRAND` inner join `w_importers` on `w_importers`.`id` = `w_details`.`IMPORT_ID` and `w_importers`.`active` = 1 - inner join `w_margins` on `w_margins`.`id` =:margin_id + inner join `w_margins` on `w_margins`.`id` = @margin left join `w_margins_importers` on `w_margins_importers`.`importer_id` = `w_details`.`IMPORT_ID` and - `w_margins_importers`.`margin_id`=:margin_id + `w_margins_importers`.`margin_id`= @margin left join `w_margins_groups` on `w_margins_groups`.`importer_id` = `w_details`.`IMPORT_ID` and - `w_margins_groups`.`margin_id` =:margin_id and + `w_margins_groups`.`margin_id` = @margin and `w_margins_groups`.`group` = `w_details`.`group` - inner join `w_currency` on `w_currency`.`id` =:currency_id + inner join `w_currency` on `w_currency`.`id` = @currency inner join `w_currency` as `t` on `t`.`id` = `w_importers`.`currency_id` inner join `w_currency` as `default` on `default`.`is_default` = 1 left join `w_margins_groups` as `input_groups` on `input_groups`.`importer_id` = `w_details`.`IMPORT_ID` and `input_groups`.`margin_id` = 8 and `input_groups`.`group` = `w_details`.`group` -where `w_details`.`ARTICLE` =:article and `w_details`.`BRAND` =:brand and (`w_details`.`BOX` > 0 or `w_details`.`ADD_BOX`) +where `w_details`.`ARTICLE` In(:article) and `w_details`.`BRAND` In(:brand) and (`w_details`.`BOX` > 0 or `w_details`.`ADD_BOX` > 0) MySQL; return $query; diff --git a/frontend/views/goods/index.php b/frontend/views/goods/index.php index 7b30015..6a7fc56 100644 --- a/frontend/views/goods/index.php +++ b/frontend/views/goods/index.php @@ -96,17 +96,18 @@ $this->params['breadcrumbs'][] = $this->title; Номер детали Описание - link('box')?> - link('delivery')?> - link('price')?> + link('box') ?> + link('delivery') ?> + link('price') ?> $dataProvider, - 'itemView'=>'one_item', - 'layout' => "{items}" - ] ); + echo \yii\widgets\ListView::widget([ + 'dataProvider' => $goods_data_provider, + 'itemView' => 'one_item', + 'summary' => '', + 'layout' => "{items}" + ]); ?> @@ -129,294 +130,14 @@ $this->params['breadcrumbs'][] = $this->title; Цена - - BOSH - 0 092 S30 120 - - - - 12V 88Ah 740A - - - - - - - - - - - -
-
- -
- - -
-
- -
- - - 3 - 1 дн. - 103.75 - - - BOSH - 0 092 S30 120 - - - - 12V 88Ah 740A - - - - - - - - - - - - - - -
-
- -
- - -
-
- -
-
- -
- - -
-
- -
- - - - - - - - - - - - -
3
3
- - - - - - - - - - - - -
1 дн.
1 дн.
- - - - - - - - - - - -
103.75
103.75
- - - - BOSH - 0 092 S30 120 - - - - 12V 88Ah 740A - - - - - - - - - - - -
-
- -
- - -
-
- -
- - - 3 - 1 дн. - 103.75 - - - BOSH - 0 092 S30 120 - - - - 12V 88Ah 740A - - - - - - - - - - - - -
-
- -
- - -
-
- -
- - - 3 - 1 дн. - 103.75 - - - BOSH - 0 092 S30 120 - - - - 12V 88Ah 740A - - - - - - - - - - - - - -
-
- -
- - -
-
- -
-
- -
- - -
-
- -
- - - - - - - - - - - - -
3
3
- - - - - - - - - - - - -
1 дн.
1 дн.
- - - - - - - - - - - -
103.75
103.75
- - + $crosses_data_provider, + 'itemView' => 'one_item', + 'summary' => '', + 'layout' => "{items}" + ]); + ?>
diff --git a/frontend/views/goods/one_item.php b/frontend/views/goods/one_item.php index e2bfc0d..30fae23 100644 --- a/frontend/views/goods/one_item.php +++ b/frontend/views/goods/one_item.php @@ -15,23 +15,25 @@ if ( empty($article_arr[$index - 1]) || $article_arr[$index - 1] != $key ) beginBlock('item_details'); // выделим отдельно детали товара в блок, для опционального его вывода ?> - - - - - - - - - - + + brand?> + article?> + + + + description?> + + + endBlock(); ?> beginBlock('empty_details'); // иначе пустой блок ?> - - + + + + endBlock(); ?> @@ -66,16 +68,16 @@ if ( empty($article_arr[$index - 1]) || $article_arr[$index - 1] != $key ) - +
box ?>
- +
дн.
delivery?> дн.
- +
outputPrice?>
-- libgit2 0.21.4