Commit bc23d2813de11f14ed36771e2c8c4dd27eab177f

Authored by Administrator
2 parents 5fc85d80 df73f762

Merge remote-tracking branch 'origin/master'

Conflicts:
	frontend/controllers/GoodsController.php
common/models/GoodsView.php
@@ -30,8 +30,7 @@ class GoodsView extends \backend\components\base\BaseActiveRecord @@ -30,8 +30,7 @@ class GoodsView extends \backend\components\base\BaseActiveRecord
30 /** 30 /**
31 * @inheritdoc 31 * @inheritdoc
32 */ 32 */
33 - public $price_currency_id;  
34 - public $price_margin_id; 33 +
35 34
36 public static function tableName() 35 public static function tableName()
37 { 36 {
@@ -77,7 +76,10 @@ class GoodsView extends \backend\components\base\BaseActiveRecord @@ -77,7 +76,10 @@ class GoodsView extends \backend\components\base\BaseActiveRecord
77 return round($this->price * ($this->rate/$rate) * $koef, 2); 76 return round($this->price * ($this->rate/$rate) * $koef, 2);
78 } 77 }
79 78
80 - 79 + public static function primaryKey()
  80 + {
  81 + return ['name','brand', 'importer_id'];
  82 + }
81 83
82 84
83 public function attributeLabels() 85 public function attributeLabels()
common/models/GoodsViewSearch.php
@@ -18,7 +18,7 @@ class GoodsViewSearch extends GoodsView @@ -18,7 +18,7 @@ class GoodsViewSearch extends GoodsView
18 public function rules() 18 public function rules()
19 { 19 {
20 return [ 20 return [
21 - [['name', 'brand', 'price_currency_id', 'price_margin_id'], 'safe'], 21 + [['name', 'brand'], 'safe'],
22 ]; 22 ];
23 } 23 }
24 24
@@ -62,7 +62,7 @@ class GoodsViewSearch extends GoodsView @@ -62,7 +62,7 @@ class GoodsViewSearch extends GoodsView
62 62
63 $dataProvider = new ActiveDataProvider([ 63 $dataProvider = new ActiveDataProvider([
64 'query' => $query, 64 'query' => $query,
65 - 'key' => 'article', 65 + 'key' => 'name',
66 'sort' => [ 66 'sort' => [
67 'attributes' => [ 67 'attributes' => [
68 'box', 68 'box',
@@ -79,6 +79,26 @@ class GoodsViewSearch extends GoodsView @@ -79,6 +79,26 @@ class GoodsViewSearch extends GoodsView
79 { 79 {
80 $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`CROSS_ARTICLE` = `name` and `w_details_crosses`.`CROSS_BRAND` = w_goods_view.`brand`'); 80 $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`CROSS_ARTICLE` = `name` and `w_details_crosses`.`CROSS_BRAND` = w_goods_view.`brand`');
81 81
  82 +
  83 +// ->select([
  84 +// 'name' => 'Name',
  85 +// 'brand' => 'w_details_crosses.CROSS_BRAND',
  86 +// 'box' => 'Box',
  87 +// 'add_box' => 'add_box',
  88 +// 'importer_id' => 'importer_id',
  89 +// 'importer_name' => 'importer_name',
  90 +// 'rate' => 'Rate',
  91 +// 'currency_id' => 'currency_id',
  92 +// 'delivery' => 'Delivery',
  93 +// 'description' => 'Description',
  94 +// 'article' => 'w_details_crosses.CROSS_ARTICLE',
  95 +// 'ID' => 'w_goods_view.ID',
  96 +// 'image' => 'Image',
  97 +// 'tecdoc_id' => 'tecdoc_id',
  98 +// 'price' => 'Price',
  99 +// 'brand_id' => 'brand_id',
  100 +// ]);
  101 +
82 // $pagination = [ 102 // $pagination = [
83 // 'pageSize' => 20, 103 // 'pageSize' => 20,
84 // ]; 104 // ];
@@ -99,7 +119,7 @@ class GoodsViewSearch extends GoodsView @@ -99,7 +119,7 @@ class GoodsViewSearch extends GoodsView
99 119
100 $dataProvider = new ActiveDataProvider([ 120 $dataProvider = new ActiveDataProvider([
101 'query' => $query, 121 'query' => $query,
102 - 'key' => 'article', 122 + 'key' => 'name',
103 'sort' => [ 123 'sort' => [
104 'attributes' => [ 124 'attributes' => [
105 'box', 125 'box',
frontend/controllers/GoodsController.php
@@ -18,16 +18,16 @@ use common\models\Details; @@ -18,16 +18,16 @@ use common\models\Details;
18 class GoodsController extends Controller { 18 class GoodsController extends Controller {
19 public $layout = '/internal'; 19 public $layout = '/internal';
20 20
21 - public function actionIndex($name, $id) 21 + public function actionIndex( $name , $id )
22 { 22 {
23 23
24 -// print('name = '.$name."<br>");  
25 -// print('id = '. $id);  
26 -// die();  
27 - $test = (new Details)->getTehdocData('1204403');  
28 - die(print_r($test));  
29 - $arr = ['GoodsViewSearch' => ['name' => '0092S40090',  
30 - 'brand' => 'BOSCH']]; 24 + $arr_name = explode('_',$name);
  25 + $brand = $arr_name[0];
  26 + $article = $arr_name[1];
  27 +
  28 +
  29 + $arr = ['GoodsViewSearch' => ['name' => $article,
  30 + 'brand' => $brand]];
31 31
32 Yii::$app->session->setFlash('price_currency_id', 1); 32 Yii::$app->session->setFlash('price_currency_id', 1);
33 Yii::$app->session->setFlash('price_margin_id', 1); 33 Yii::$app->session->setFlash('price_margin_id', 1);
@@ -35,121 +35,13 @@ class GoodsController extends Controller { @@ -35,121 +35,13 @@ class GoodsController extends Controller {
35 $searchModel = new GoodsViewSearch(); 35 $searchModel = new GoodsViewSearch();
36 $goods_provider = $searchModel->search($arr); 36 $goods_provider = $searchModel->search($arr);
37 37
38 -  
39 -//$cross_arr = DetailsCrosses::find()->select('ARTICLE, BRAND')->where(['CROSS_ARTICLE' => '0092S40090', 'CROSS_BRAND' => 'BOSCH'])->asArray()->all();  
40 -//  
41 -// $article_condition = "'" . implode("','", array_column($cross_arr,'ARTICLE')) . "'";  
42 -// $brand_condition = "'" . implode("','", array_column($cross_arr,'BRAND')) . "'";  
43 -//  
44 -// $crosses_provider = new SqlDataProvider([  
45 -// 'sql' => $query,  
46 -// 'key' => 'article',  
47 -// 'pagination' => false,  
48 -// 'params' => [':article' => $article_condition,  
49 -// ':brand' => $brand_condition],  
50 -// 'sort' => [  
51 -// 'attributes' => [  
52 -// 'box',  
53 -// 'delivery',  
54 -// 'price'  
55 -// ],  
56 -// ],  
57 -// ]);  
58 - 38 + $crosses_provider = $searchModel->searchCrosses($arr);
59 39
60 return $this->render('index',[ 40 return $this->render('index',[
61 'goods_data_provider' => $goods_provider, 41 'goods_data_provider' => $goods_provider,
62 - 'crosses_data_provider' => $goods_provider, 42 + 'crosses_data_provider' => $crosses_provider,
63 ]); 43 ]);
64 } 44 }
65 45
66 46
67 - private function getQuery(){  
68 - $query = <<< MySQL  
69 - select straight_join `w_details`.`ARTICLE` as `name`,  
70 - `w_details`.`BRAND` as `brand`,  
71 - `w_details`.`BOX` as `box`,  
72 - `w_details`.`ADD_BOX` as `add_box`,  
73 - `w_details`.`IMPORT_ID` as `importer_id`,  
74 - `w_importers`.`name` as `importer_name`,  
75 - `w_importers`.`delivery`,  
76 - if (`w_details_description`.`description` = '',  
77 - if (`w_details_description`.`tecdoc_description` = '',  
78 - `w_details_description`.`supplier_description`,  
79 - `w_details_description`.`tecdoc_description`  
80 - ),  
81 - `w_details_description`.`description`  
82 - ) as `description`,  
83 -  
84 - if (`w_details_description`.`tecdoc_article` = '',  
85 - if (`w_details_description`.`article` = '',  
86 - if (`w_details`.`FULL_ARTICLE` = '',  
87 - `w_details`.`ARTICLE`,  
88 - `w_details`.`FULL_ARTICLE`  
89 - ),  
90 - `w_details_description`.`article`  
91 - ),  
92 - `w_details_description`.`tecdoc_article`  
93 - ) as `article`,  
94 - `w_details`.`ID`,  
95 - if (`w_details_description`.`image` = '',  
96 - if (`w_details_description`.`tecdoc_image` = '',  
97 - '',  
98 - concat('ital_origin/images/tecdoc/big/',`w_details_description`.`tecdoc_image`)  
99 - ),  
100 - concat('ital_origin/images/goods/big/',`w_details_description`.`image`)  
101 - ) as `image`,  
102 - `w_details_description`.`tecdoc_id`,  
103 - round(if(`w_margins_groups`.`koef` is not null,  
104 - `w_details`.`PRICE`*`w_margins_groups`.`koef`,  
105 - if (`w_margins_importers`.`koef` is not null,  
106 - `w_details`.`PRICE`*`w_margins_importers`.`koef`,  
107 - `w_details`.`PRICE`*`w_margins`.`koef`  
108 - )  
109 - )*`t`.`rate`/`w_currency`.`rate`,2) as `price`,  
110 -  
111 - round(if(`input_groups`.`koef` is not null,  
112 - `w_details`.`PRICE`*`input_groups`.`koef`,  
113 - `w_details`.`PRICE`  
114 - )*`t`.`rate`/`w_currency`.`rate`,2) as `input_price`,  
115 -  
116 - round(if(`input_groups`.`koef` is not null,  
117 - `w_details`.`PRICE`*`input_groups`.`koef`,  
118 - `w_details`.`PRICE`  
119 - )*`t`.`rate`/`default`.`rate`,2) as `input_price_default`,  
120 -  
121 - round(if(`w_margins_groups`.`koef` is not null,  
122 - `w_details`.`PRICE`*`w_margins_groups`.`koef`,  
123 - if (`w_margins_importers`.`koef` is not null,  
124 - `w_details`.`PRICE`*`w_margins_importers`.`koef`,  
125 - `w_details`.`PRICE`*`w_margins`.`koef`  
126 - )  
127 - )*`t`.`rate`/`default`.`rate`,2) as `price_default`,  
128 -  
129 - `w_brands`.`ID` as `brand_id`  
130 -from `w_details`  
131 - inner join `w_brands` on `w_brands`.`BRAND` = `w_details`.`BRAND`  
132 - left join `w_details_description` on `w_details_description`.`name` = `w_details`.`ARTICLE` and  
133 - `w_details_description`.`brand` = `w_details`.`BRAND`  
134 - inner join `w_importers` on `w_importers`.`id` = `w_details`.`IMPORT_ID` and  
135 - `w_importers`.`active` = 1  
136 - inner join `w_margins` on `w_margins`.`id` = @margin  
137 - left join `w_margins_importers` on `w_margins_importers`.`importer_id` = `w_details`.`IMPORT_ID` and  
138 - `w_margins_importers`.`margin_id`= @margin  
139 - left join `w_margins_groups` on `w_margins_groups`.`importer_id` = `w_details`.`IMPORT_ID` and  
140 - `w_margins_groups`.`margin_id` = @margin and  
141 - `w_margins_groups`.`group` = `w_details`.`group`  
142 - inner join `w_currency` on `w_currency`.`id` = @currency  
143 - inner join `w_currency` as `t` on `t`.`id` = `w_importers`.`currency_id`  
144 - inner join `w_currency` as `default` on `default`.`is_default` = 1  
145 - left join `w_margins_groups` as `input_groups` on `input_groups`.`importer_id` = `w_details`.`IMPORT_ID` and  
146 - `input_groups`.`margin_id` = 8 and  
147 - `input_groups`.`group` = `w_details`.`group`  
148 -where `w_details`.`ARTICLE` In(:article) and `w_details`.`BRAND` In(:brand) and (`w_details`.`BOX` > 0 or `w_details`.`ADD_BOX` > 0)  
149 -MySQL;  
150 -  
151 - return $query;  
152 -}  
153 -  
154 -  
155 } 47 }
156 \ No newline at end of file 48 \ No newline at end of file